80 lines · plain
1// RUN: mlir-opt -allow-unregistered-dialect %s -test-loop-permutation="permutation-map=1,2,0" | FileCheck %s --check-prefix=CHECK-1202// RUN: mlir-opt -allow-unregistered-dialect %s -test-loop-permutation="permutation-map=1,0,2" | FileCheck %s --check-prefix=CHECK-1023// RUN: mlir-opt -allow-unregistered-dialect %s -test-loop-permutation="permutation-map=0,1,2" | FileCheck %s --check-prefix=CHECK-0124// RUN: mlir-opt -allow-unregistered-dialect %s -test-loop-permutation="permutation-map=0,2,1" | FileCheck %s --check-prefix=CHECK-0215// RUN: mlir-opt -allow-unregistered-dialect %s -test-loop-permutation="permutation-map=2,0,1" | FileCheck %s --check-prefix=CHECK-2016// RUN: mlir-opt -allow-unregistered-dialect %s -test-loop-permutation="permutation-map=2,1,0" | FileCheck %s --check-prefix=CHECK-2107// RUN: mlir-opt -allow-unregistered-dialect %s -test-loop-permutation="permutation-map=2,1,0 check-validity=1" | FileCheck %s --check-prefix=CHECK-210-VALID8 9// CHECK-120-LABEL: func @permute10func.func @permute(%U0 : index, %U1 : index, %U2 : index) {11 "abc"() : () -> ()12 affine.for %arg0 = 0 to %U0 {13 affine.for %arg1 = 0 to %U1 {14 affine.for %arg2 = 0 to %U2 {15 "foo"(%arg0, %arg1) : (index, index) -> ()16 "bar"(%arg2) : (index) -> ()17 }18 }19 }20 "xyz"() : () -> ()21 return22}23// CHECK-120: "abc"24// CHECK-120-NEXT: affine.for25// CHECK-120-NEXT: affine.for26// CHECK-120-NEXT: affine.for27// CHECK-120-NEXT: "foo"(%arg4, %arg5)28// CHECK-120-NEXT: "bar"(%arg3)29// CHECK-120-NEXT: }30// CHECK-120-NEXT: }31// CHECK-120-NEXT: }32// CHECK-120-NEXT: "xyz"33// CHECK-120-NEXT: return34 35// CHECK-102: "foo"(%arg4, %arg3)36// CHECK-102-NEXT: "bar"(%arg5)37 38// CHECK-012: "foo"(%arg3, %arg4)39// CHECK-012-NEXT: "bar"(%arg5)40 41// CHECK-021: "foo"(%arg3, %arg5)42// CHECK-021-NEXT: "bar"(%arg4)43 44// CHECK-210: "foo"(%arg5, %arg4)45// CHECK-210-NEXT: "bar"(%arg3)46 47// CHECK-201: "foo"(%arg5, %arg3)48// CHECK-201-NEXT: "bar"(%arg4)49 50// -----51 52// Tests that the permutation validation check utility conservatively returns false when the53// for loop has an iter_arg.54 55// CHECK-210-VALID-LABEL: func @check_validity_with_iter_args56// CHECK-210-VALID-SAME: %[[ARG0:.*]]: index, %[[ARG1:.*]]: index, %[[ARG2:.*]]: index57func.func @check_validity_with_iter_args(%U0 : index, %U1 : index, %U2 : index) {58 %buf = memref.alloc() : memref<100x100xf32>59 %cst = arith.constant 1.0 : f3260 %c10 = arith.constant 10 : index61 %c20 = arith.constant 20 : index62 63 // Check that the loops are not permuted.64 // CHECK-210-VALID: affine.for %{{.*}} = 0 to %[[ARG0]] {65 // CHECK-210-VALID-NEXT: affine.for %{{.*}} = 0 to %[[ARG1]] {66 // CHECK-210-VALID-NEXT: affine.for %{{.*}} = 0 to %[[ARG2]] iter_args(67 affine.for %arg0 = 0 to %U0 {68 affine.for %arg1 = 0 to %U1 {69 %res = affine.for %arg2 = 0 to %U2 iter_args(%iter1 = %cst) -> (f32) {70 %val = affine.load %buf[%arg0 + 10, %arg1 + 20] : memref<100x100xf32>71 %newVal = arith.addf %val, %cst : f3272 affine.store %newVal, %buf[%arg0 + 10, %arg1 + 20] : memref<100x100xf32>73 %newVal2 = arith.addf %newVal, %iter1 : f3274 affine.yield %iter1 : f3275 }76 }77 }78 return79}80