2019-01-03 04:52:41 +08:00
|
|
|
// RUN: mlir-opt -lower-affine %s | FileCheck %s
|
2018-07-25 01:15:13 +08:00
|
|
|
|
2019-01-03 02:20:00 +08:00
|
|
|
// CHECK-LABEL: func @empty() {
|
|
|
|
func @empty() {
|
2018-07-25 01:15:13 +08:00
|
|
|
return // CHECK: return
|
|
|
|
} // CHECK: }
|
2018-11-13 06:58:36 +08:00
|
|
|
|
2020-11-14 05:04:53 +08:00
|
|
|
func private @body(index) -> ()
|
2018-11-13 06:58:36 +08:00
|
|
|
|
|
|
|
// Simple loops are properly converted.
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-LABEL: func @simple_loop
|
|
|
|
// CHECK-NEXT: %[[c1:.*]] = constant 1 : index
|
|
|
|
// CHECK-NEXT: %[[c42:.*]] = constant 42 : index
|
|
|
|
// CHECK-NEXT: %[[c1_0:.*]] = constant 1 : index
|
|
|
|
// CHECK-NEXT: for %{{.*}} = %[[c1]] to %[[c42]] step %[[c1_0]] {
|
|
|
|
// CHECK-NEXT: call @body(%{{.*}}) : (index) -> ()
|
|
|
|
// CHECK-NEXT: }
|
2018-11-13 06:58:36 +08:00
|
|
|
// CHECK-NEXT: return
|
|
|
|
// CHECK-NEXT: }
|
2019-01-03 02:20:00 +08:00
|
|
|
func @simple_loop() {
|
2019-03-26 01:14:34 +08:00
|
|
|
affine.for %i = 1 to 42 {
|
2018-11-13 06:58:36 +08:00
|
|
|
call @body(%i) : (index) -> ()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2020-12-23 00:10:17 +08:00
|
|
|
func @for_with_yield(%buffer: memref<1024xf32>) -> (f32) {
|
|
|
|
%sum_0 = constant 0.0 : f32
|
|
|
|
%sum = affine.for %i = 0 to 10 step 2 iter_args(%sum_iter = %sum_0) -> (f32) {
|
|
|
|
%t = affine.load %buffer[%i] : memref<1024xf32>
|
|
|
|
%sum_next = addf %sum_iter, %t : f32
|
|
|
|
affine.yield %sum_next : f32
|
|
|
|
}
|
|
|
|
return %sum : f32
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: func @for_with_yield
|
|
|
|
// CHECK: %[[INIT_SUM:.*]] = constant 0.000000e+00 : f32
|
|
|
|
// CHECK-NEXT: %[[LOWER:.*]] = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[UPPER:.*]] = constant 10 : index
|
|
|
|
// CHECK-NEXT: %[[STEP:.*]] = constant 2 : index
|
|
|
|
// CHECK-NEXT: %[[SUM:.*]] = scf.for %[[IV:.*]] = %[[LOWER]] to %[[UPPER]] step %[[STEP]] iter_args(%[[SUM_ITER:.*]] = %[[INIT_SUM]]) -> (f32) {
|
|
|
|
// CHECK-NEXT: load
|
|
|
|
// CHECK-NEXT: %[[SUM_NEXT:.*]] = addf
|
|
|
|
// CHECK-NEXT: scf.yield %[[SUM_NEXT]] : f32
|
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: return %[[SUM]] : f32
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2020-11-14 05:04:53 +08:00
|
|
|
func private @pre(index) -> ()
|
|
|
|
func private @body2(index, index) -> ()
|
|
|
|
func private @post(index) -> ()
|
2018-11-13 06:58:36 +08:00
|
|
|
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-LABEL: func @imperfectly_nested_loops
|
|
|
|
// CHECK-NEXT: %[[c0:.*]] = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[c42:.*]] = constant 42 : index
|
|
|
|
// CHECK-NEXT: %[[c1:.*]] = constant 1 : index
|
|
|
|
// CHECK-NEXT: for %{{.*}} = %[[c0]] to %[[c42]] step %[[c1]] {
|
|
|
|
// CHECK-NEXT: call @pre(%{{.*}}) : (index) -> ()
|
|
|
|
// CHECK-NEXT: %[[c7:.*]] = constant 7 : index
|
|
|
|
// CHECK-NEXT: %[[c56:.*]] = constant 56 : index
|
|
|
|
// CHECK-NEXT: %[[c2:.*]] = constant 2 : index
|
|
|
|
// CHECK-NEXT: for %{{.*}} = %[[c7]] to %[[c56]] step %[[c2]] {
|
|
|
|
// CHECK-NEXT: call @body2(%{{.*}}, %{{.*}}) : (index, index) -> ()
|
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: call @post(%{{.*}}) : (index) -> ()
|
|
|
|
// CHECK-NEXT: }
|
2018-11-13 06:58:36 +08:00
|
|
|
// CHECK-NEXT: return
|
|
|
|
// CHECK-NEXT: }
|
2019-01-03 02:20:00 +08:00
|
|
|
func @imperfectly_nested_loops() {
|
2019-03-26 01:14:34 +08:00
|
|
|
affine.for %i = 0 to 42 {
|
2018-11-13 06:58:36 +08:00
|
|
|
call @pre(%i) : (index) -> ()
|
2019-03-26 01:14:34 +08:00
|
|
|
affine.for %j = 7 to 56 step 2 {
|
2018-11-13 06:58:36 +08:00
|
|
|
call @body2(%i, %j) : (index, index) -> ()
|
|
|
|
}
|
|
|
|
call @post(%i) : (index) -> ()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2020-11-14 05:04:53 +08:00
|
|
|
func private @mid(index) -> ()
|
|
|
|
func private @body3(index, index) -> ()
|
2018-11-13 06:58:36 +08:00
|
|
|
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-LABEL: func @more_imperfectly_nested_loops
|
|
|
|
// CHECK-NEXT: %[[c0:.*]] = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[c42:.*]] = constant 42 : index
|
|
|
|
// CHECK-NEXT: %[[c1:.*]] = constant 1 : index
|
|
|
|
// CHECK-NEXT: for %{{.*}} = %[[c0]] to %[[c42]] step %[[c1]] {
|
|
|
|
// CHECK-NEXT: call @pre(%{{.*}}) : (index) -> ()
|
|
|
|
// CHECK-NEXT: %[[c7:.*]] = constant 7 : index
|
|
|
|
// CHECK-NEXT: %[[c56:.*]] = constant 56 : index
|
|
|
|
// CHECK-NEXT: %[[c2:.*]] = constant 2 : index
|
|
|
|
// CHECK-NEXT: for %{{.*}} = %[[c7]] to %[[c56]] step %[[c2]] {
|
|
|
|
// CHECK-NEXT: call @body2(%{{.*}}, %{{.*}}) : (index, index) -> ()
|
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: call @mid(%{{.*}}) : (index) -> ()
|
|
|
|
// CHECK-NEXT: %[[c18:.*]] = constant 18 : index
|
|
|
|
// CHECK-NEXT: %[[c37:.*]] = constant 37 : index
|
|
|
|
// CHECK-NEXT: %[[c3:.*]] = constant 3 : index
|
|
|
|
// CHECK-NEXT: for %{{.*}} = %[[c18]] to %[[c37]] step %[[c3]] {
|
|
|
|
// CHECK-NEXT: call @body3(%{{.*}}, %{{.*}}) : (index, index) -> ()
|
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: call @post(%{{.*}}) : (index) -> ()
|
|
|
|
// CHECK-NEXT: }
|
2018-11-13 06:58:36 +08:00
|
|
|
// CHECK-NEXT: return
|
|
|
|
// CHECK-NEXT: }
|
2019-01-03 02:20:00 +08:00
|
|
|
func @more_imperfectly_nested_loops() {
|
2019-03-26 01:14:34 +08:00
|
|
|
affine.for %i = 0 to 42 {
|
2018-11-13 06:58:36 +08:00
|
|
|
call @pre(%i) : (index) -> ()
|
2019-03-26 01:14:34 +08:00
|
|
|
affine.for %j = 7 to 56 step 2 {
|
2018-11-13 06:58:36 +08:00
|
|
|
call @body2(%i, %j) : (index, index) -> ()
|
|
|
|
}
|
|
|
|
call @mid(%i) : (index) -> ()
|
2019-03-26 01:14:34 +08:00
|
|
|
affine.for %k = 18 to 37 step 3 {
|
2018-11-13 06:58:36 +08:00
|
|
|
call @body3(%i, %k) : (index, index) -> ()
|
|
|
|
}
|
|
|
|
call @post(%i) : (index) -> ()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2018-11-21 03:15:03 +08:00
|
|
|
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-LABEL: func @affine_apply_loops_shorthand
|
|
|
|
// CHECK-NEXT: %[[c0:.*]] = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[c1:.*]] = constant 1 : index
|
|
|
|
// CHECK-NEXT: for %{{.*}} = %[[c0]] to %{{.*}} step %[[c1]] {
|
|
|
|
// CHECK-NEXT: %[[c42:.*]] = constant 42 : index
|
|
|
|
// CHECK-NEXT: %[[c1_0:.*]] = constant 1 : index
|
|
|
|
// CHECK-NEXT: for %{{.*}} = %{{.*}} to %[[c42]] step %[[c1_0]] {
|
|
|
|
// CHECK-NEXT: call @body2(%{{.*}}, %{{.*}}) : (index, index) -> ()
|
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: }
|
2019-01-03 04:36:58 +08:00
|
|
|
// CHECK-NEXT: return
|
|
|
|
// CHECK-NEXT: }
|
2019-01-03 02:20:00 +08:00
|
|
|
func @affine_apply_loops_shorthand(%N : index) {
|
2019-03-26 01:14:34 +08:00
|
|
|
affine.for %i = 0 to %N {
|
2020-01-14 05:12:37 +08:00
|
|
|
affine.for %j = affine_map<(d0)[]->(d0)>(%i)[] to 42 {
|
2018-11-21 03:15:03 +08:00
|
|
|
call @body2(%i, %j) : (index, index) -> ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-12-04 23:04:44 +08:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2020-11-14 05:04:53 +08:00
|
|
|
func private @get_idx() -> (index)
|
2018-12-04 23:04:44 +08:00
|
|
|
|
2020-01-14 05:12:37 +08:00
|
|
|
#set1 = affine_set<(d0) : (20 - d0 >= 0)>
|
|
|
|
#set2 = affine_set<(d0) : (d0 - 10 >= 0)>
|
2018-12-04 23:04:44 +08:00
|
|
|
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-LABEL: func @if_only
|
|
|
|
// CHECK-NEXT: %[[v0:.*]] = call @get_idx() : () -> index
|
|
|
|
// CHECK-NEXT: %[[c0:.*]] = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[cm1:.*]] = constant -1 : index
|
|
|
|
// CHECK-NEXT: %[[v1:.*]] = muli %[[v0]], %[[cm1]] : index
|
|
|
|
// CHECK-NEXT: %[[c20:.*]] = constant 20 : index
|
|
|
|
// CHECK-NEXT: %[[v2:.*]] = addi %[[v1]], %[[c20]] : index
|
|
|
|
// CHECK-NEXT: %[[v3:.*]] = cmpi "sge", %[[v2]], %[[c0]] : index
|
|
|
|
// CHECK-NEXT: if %[[v3]] {
|
|
|
|
// CHECK-NEXT: call @body(%[[v0:.*]]) : (index) -> ()
|
|
|
|
// CHECK-NEXT: }
|
2018-12-04 23:04:44 +08:00
|
|
|
// CHECK-NEXT: return
|
|
|
|
// CHECK-NEXT: }
|
2019-01-03 02:20:00 +08:00
|
|
|
func @if_only() {
|
2018-12-04 23:04:44 +08:00
|
|
|
%i = call @get_idx() : () -> (index)
|
2019-03-25 11:35:07 +08:00
|
|
|
affine.if #set1(%i) {
|
2018-12-04 23:04:44 +08:00
|
|
|
call @body(%i) : (index) -> ()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-LABEL: func @if_else
|
|
|
|
// CHECK-NEXT: %[[v0:.*]] = call @get_idx() : () -> index
|
|
|
|
// CHECK-NEXT: %[[c0:.*]] = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[cm1:.*]] = constant -1 : index
|
|
|
|
// CHECK-NEXT: %[[v1:.*]] = muli %[[v0]], %[[cm1]] : index
|
|
|
|
// CHECK-NEXT: %[[c20:.*]] = constant 20 : index
|
|
|
|
// CHECK-NEXT: %[[v2:.*]] = addi %[[v1]], %[[c20]] : index
|
|
|
|
// CHECK-NEXT: %[[v3:.*]] = cmpi "sge", %[[v2]], %[[c0]] : index
|
|
|
|
// CHECK-NEXT: if %[[v3]] {
|
|
|
|
// CHECK-NEXT: call @body(%[[v0:.*]]) : (index) -> ()
|
|
|
|
// CHECK-NEXT: } else {
|
|
|
|
// CHECK-NEXT: call @mid(%[[v0:.*]]) : (index) -> ()
|
|
|
|
// CHECK-NEXT: }
|
2018-12-04 23:04:44 +08:00
|
|
|
// CHECK-NEXT: return
|
|
|
|
// CHECK-NEXT: }
|
2019-01-03 02:20:00 +08:00
|
|
|
func @if_else() {
|
2018-12-04 23:04:44 +08:00
|
|
|
%i = call @get_idx() : () -> (index)
|
2019-03-25 11:35:07 +08:00
|
|
|
affine.if #set1(%i) {
|
2018-12-04 23:04:44 +08:00
|
|
|
call @body(%i) : (index) -> ()
|
|
|
|
} else {
|
|
|
|
call @mid(%i) : (index) -> ()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-LABEL: func @nested_ifs
|
|
|
|
// CHECK-NEXT: %[[v0:.*]] = call @get_idx() : () -> index
|
|
|
|
// CHECK-NEXT: %[[c0:.*]] = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[cm1:.*]] = constant -1 : index
|
|
|
|
// CHECK-NEXT: %[[v1:.*]] = muli %[[v0]], %[[cm1]] : index
|
|
|
|
// CHECK-NEXT: %[[c20:.*]] = constant 20 : index
|
|
|
|
// CHECK-NEXT: %[[v2:.*]] = addi %[[v1]], %[[c20]] : index
|
|
|
|
// CHECK-NEXT: %[[v3:.*]] = cmpi "sge", %[[v2]], %[[c0]] : index
|
|
|
|
// CHECK-NEXT: if %[[v3]] {
|
|
|
|
// CHECK-NEXT: %[[c0_0:.*]] = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[cm10:.*]] = constant -10 : index
|
|
|
|
// CHECK-NEXT: %[[v4:.*]] = addi %[[v0]], %[[cm10]] : index
|
|
|
|
// CHECK-NEXT: %[[v5:.*]] = cmpi "sge", %[[v4]], %[[c0_0]] : index
|
|
|
|
// CHECK-NEXT: if %[[v5]] {
|
|
|
|
// CHECK-NEXT: call @body(%[[v0:.*]]) : (index) -> ()
|
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: } else {
|
|
|
|
// CHECK-NEXT: %[[c0_0:.*]] = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[cm10:.*]] = constant -10 : index
|
|
|
|
// CHECK-NEXT: %{{.*}} = addi %[[v0]], %[[cm10]] : index
|
|
|
|
// CHECK-NEXT: %{{.*}} = cmpi "sge", %{{.*}}, %[[c0_0]] : index
|
|
|
|
// CHECK-NEXT: if %{{.*}} {
|
|
|
|
// CHECK-NEXT: call @mid(%[[v0:.*]]) : (index) -> ()
|
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: }
|
2018-12-04 23:04:44 +08:00
|
|
|
// CHECK-NEXT: return
|
|
|
|
// CHECK-NEXT: }
|
2019-01-03 02:20:00 +08:00
|
|
|
func @nested_ifs() {
|
2018-12-04 23:04:44 +08:00
|
|
|
%i = call @get_idx() : () -> (index)
|
2019-03-25 11:35:07 +08:00
|
|
|
affine.if #set1(%i) {
|
|
|
|
affine.if #set2(%i) {
|
2018-12-04 23:04:44 +08:00
|
|
|
call @body(%i) : (index) -> ()
|
|
|
|
}
|
|
|
|
} else {
|
2019-03-25 11:35:07 +08:00
|
|
|
affine.if #set2(%i) {
|
2018-12-04 23:04:44 +08:00
|
|
|
call @mid(%i) : (index) -> ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-14 05:12:37 +08:00
|
|
|
#setN = affine_set<(d0)[N,M,K,L] : (N - d0 + 1 >= 0, N - 1 >= 0, M - 1 >= 0, K - 1 >= 0, L - 42 == 0)>
|
2018-12-04 23:04:44 +08:00
|
|
|
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-LABEL: func @multi_cond
|
|
|
|
// CHECK-NEXT: %[[v0:.*]] = call @get_idx() : () -> index
|
|
|
|
// CHECK-NEXT: %[[c0:.*]] = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[cm1:.*]] = constant -1 : index
|
|
|
|
// CHECK-NEXT: %[[v1:.*]] = muli %[[v0]], %[[cm1]] : index
|
|
|
|
// CHECK-NEXT: %[[v2:.*]] = addi %[[v1]], %{{.*}} : index
|
|
|
|
// CHECK-NEXT: %[[c1:.*]] = constant 1 : index
|
|
|
|
// CHECK-NEXT: %[[v3:.*]] = addi %[[v2]], %[[c1]] : index
|
|
|
|
// CHECK-NEXT: %[[v4:.*]] = cmpi "sge", %[[v3]], %[[c0]] : index
|
|
|
|
// CHECK-NEXT: %[[cm1_0:.*]] = constant -1 : index
|
|
|
|
// CHECK-NEXT: %[[v5:.*]] = addi %{{.*}}, %[[cm1_0]] : index
|
|
|
|
// CHECK-NEXT: %[[v6:.*]] = cmpi "sge", %[[v5]], %[[c0]] : index
|
|
|
|
// CHECK-NEXT: %[[v7:.*]] = and %[[v4]], %[[v6]] : i1
|
|
|
|
// CHECK-NEXT: %[[cm1_1:.*]] = constant -1 : index
|
|
|
|
// CHECK-NEXT: %[[v8:.*]] = addi %{{.*}}, %[[cm1_1]] : index
|
|
|
|
// CHECK-NEXT: %[[v9:.*]] = cmpi "sge", %[[v8]], %[[c0]] : index
|
|
|
|
// CHECK-NEXT: %[[v10:.*]] = and %[[v7]], %[[v9]] : i1
|
|
|
|
// CHECK-NEXT: %[[cm1_2:.*]] = constant -1 : index
|
|
|
|
// CHECK-NEXT: %[[v11:.*]] = addi %{{.*}}, %[[cm1_2]] : index
|
|
|
|
// CHECK-NEXT: %[[v12:.*]] = cmpi "sge", %[[v11]], %[[c0]] : index
|
|
|
|
// CHECK-NEXT: %[[v13:.*]] = and %[[v10]], %[[v12]] : i1
|
|
|
|
// CHECK-NEXT: %[[cm42:.*]] = constant -42 : index
|
|
|
|
// CHECK-NEXT: %[[v14:.*]] = addi %{{.*}}, %[[cm42]] : index
|
|
|
|
// CHECK-NEXT: %[[v15:.*]] = cmpi "eq", %[[v14]], %[[c0]] : index
|
|
|
|
// CHECK-NEXT: %[[v16:.*]] = and %[[v13]], %[[v15]] : i1
|
|
|
|
// CHECK-NEXT: if %[[v16]] {
|
|
|
|
// CHECK-NEXT: call @body(%[[v0:.*]]) : (index) -> ()
|
|
|
|
// CHECK-NEXT: } else {
|
|
|
|
// CHECK-NEXT: call @mid(%[[v0:.*]]) : (index) -> ()
|
|
|
|
// CHECK-NEXT: }
|
2018-12-04 23:04:44 +08:00
|
|
|
// CHECK-NEXT: return
|
|
|
|
// CHECK-NEXT: }
|
2019-01-03 02:20:00 +08:00
|
|
|
func @multi_cond(%N : index, %M : index, %K : index, %L : index) {
|
2018-12-04 23:04:44 +08:00
|
|
|
%i = call @get_idx() : () -> (index)
|
2019-03-25 11:35:07 +08:00
|
|
|
affine.if #setN(%i)[%N,%M,%K,%L] {
|
2018-12-04 23:04:44 +08:00
|
|
|
call @body(%i) : (index) -> ()
|
|
|
|
} else {
|
|
|
|
call @mid(%i) : (index) -> ()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-LABEL: func @if_for
|
2019-01-03 02:20:00 +08:00
|
|
|
func @if_for() {
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-NEXT: %[[v0:.*]] = call @get_idx() : () -> index
|
2018-12-04 23:04:44 +08:00
|
|
|
%i = call @get_idx() : () -> (index)
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-NEXT: %[[c0:.*]] = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[cm1:.*]] = constant -1 : index
|
|
|
|
// CHECK-NEXT: %[[v1:.*]] = muli %[[v0]], %[[cm1]] : index
|
|
|
|
// CHECK-NEXT: %[[c20:.*]] = constant 20 : index
|
|
|
|
// CHECK-NEXT: %[[v2:.*]] = addi %[[v1]], %[[c20]] : index
|
|
|
|
// CHECK-NEXT: %[[v3:.*]] = cmpi "sge", %[[v2]], %[[c0]] : index
|
|
|
|
// CHECK-NEXT: if %[[v3]] {
|
|
|
|
// CHECK-NEXT: %[[c0:.*]]{{.*}} = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[c42:.*]]{{.*}} = constant 42 : index
|
|
|
|
// CHECK-NEXT: %[[c1:.*]]{{.*}} = constant 1 : index
|
|
|
|
// CHECK-NEXT: for %{{.*}} = %[[c0:.*]]{{.*}} to %[[c42:.*]]{{.*}} step %[[c1:.*]]{{.*}} {
|
|
|
|
// CHECK-NEXT: %[[c0_:.*]]{{.*}} = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[cm10:.*]] = constant -10 : index
|
|
|
|
// CHECK-NEXT: %[[v4:.*]] = addi %{{.*}}, %[[cm10]] : index
|
|
|
|
// CHECK-NEXT: %[[v5:.*]] = cmpi "sge", %[[v4]], %[[c0_:.*]]{{.*}} : index
|
|
|
|
// CHECK-NEXT: if %[[v5]] {
|
|
|
|
// CHECK-NEXT: call @body2(%[[v0]], %{{.*}}) : (index, index) -> ()
|
2019-03-25 11:35:07 +08:00
|
|
|
affine.if #set1(%i) {
|
2019-03-26 01:14:34 +08:00
|
|
|
affine.for %j = 0 to 42 {
|
2019-03-25 11:35:07 +08:00
|
|
|
affine.if #set2(%j) {
|
2018-12-04 23:04:44 +08:00
|
|
|
call @body2(%i, %j) : (index, index) -> ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK: %[[c0:.*]]{{.*}} = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[c42:.*]]{{.*}} = constant 42 : index
|
|
|
|
// CHECK-NEXT: %[[c1:.*]]{{.*}} = constant 1 : index
|
|
|
|
// CHECK-NEXT: for %{{.*}} = %[[c0:.*]]{{.*}} to %[[c42:.*]]{{.*}} step %[[c1:.*]]{{.*}} {
|
|
|
|
// CHECK-NEXT: %[[c0:.*]]{{.*}} = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[cm10:.*]]{{.*}} = constant -10 : index
|
|
|
|
// CHECK-NEXT: %{{.*}} = addi %{{.*}}, %[[cm10:.*]]{{.*}} : index
|
|
|
|
// CHECK-NEXT: %{{.*}} = cmpi "sge", %{{.*}}, %[[c0:.*]]{{.*}} : index
|
|
|
|
// CHECK-NEXT: if %{{.*}} {
|
|
|
|
// CHECK-NEXT: %[[c0_:.*]]{{.*}} = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[c42_:.*]]{{.*}} = constant 42 : index
|
|
|
|
// CHECK-NEXT: %[[c1_:.*]]{{.*}} = constant 1 : index
|
|
|
|
// CHECK-NEXT: for %{{.*}} = %[[c0_:.*]]{{.*}} to %[[c42_:.*]]{{.*}} step %[[c1_:.*]]{{.*}} {
|
2019-03-26 01:14:34 +08:00
|
|
|
affine.for %k = 0 to 42 {
|
2019-03-25 11:35:07 +08:00
|
|
|
affine.if #set2(%k) {
|
2019-03-26 01:14:34 +08:00
|
|
|
affine.for %l = 0 to 42 {
|
2018-12-04 23:04:44 +08:00
|
|
|
call @body3(%k, %l) : (index, index) -> ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK: return
|
2018-12-04 23:04:44 +08:00
|
|
|
return
|
|
|
|
}
|
2018-12-07 03:34:27 +08:00
|
|
|
|
2020-01-14 05:12:37 +08:00
|
|
|
#lbMultiMap = affine_map<(d0)[s0] -> (d0, s0 - d0)>
|
|
|
|
#ubMultiMap = affine_map<(d0)[s0] -> (s0, d0 + 10)>
|
2018-12-07 03:34:27 +08:00
|
|
|
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-LABEL: func @loop_min_max
|
|
|
|
// CHECK-NEXT: %[[c0:.*]] = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[c42:.*]] = constant 42 : index
|
|
|
|
// CHECK-NEXT: %[[c1:.*]] = constant 1 : index
|
|
|
|
// CHECK-NEXT: for %{{.*}} = %[[c0]] to %[[c42]] step %[[c1]] {
|
|
|
|
// CHECK-NEXT: %[[cm1:.*]] = constant -1 : index
|
|
|
|
// CHECK-NEXT: %[[a:.*]] = muli %{{.*}}, %[[cm1]] : index
|
|
|
|
// CHECK-NEXT: %[[b:.*]] = addi %[[a]], %{{.*}} : index
|
|
|
|
// CHECK-NEXT: %[[c:.*]] = cmpi "sgt", %{{.*}}, %[[b]] : index
|
|
|
|
// CHECK-NEXT: %[[d:.*]] = select %[[c]], %{{.*}}, %[[b]] : index
|
|
|
|
// CHECK-NEXT: %[[c10:.*]] = constant 10 : index
|
|
|
|
// CHECK-NEXT: %[[e:.*]] = addi %{{.*}}, %[[c10]] : index
|
|
|
|
// CHECK-NEXT: %[[f:.*]] = cmpi "slt", %{{.*}}, %[[e]] : index
|
|
|
|
// CHECK-NEXT: %[[g:.*]] = select %[[f]], %{{.*}}, %[[e]] : index
|
|
|
|
// CHECK-NEXT: %[[c1_0:.*]] = constant 1 : index
|
2020-06-12 08:34:35 +08:00
|
|
|
// CHECK-NEXT: for %{{.*}} = %[[d]] to %[[g]] step %[[c1_0]] {
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-NEXT: call @body2(%{{.*}}, %{{.*}}) : (index, index) -> ()
|
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: }
|
2018-12-07 03:34:27 +08:00
|
|
|
// CHECK-NEXT: return
|
|
|
|
// CHECK-NEXT: }
|
2019-01-03 02:20:00 +08:00
|
|
|
func @loop_min_max(%N : index) {
|
2019-03-26 01:14:34 +08:00
|
|
|
affine.for %i = 0 to 42 {
|
|
|
|
affine.for %j = max #lbMultiMap(%i)[%N] to min #ubMultiMap(%i)[%N] {
|
2018-12-07 03:34:27 +08:00
|
|
|
call @body2(%i, %j) : (index, index) -> ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-04-02 03:58:09 +08:00
|
|
|
#map_7_values = affine_map<(d0, d1, d2, d3, d4, d5, d6) -> (d0, d1, d2, d3, d4, d5, d6)>
|
2018-12-07 03:34:27 +08:00
|
|
|
|
|
|
|
// Check that the "min" (cmpi "slt" + select) reduction sequence is emitted
|
2020-04-05 10:30:01 +08:00
|
|
|
// correctly for an affine map with 7 results.
|
2018-12-07 03:34:27 +08:00
|
|
|
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-LABEL: func @min_reduction_tree
|
|
|
|
// CHECK-NEXT: %[[c0:.*]] = constant 0 : index
|
2019-07-10 01:40:29 +08:00
|
|
|
// CHECK-NEXT: %[[c01:.+]] = cmpi "slt", %{{.*}}, %{{.*}} : index
|
|
|
|
// CHECK-NEXT: %[[r01:.+]] = select %[[c01]], %{{.*}}, %{{.*}} : index
|
|
|
|
// CHECK-NEXT: %[[c012:.+]] = cmpi "slt", %[[r01]], %{{.*}} : index
|
|
|
|
// CHECK-NEXT: %[[r012:.+]] = select %[[c012]], %[[r01]], %{{.*}} : index
|
|
|
|
// CHECK-NEXT: %[[c0123:.+]] = cmpi "slt", %[[r012]], %{{.*}} : index
|
|
|
|
// CHECK-NEXT: %[[r0123:.+]] = select %[[c0123]], %[[r012]], %{{.*}} : index
|
|
|
|
// CHECK-NEXT: %[[c01234:.+]] = cmpi "slt", %[[r0123]], %{{.*}} : index
|
|
|
|
// CHECK-NEXT: %[[r01234:.+]] = select %[[c01234]], %[[r0123]], %{{.*}} : index
|
|
|
|
// CHECK-NEXT: %[[c012345:.+]] = cmpi "slt", %[[r01234]], %{{.*}} : index
|
|
|
|
// CHECK-NEXT: %[[r012345:.+]] = select %[[c012345]], %[[r01234]], %{{.*}} : index
|
|
|
|
// CHECK-NEXT: %[[c0123456:.+]] = cmpi "slt", %[[r012345]], %{{.*}} : index
|
|
|
|
// CHECK-NEXT: %[[r0123456:.+]] = select %[[c0123456]], %[[r012345]], %{{.*}} : index
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-NEXT: %[[c1:.*]] = constant 1 : index
|
2020-06-12 08:34:35 +08:00
|
|
|
// CHECK-NEXT: for %{{.*}} = %[[c0]] to %[[r0123456]] step %[[c1]] {
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-NEXT: call @body(%{{.*}}) : (index) -> ()
|
|
|
|
// CHECK-NEXT: }
|
2018-12-07 03:34:27 +08:00
|
|
|
// CHECK-NEXT: return
|
|
|
|
// CHECK-NEXT: }
|
2020-04-02 03:58:09 +08:00
|
|
|
func @min_reduction_tree(%v1 : index, %v2 : index, %v3 : index, %v4 : index, %v5 : index, %v6 : index, %v7 : index) {
|
|
|
|
affine.for %i = 0 to min #map_7_values(%v1, %v2, %v3, %v4, %v5, %v6, %v7)[] {
|
2018-12-07 03:34:27 +08:00
|
|
|
call @body(%i) : (index) -> ()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2019-01-03 04:52:41 +08:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2020-01-14 05:12:37 +08:00
|
|
|
#map0 = affine_map<() -> (0)>
|
|
|
|
#map1 = affine_map<()[s0] -> (s0)>
|
|
|
|
#map2 = affine_map<(d0) -> (d0)>
|
|
|
|
#map3 = affine_map<(d0)[s0] -> (d0 + s0 + 1)>
|
|
|
|
#map4 = affine_map<(d0,d1,d2,d3)[s0,s1,s2] -> (d0 + 2*d1 + 3*d2 + 4*d3 + 5*s0 + 6*s1 + 7*s2)>
|
|
|
|
#map5 = affine_map<(d0,d1,d2) -> (d0,d1,d2)>
|
|
|
|
#map6 = affine_map<(d0,d1,d2) -> (d0 + d1 + d2)>
|
2019-01-03 04:52:41 +08:00
|
|
|
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-LABEL: func @affine_applies(
|
2019-12-14 04:21:42 +08:00
|
|
|
func @affine_applies(%arg0 : index) {
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK: %[[c0:.*]] = constant 0 : index
|
2019-02-07 03:08:18 +08:00
|
|
|
%zero = affine.apply #map0()
|
2019-01-03 04:52:41 +08:00
|
|
|
|
|
|
|
// Identity maps are just discarded.
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-NEXT: %[[c101:.*]] = constant 101 : index
|
2019-01-03 04:52:41 +08:00
|
|
|
%101 = constant 101 : index
|
2019-02-07 03:08:18 +08:00
|
|
|
%symbZero = affine.apply #map1()[%zero]
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-NEXT: %[[c102:.*]] = constant 102 : index
|
2019-01-03 04:52:41 +08:00
|
|
|
%102 = constant 102 : index
|
2019-02-07 03:08:18 +08:00
|
|
|
%copy = affine.apply #map2(%zero)
|
2019-01-03 04:52:41 +08:00
|
|
|
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-NEXT: %[[v0:.*]] = addi %[[c0]], %[[c0]] : index
|
|
|
|
// CHECK-NEXT: %[[c1:.*]] = constant 1 : index
|
|
|
|
// CHECK-NEXT: %[[v1:.*]] = addi %[[v0]], %[[c1]] : index
|
2019-02-07 03:08:18 +08:00
|
|
|
%one = affine.apply #map3(%symbZero)[%zero]
|
2019-01-03 04:52:41 +08:00
|
|
|
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-NEXT: %[[c2:.*]] = constant 2 : index
|
2019-12-14 04:21:42 +08:00
|
|
|
// CHECK-NEXT: %[[v2:.*]] = muli %arg0, %[[c2]] : index
|
|
|
|
// CHECK-NEXT: %[[v3:.*]] = addi %arg0, %[[v2]] : index
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-NEXT: %[[c3:.*]] = constant 3 : index
|
2019-12-14 04:21:42 +08:00
|
|
|
// CHECK-NEXT: %[[v4:.*]] = muli %arg0, %[[c3]] : index
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-NEXT: %[[v5:.*]] = addi %[[v3]], %[[v4]] : index
|
|
|
|
// CHECK-NEXT: %[[c4:.*]] = constant 4 : index
|
2019-12-14 04:21:42 +08:00
|
|
|
// CHECK-NEXT: %[[v6:.*]] = muli %arg0, %[[c4]] : index
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-NEXT: %[[v7:.*]] = addi %[[v5]], %[[v6]] : index
|
|
|
|
// CHECK-NEXT: %[[c5:.*]] = constant 5 : index
|
2019-12-14 04:21:42 +08:00
|
|
|
// CHECK-NEXT: %[[v8:.*]] = muli %arg0, %[[c5]] : index
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-NEXT: %[[v9:.*]] = addi %[[v7]], %[[v8]] : index
|
|
|
|
// CHECK-NEXT: %[[c6:.*]] = constant 6 : index
|
2019-12-14 04:21:42 +08:00
|
|
|
// CHECK-NEXT: %[[v10:.*]] = muli %arg0, %[[c6]] : index
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-NEXT: %[[v11:.*]] = addi %[[v9]], %[[v10]] : index
|
|
|
|
// CHECK-NEXT: %[[c7:.*]] = constant 7 : index
|
2019-12-14 04:21:42 +08:00
|
|
|
// CHECK-NEXT: %[[v12:.*]] = muli %arg0, %[[c7]] : index
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-NEXT: %[[v13:.*]] = addi %[[v11]], %[[v12]] : index
|
2019-12-14 04:21:42 +08:00
|
|
|
%four = affine.apply #map4(%arg0, %arg0, %arg0, %arg0)[%arg0, %arg0, %arg0]
|
2019-01-03 04:52:41 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-LABEL: func @args_ret_affine_apply(
|
2019-01-03 04:52:41 +08:00
|
|
|
func @args_ret_affine_apply(index, index) -> (index, index) {
|
|
|
|
^bb0(%0 : index, %1 : index):
|
2019-07-10 01:40:29 +08:00
|
|
|
// CHECK-NEXT: return %{{.*}}, %{{.*}} : index, index
|
2019-02-07 03:08:18 +08:00
|
|
|
%00 = affine.apply #map2 (%0)
|
|
|
|
%11 = affine.apply #map1 ()[%1]
|
2019-01-03 04:52:41 +08:00
|
|
|
return %00, %11 : index, index
|
|
|
|
}
|
2019-01-10 17:44:32 +08:00
|
|
|
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
// Test lowering of Euclidean (floor) division, ceil division and modulo
|
|
|
|
// operation used in affine expressions. In addition to testing the
|
2019-03-28 23:24:38 +08:00
|
|
|
// operation-level output, check that the obtained results are correct by
|
2019-01-10 17:44:32 +08:00
|
|
|
// applying constant folding transformation after affine lowering.
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
|
2020-01-14 05:12:37 +08:00
|
|
|
#mapmod = affine_map<(i) -> (i mod 42)>
|
2019-01-10 17:44:32 +08:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------//
|
|
|
|
// IMPORTANT NOTE: if you change this test, also change the @lowered_affine_mod
|
|
|
|
// test in the "constant-fold.mlir" test to reflect the expected output of
|
2019-02-07 03:08:18 +08:00
|
|
|
// affine.apply lowering.
|
2019-01-10 17:44:32 +08:00
|
|
|
// --------------------------------------------------------------------------//
|
|
|
|
// CHECK-LABEL: func @affine_apply_mod
|
|
|
|
func @affine_apply_mod(%arg0 : index) -> (index) {
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-NEXT: %[[c42:.*]] = constant 42 : index
|
2019-12-23 02:01:35 +08:00
|
|
|
// CHECK-NEXT: %[[v0:.*]] = remi_signed %{{.*}}, %[[c42]] : index
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-NEXT: %[[c0:.*]] = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[v1:.*]] = cmpi "slt", %[[v0]], %[[c0]] : index
|
|
|
|
// CHECK-NEXT: %[[v2:.*]] = addi %[[v0]], %[[c42]] : index
|
|
|
|
// CHECK-NEXT: %[[v3:.*]] = select %[[v1]], %[[v2]], %[[v0]] : index
|
2019-02-07 03:08:18 +08:00
|
|
|
%0 = affine.apply #mapmod (%arg0)
|
2019-01-10 17:44:32 +08:00
|
|
|
return %0 : index
|
|
|
|
}
|
|
|
|
|
2020-01-14 05:12:37 +08:00
|
|
|
#mapfloordiv = affine_map<(i) -> (i floordiv 42)>
|
2019-01-10 17:44:32 +08:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------//
|
|
|
|
// IMPORTANT NOTE: if you change this test, also change the @lowered_affine_mod
|
|
|
|
// test in the "constant-fold.mlir" test to reflect the expected output of
|
2019-02-07 03:08:18 +08:00
|
|
|
// affine.apply lowering.
|
2019-01-10 17:44:32 +08:00
|
|
|
// --------------------------------------------------------------------------//
|
|
|
|
// CHECK-LABEL: func @affine_apply_floordiv
|
|
|
|
func @affine_apply_floordiv(%arg0 : index) -> (index) {
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-NEXT: %[[c42:.*]] = constant 42 : index
|
|
|
|
// CHECK-NEXT: %[[c0:.*]] = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[cm1:.*]] = constant -1 : index
|
|
|
|
// CHECK-NEXT: %[[v0:.*]] = cmpi "slt", %{{.*}}, %[[c0]] : index
|
|
|
|
// CHECK-NEXT: %[[v1:.*]] = subi %[[cm1]], %{{.*}} : index
|
|
|
|
// CHECK-NEXT: %[[v2:.*]] = select %[[v0]], %[[v1]], %{{.*}} : index
|
2019-12-23 02:01:35 +08:00
|
|
|
// CHECK-NEXT: %[[v3:.*]] = divi_signed %[[v2]], %[[c42]] : index
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-NEXT: %[[v4:.*]] = subi %[[cm1]], %[[v3]] : index
|
|
|
|
// CHECK-NEXT: %[[v5:.*]] = select %[[v0]], %[[v4]], %[[v3]] : index
|
2019-02-07 03:08:18 +08:00
|
|
|
%0 = affine.apply #mapfloordiv (%arg0)
|
2019-01-10 17:44:32 +08:00
|
|
|
return %0 : index
|
|
|
|
}
|
|
|
|
|
2020-01-14 05:12:37 +08:00
|
|
|
#mapceildiv = affine_map<(i) -> (i ceildiv 42)>
|
2019-01-10 17:44:32 +08:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------//
|
|
|
|
// IMPORTANT NOTE: if you change this test, also change the @lowered_affine_mod
|
|
|
|
// test in the "constant-fold.mlir" test to reflect the expected output of
|
2019-02-07 03:08:18 +08:00
|
|
|
// affine.apply lowering.
|
2019-01-10 17:44:32 +08:00
|
|
|
// --------------------------------------------------------------------------//
|
|
|
|
// CHECK-LABEL: func @affine_apply_ceildiv
|
|
|
|
func @affine_apply_ceildiv(%arg0 : index) -> (index) {
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-NEXT: %[[c42:.*]] = constant 42 : index
|
|
|
|
// CHECK-NEXT: %[[c0:.*]] = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[c1:.*]] = constant 1 : index
|
|
|
|
// CHECK-NEXT: %[[v0:.*]] = cmpi "sle", %{{.*}}, %[[c0]] : index
|
|
|
|
// CHECK-NEXT: %[[v1:.*]] = subi %[[c0]], %{{.*}} : index
|
|
|
|
// CHECK-NEXT: %[[v2:.*]] = subi %{{.*}}, %[[c1]] : index
|
|
|
|
// CHECK-NEXT: %[[v3:.*]] = select %[[v0]], %[[v1]], %[[v2]] : index
|
2019-12-23 02:01:35 +08:00
|
|
|
// CHECK-NEXT: %[[v4:.*]] = divi_signed %[[v3]], %[[c42]] : index
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK-NEXT: %[[v5:.*]] = subi %[[c0]], %[[v4]] : index
|
|
|
|
// CHECK-NEXT: %[[v6:.*]] = addi %[[v4]], %[[c1]] : index
|
|
|
|
// CHECK-NEXT: %[[v7:.*]] = select %[[v0]], %[[v5]], %[[v6]] : index
|
2019-02-07 03:08:18 +08:00
|
|
|
%0 = affine.apply #mapceildiv (%arg0)
|
2019-01-10 17:44:32 +08:00
|
|
|
return %0 : index
|
|
|
|
}
|
2019-07-01 23:32:44 +08:00
|
|
|
|
|
|
|
// CHECK-LABEL: func @affine_load
|
|
|
|
func @affine_load(%arg0 : index) {
|
|
|
|
%0 = alloc() : memref<10xf32>
|
|
|
|
affine.for %i0 = 0 to 10 {
|
|
|
|
%1 = affine.load %0[%i0 + symbol(%arg0) + 7] : memref<10xf32>
|
|
|
|
}
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK: %[[a:.*]] = addi %{{.*}}, %{{.*}} : index
|
|
|
|
// CHECK-NEXT: %[[c7:.*]] = constant 7 : index
|
|
|
|
// CHECK-NEXT: %[[b:.*]] = addi %[[a]], %[[c7]] : index
|
|
|
|
// CHECK-NEXT: %{{.*}} = load %[[v0:.*]][%[[b]]] : memref<10xf32>
|
2019-07-01 23:32:44 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: func @affine_store
|
|
|
|
func @affine_store(%arg0 : index) {
|
|
|
|
%0 = alloc() : memref<10xf32>
|
2019-07-12 21:48:45 +08:00
|
|
|
%1 = constant 11.0 : f32
|
2019-07-01 23:32:44 +08:00
|
|
|
affine.for %i0 = 0 to 10 {
|
|
|
|
affine.store %1, %0[%i0 - symbol(%arg0) + 7] : memref<10xf32>
|
|
|
|
}
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK: %c-1 = constant -1 : index
|
|
|
|
// CHECK-NEXT: %[[a:.*]] = muli %arg0, %c-1 : index
|
|
|
|
// CHECK-NEXT: %[[b:.*]] = addi %{{.*}}, %[[a]] : index
|
|
|
|
// CHECK-NEXT: %c7 = constant 7 : index
|
|
|
|
// CHECK-NEXT: %[[c:.*]] = addi %[[b]], %c7 : index
|
|
|
|
// CHECK-NEXT: store %cst, %0[%[[c]]] : memref<10xf32>
|
2019-07-01 23:32:44 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-11-21 08:30:14 +08:00
|
|
|
// CHECK-LABEL: func @affine_load_store_zero_dim
|
|
|
|
func @affine_load_store_zero_dim(%arg0 : memref<i32>, %arg1 : memref<i32>) {
|
|
|
|
%0 = affine.load %arg0[] : memref<i32>
|
|
|
|
affine.store %0, %arg1[] : memref<i32>
|
|
|
|
// CHECK: %[[x:.*]] = load %arg0[] : memref<i32>
|
|
|
|
// CHECK: store %[[x]], %arg1[] : memref<i32>
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-12-19 01:59:37 +08:00
|
|
|
// CHECK-LABEL: func @affine_prefetch
|
|
|
|
func @affine_prefetch(%arg0 : index) {
|
|
|
|
%0 = alloc() : memref<10xf32>
|
|
|
|
affine.for %i0 = 0 to 10 {
|
|
|
|
affine.prefetch %0[%i0 + symbol(%arg0) + 7], read, locality<3>, data : memref<10xf32>
|
|
|
|
}
|
|
|
|
// CHECK: %[[a:.*]] = addi %{{.*}}, %{{.*}} : index
|
|
|
|
// CHECK-NEXT: %[[c7:.*]] = constant 7 : index
|
|
|
|
// CHECK-NEXT: %[[b:.*]] = addi %[[a]], %[[c7]] : index
|
|
|
|
// CHECK-NEXT: prefetch %[[v0:.*]][%[[b]]], read, locality<3>, data : memref<10xf32>
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-07-01 23:32:44 +08:00
|
|
|
// CHECK-LABEL: func @affine_dma_start
|
|
|
|
func @affine_dma_start(%arg0 : index) {
|
|
|
|
%0 = alloc() : memref<100xf32>
|
|
|
|
%1 = alloc() : memref<100xf32, 2>
|
|
|
|
%2 = alloc() : memref<1xi32>
|
|
|
|
%c0 = constant 0 : index
|
|
|
|
%c64 = constant 64 : index
|
|
|
|
affine.for %i0 = 0 to 10 {
|
|
|
|
affine.dma_start %0[%i0 + 7], %1[%arg0 + 11], %2[%c0], %c64
|
|
|
|
: memref<100xf32>, memref<100xf32, 2>, memref<1xi32>
|
|
|
|
}
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK: %c7 = constant 7 : index
|
|
|
|
// CHECK-NEXT: %[[a:.*]] = addi %{{.*}}, %c7 : index
|
|
|
|
// CHECK-NEXT: %c11 = constant 11 : index
|
|
|
|
// CHECK-NEXT: %[[b:.*]] = addi %arg0, %c11 : index
|
|
|
|
// CHECK-NEXT: dma_start %0[%[[a]]], %1[%[[b]]], %c64, %2[%c0] : memref<100xf32>, memref<100xf32, 2>, memref<1xi32>
|
2019-07-01 23:32:44 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: func @affine_dma_wait
|
|
|
|
func @affine_dma_wait(%arg0 : index) {
|
|
|
|
%2 = alloc() : memref<1xi32>
|
|
|
|
%c64 = constant 64 : index
|
|
|
|
affine.for %i0 = 0 to 10 {
|
|
|
|
affine.dma_wait %2[%i0 + %arg0 + 17], %c64 : memref<1xi32>
|
|
|
|
}
|
2019-07-12 21:48:45 +08:00
|
|
|
// CHECK: %[[a:.*]] = addi %{{.*}}, %arg0 : index
|
|
|
|
// CHECK-NEXT: %c17 = constant 17 : index
|
|
|
|
// CHECK-NEXT: %[[b:.*]] = addi %[[a]], %c17 : index
|
|
|
|
// CHECK-NEXT: dma_wait %0[%[[b]]], %c64 : memref<1xi32>
|
2019-07-01 23:32:44 +08:00
|
|
|
return
|
|
|
|
}
|
2020-01-28 00:14:56 +08:00
|
|
|
|
|
|
|
// CHECK-LABEL: func @affine_min
|
|
|
|
// CHECK-SAME: %[[ARG0:.*]]: index, %[[ARG1:.*]]: index
|
|
|
|
func @affine_min(%arg0: index, %arg1: index) -> index{
|
|
|
|
// CHECK: %[[Cm1:.*]] = constant -1
|
|
|
|
// CHECK: %[[neg1:.*]] = muli %[[ARG1]], %[[Cm1:.*]]
|
|
|
|
// CHECK: %[[first:.*]] = addi %[[ARG0]], %[[neg1]]
|
|
|
|
// CHECK: %[[Cm2:.*]] = constant -1
|
|
|
|
// CHECK: %[[neg2:.*]] = muli %[[ARG0]], %[[Cm2:.*]]
|
|
|
|
// CHECK: %[[second:.*]] = addi %[[ARG1]], %[[neg2]]
|
|
|
|
// CHECK: %[[cmp:.*]] = cmpi "slt", %[[first]], %[[second]]
|
|
|
|
// CHECK: select %[[cmp]], %[[first]], %[[second]]
|
|
|
|
%0 = affine.min affine_map<(d0,d1) -> (d0 - d1, d1 - d0)>(%arg0, %arg1)
|
|
|
|
return %0 : index
|
|
|
|
}
|
2020-02-06 17:25:55 +08:00
|
|
|
|
|
|
|
// CHECK-LABEL: func @affine_max
|
|
|
|
// CHECK-SAME: %[[ARG0:.*]]: index, %[[ARG1:.*]]: index
|
|
|
|
func @affine_max(%arg0: index, %arg1: index) -> index{
|
|
|
|
// CHECK: %[[Cm1:.*]] = constant -1
|
|
|
|
// CHECK: %[[neg1:.*]] = muli %[[ARG1]], %[[Cm1:.*]]
|
|
|
|
// CHECK: %[[first:.*]] = addi %[[ARG0]], %[[neg1]]
|
|
|
|
// CHECK: %[[Cm2:.*]] = constant -1
|
|
|
|
// CHECK: %[[neg2:.*]] = muli %[[ARG0]], %[[Cm2:.*]]
|
|
|
|
// CHECK: %[[second:.*]] = addi %[[ARG1]], %[[neg2]]
|
|
|
|
// CHECK: %[[cmp:.*]] = cmpi "sgt", %[[first]], %[[second]]
|
|
|
|
// CHECK: select %[[cmp]], %[[first]], %[[second]]
|
|
|
|
%0 = affine.max affine_map<(d0,d1) -> (d0 - d1, d1 - d0)>(%arg0, %arg1)
|
|
|
|
return %0 : index
|
2020-04-02 03:58:09 +08:00
|
|
|
}
|
2020-07-18 15:39:30 +08:00
|
|
|
|
|
|
|
// CHECK-LABEL: func @affine_parallel(
|
|
|
|
// CHECK-SAME: %[[ARG0:.*]]: memref<100x100xf32>, %[[ARG1:.*]]: memref<100x100xf32>) {
|
|
|
|
func @affine_parallel(%o: memref<100x100xf32>, %a: memref<100x100xf32>) {
|
|
|
|
affine.parallel (%i, %j) = (0, 0) to (100, 100) {
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-DAG: %[[C100:.*]] = constant 100
|
|
|
|
// CHECK-DAG: %[[C100_1:.*]] = constant 100
|
|
|
|
// CHECK-DAG: %[[C0:.*]] = constant 0
|
|
|
|
// CHECK-DAG: %[[C0_1:.*]] = constant 0
|
|
|
|
// CHECK-DAG: %[[C1:.*]] = constant 1
|
|
|
|
// CHECK-DAG: %[[C1_1:.*]] = constant 1
|
|
|
|
// CHECK-DAG: scf.parallel (%arg2, %arg3) = (%[[C0]], %[[C0_1]]) to (%[[C100]], %[[C100_1]]) step (%[[C1]], %[[C1_1]]) {
|
|
|
|
|
|
|
|
// CHECK-LABEL: func @affine_parallel_tiled(
|
|
|
|
// CHECK-SAME: %[[ARG0:.*]]: memref<100x100xf32>, %[[ARG1:.*]]: memref<100x100xf32>, %[[ARG2:.*]]: memref<100x100xf32>) {
|
|
|
|
func @affine_parallel_tiled(%o: memref<100x100xf32>, %a: memref<100x100xf32>, %b: memref<100x100xf32>) {
|
|
|
|
affine.parallel (%i0, %j0, %k0) = (0, 0, 0) to (100, 100, 100) step (10, 10, 10) {
|
|
|
|
affine.parallel (%i1, %j1, %k1) = (%i0, %j0, %k0) to (%i0 + 10, %j0 + 10, %k0 + 10) {
|
|
|
|
%0 = affine.load %a[%i1, %k1] : memref<100x100xf32>
|
|
|
|
%1 = affine.load %b[%k1, %j1] : memref<100x100xf32>
|
|
|
|
%2 = mulf %0, %1 : f32
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-DAG: %[[C100:.*]] = constant 100
|
|
|
|
// CHECK-DAG: %[[C100_0:.*]] = constant 100
|
|
|
|
// CHECK-DAG: %[[C100_1:.*]] = constant 100
|
|
|
|
// CHECK-DAG: %[[C0:.*]] = constant 0
|
|
|
|
// CHECK-DAG: %[[C0_2:.*]] = constant 0
|
|
|
|
// CHECK-DAG: %[[C0_3:.*]] = constant 0
|
|
|
|
// CHECK-DAG: %[[C10:.*]] = constant 10
|
|
|
|
// CHECK-DAG: %[[C10_4:.*]] = constant 10
|
|
|
|
// CHECK-DAG: %[[C10_5:.*]] = constant 10
|
|
|
|
// CHECK: scf.parallel (%[[arg3:.*]], %[[arg4:.*]], %[[arg5:.*]]) = (%[[C0]], %[[C0_2]], %[[C0_3]]) to (%[[C100]], %[[C100_0]], %[[C100_1]]) step (%[[C10]], %[[C10_4]], %[[C10_5]]) {
|
|
|
|
// CHECK-DAG: %[[C10_6:.*]] = constant 10
|
|
|
|
// CHECK-DAG: %[[A0:.*]] = addi %[[arg3]], %[[C10_6]]
|
|
|
|
// CHECK-DAG: %[[C10_7:.*]] = constant 10
|
|
|
|
// CHECK-DAG: %[[A1:.*]] = addi %[[arg4]], %[[C10_7]]
|
|
|
|
// CHECK-DAG: %[[C10_8:.*]] = constant 10
|
|
|
|
// CHECK-DAG: %[[A2:.*]] = addi %[[arg5]], %[[C10_8]]
|
|
|
|
// CHECK-DAG: %[[C1:.*]] = constant 1
|
|
|
|
// CHECK-DAG: %[[C1_9:.*]] = constant 1
|
|
|
|
// CHECK-DAG: %[[C1_10:.*]] = constant 1
|
|
|
|
// CHECK: scf.parallel (%[[arg6:.*]], %[[arg7:.*]], %[[arg8:.*]]) = (%[[arg3]], %[[arg4]], %[[arg5]]) to (%[[A0]], %[[A1]], %[[A2]]) step (%[[C1]], %[[C1_9]], %[[C1_10]]) {
|
|
|
|
// CHECK: %[[A3:.*]] = load %[[ARG1]][%[[arg6]], %[[arg8]]] : memref<100x100xf32>
|
|
|
|
// CHECK: %[[A4:.*]] = load %[[ARG2]][%[[arg8]], %[[arg7]]] : memref<100x100xf32>
|
|
|
|
// CHECK: mulf %[[A3]], %[[A4]] : f32
|
|
|
|
// CHECK: scf.yield
|
2020-12-23 00:10:17 +08:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
func @affine_parallel_simple(%arg0: memref<3x3xf32>, %arg1: memref<3x3xf32>) -> (memref<3x3xf32>) {
|
|
|
|
%O = alloc() : memref<3x3xf32>
|
|
|
|
affine.parallel (%kx, %ky) = (0, 0) to (2, 2) {
|
|
|
|
%1 = affine.load %arg0[%kx, %ky] : memref<3x3xf32>
|
|
|
|
%2 = affine.load %arg1[%kx, %ky] : memref<3x3xf32>
|
|
|
|
%3 = mulf %1, %2 : f32
|
|
|
|
affine.store %3, %O[%kx, %ky] : memref<3x3xf32>
|
|
|
|
}
|
|
|
|
return %O : memref<3x3xf32>
|
|
|
|
}
|
|
|
|
// CHECK-LABEL: func @affine_parallel_simple
|
|
|
|
// CHECK: %[[LOWER_1:.*]] = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[LOWER_2:.*]] = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[UPPER_1:.*]] = constant 2 : index
|
|
|
|
// CHECK-NEXT: %[[UPPER_2:.*]] = constant 2 : index
|
|
|
|
// CHECK-NEXT: %[[STEP_1:.*]] = constant 1 : index
|
|
|
|
// CHECK-NEXT: %[[STEP_2:.*]] = constant 1 : index
|
|
|
|
// CHECK-NEXT: scf.parallel (%[[I:.*]], %[[J:.*]]) = (%[[LOWER_1]], %[[LOWER_2]]) to (%[[UPPER_1]], %[[UPPER_2]]) step (%[[STEP_1]], %[[STEP_2]]) {
|
|
|
|
// CHECK-NEXT: %[[VAL_1:.*]] = load
|
|
|
|
// CHECK-NEXT: %[[VAL_2:.*]] = load
|
|
|
|
// CHECK-NEXT: %[[PRODUCT:.*]] = mulf
|
|
|
|
// CHECK-NEXT: store
|
|
|
|
// CHECK-NEXT: scf.yield
|
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: return
|
|
|
|
// CHECK-NEXT: }
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
func @affine_parallel_simple_dynamic_bounds(%arg0: memref<?x?xf32>, %arg1: memref<?x?xf32>, %arg2: memref<?x?xf32>) {
|
|
|
|
%c_0 = constant 0 : index
|
|
|
|
%output_dim = dim %arg0, %c_0 : memref<?x?xf32>
|
|
|
|
affine.parallel (%kx, %ky) = (%c_0, %c_0) to (%output_dim, %output_dim) {
|
|
|
|
%1 = affine.load %arg0[%kx, %ky] : memref<?x?xf32>
|
|
|
|
%2 = affine.load %arg1[%kx, %ky] : memref<?x?xf32>
|
|
|
|
%3 = mulf %1, %2 : f32
|
|
|
|
affine.store %3, %arg2[%kx, %ky] : memref<?x?xf32>
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// CHECK-LABEL: func @affine_parallel_simple_dynamic_bounds
|
|
|
|
// CHECK-SAME: %[[ARG_0:.*]]: memref<?x?xf32>, %[[ARG_1:.*]]: memref<?x?xf32>, %[[ARG_2:.*]]: memref<?x?xf32>
|
|
|
|
// CHECK: %[[DIM_INDEX:.*]] = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[UPPER:.*]] = dim %[[ARG_0]], %[[DIM_INDEX]] : memref<?x?xf32>
|
|
|
|
// CHECK-NEXT: %[[LOWER_1:.*]] = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[LOWER_2:.*]] = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[STEP_1:.*]] = constant 1 : index
|
|
|
|
// CHECK-NEXT: %[[STEP_2:.*]] = constant 1 : index
|
|
|
|
// CHECK-NEXT: scf.parallel (%[[I:.*]], %[[J:.*]]) = (%[[LOWER_1]], %[[LOWER_2]]) to (%[[UPPER]], %[[UPPER]]) step (%[[STEP_1]], %[[STEP_2]]) {
|
|
|
|
// CHECK-NEXT: %[[VAL_1:.*]] = load
|
|
|
|
// CHECK-NEXT: %[[VAL_2:.*]] = load
|
|
|
|
// CHECK-NEXT: %[[PRODUCT:.*]] = mulf
|
|
|
|
// CHECK-NEXT: store
|
|
|
|
// CHECK-NEXT: scf.yield
|
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: return
|
|
|
|
// CHECK-NEXT: }
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
func @affine_parallel_with_reductions(%arg0: memref<3x3xf32>, %arg1: memref<3x3xf32>) -> (f32, f32) {
|
|
|
|
%0:2 = affine.parallel (%kx, %ky) = (0, 0) to (2, 2) reduce ("addf", "mulf") -> (f32, f32) {
|
|
|
|
%1 = affine.load %arg0[%kx, %ky] : memref<3x3xf32>
|
|
|
|
%2 = affine.load %arg1[%kx, %ky] : memref<3x3xf32>
|
|
|
|
%3 = mulf %1, %2 : f32
|
|
|
|
%4 = addf %1, %2 : f32
|
|
|
|
affine.yield %3, %4 : f32, f32
|
|
|
|
}
|
|
|
|
return %0#0, %0#1 : f32, f32
|
|
|
|
}
|
|
|
|
// CHECK-LABEL: func @affine_parallel_with_reductions
|
|
|
|
// CHECK: %[[LOWER_1:.*]] = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[LOWER_2:.*]] = constant 0 : index
|
|
|
|
// CHECK-NEXT: %[[UPPER_1:.*]] = constant 2 : index
|
|
|
|
// CHECK-NEXT: %[[UPPER_2:.*]] = constant 2 : index
|
|
|
|
// CHECK-NEXT: %[[STEP_1:.*]] = constant 1 : index
|
|
|
|
// CHECK-NEXT: %[[STEP_2:.*]] = constant 1 : index
|
|
|
|
// CHECK-NEXT: %[[INIT_1:.*]] = constant 0.000000e+00 : f32
|
|
|
|
// CHECK-NEXT: %[[INIT_2:.*]] = constant 1.000000e+00 : f32
|
|
|
|
// CHECK-NEXT: %[[RES:.*]] = scf.parallel (%[[I:.*]], %[[J:.*]]) = (%[[LOWER_1]], %[[LOWER_2]]) to (%[[UPPER_1]], %[[UPPER_2]]) step (%[[STEP_1]], %[[STEP_2]]) init (%[[INIT_1]], %[[INIT_2]]) -> (f32, f32) {
|
|
|
|
// CHECK-NEXT: %[[VAL_1:.*]] = load
|
|
|
|
// CHECK-NEXT: %[[VAL_2:.*]] = load
|
|
|
|
// CHECK-NEXT: %[[PRODUCT:.*]] = mulf
|
|
|
|
// CHECK-NEXT: %[[SUM:.*]] = addf
|
|
|
|
// CHECK-NEXT: scf.reduce(%[[PRODUCT]]) : f32 {
|
|
|
|
// CHECK-NEXT: ^bb0(%[[LHS:.*]]: f32, %[[RHS:.*]]: f32):
|
|
|
|
// CHECK-NEXT: %[[RES:.*]] = addf
|
|
|
|
// CHECK-NEXT: scf.reduce.return %[[RES]] : f32
|
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: scf.reduce(%[[SUM]]) : f32 {
|
|
|
|
// CHECK-NEXT: ^bb0(%[[LHS:.*]]: f32, %[[RHS:.*]]: f32):
|
|
|
|
// CHECK-NEXT: %[[RES:.*]] = mulf
|
|
|
|
// CHECK-NEXT: scf.reduce.return %[[RES]] : f32
|
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: scf.yield
|
|
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK-NEXT: return
|
|
|
|
// CHECK-NEXT: }
|