1 // RUN: mlir-opt %s --test-loop-unrolling="unroll-factor=3" -split-input-file -canonicalize | FileCheck %s
2 // RUN: mlir-opt %s --test-loop-unrolling="unroll-factor=1" -split-input-file -canonicalize | FileCheck %s --check-prefix UNROLL-BY-1
4 // CHECK-LABEL: scf_loop_unroll_single
5 func.func @scf_loop_unroll_single(%arg0 : f32, %arg1 : f32) -> f32 {
6 %from = arith.constant 0 : index
7 %to = arith.constant 10 : index
8 %step = arith.constant 1 : index
9 %sum = scf.for %iv = %from to %to step %step iter_args(%sum_iter = %arg0) -> (f32) {
10 %next = arith.addf %sum_iter, %arg1 : f32
13 // CHECK: %[[SUM:.*]] = scf.for %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%[[V0:.*]] =
14 // CHECK-NEXT: %[[V1:.*]] = arith.addf %[[V0]]
15 // CHECK-NEXT: %[[V2:.*]] = arith.addf %[[V1]]
16 // CHECK-NEXT: %[[V3:.*]] = arith.addf %[[V2]]
17 // CHECK-NEXT: scf.yield %[[V3]]
19 // CHECK-NEXT: %[[RES:.*]] = arith.addf %[[SUM]],
20 // CHECK-NEXT: return %[[RES]]
24 // CHECK-LABEL: scf_loop_unroll_double_symbolic_ub
25 // CHECK-SAME: (%{{.*}}: f32, %{{.*}}: f32, %[[N:.*]]: index)
26 func.func @scf_loop_unroll_double_symbolic_ub(%arg0 : f32, %arg1 : f32, %n : index) -> (f32,f32) {
27 %from = arith.constant 0 : index
28 %step = arith.constant 1 : index
29 %sum:2 = scf.for %iv = %from to %n step %step iter_args(%i0 = %arg0, %i1 = %arg1) -> (f32, f32) {
30 %sum0 = arith.addf %i0, %arg0 : f32
31 %sum1 = arith.addf %i1, %arg1 : f32
32 scf.yield %sum0, %sum1 : f32, f32
34 return %sum#0, %sum#1 : f32, f32
35 // CHECK-DAG: %[[C0:.*]] = arith.constant 0 : index
36 // CHECK-DAG: %[[C1:.*]] = arith.constant 1 : index
37 // CHECK-DAG: %[[C3:.*]] = arith.constant 3 : index
38 // CHECK-NEXT: %[[REM:.*]] = arith.remsi %[[N]], %[[C3]]
39 // CHECK-NEXT: %[[UB:.*]] = arith.subi %[[N]], %[[REM]]
40 // CHECK-NEXT: %[[SUM:.*]]:2 = scf.for {{.*}} = %[[C0]] to %[[UB]] step %[[C3]] iter_args
42 // CHECK-NEXT: %[[SUM1:.*]]:2 = scf.for {{.*}} = %[[UB]] to %[[N]] step %[[C1]] iter_args(%[[V1:.*]] = %[[SUM]]#0, %[[V2:.*]] = %[[SUM]]#1)
44 // CHECK-NEXT: return %[[SUM1]]#0, %[[SUM1]]#1
47 // UNROLL-BY-1-LABEL: scf_loop_unroll_factor_1_promote
48 func.func @scf_loop_unroll_factor_1_promote() -> () {
49 %step = arith.constant 1 : index
50 %lo = arith.constant 0 : index
51 %hi = arith.constant 1 : index
52 scf.for %i = %lo to %hi step %step {
53 %x = "test.foo"(%i) : (index) -> i32
56 // UNROLL-BY-1-NEXT: %[[C0:.*]] = arith.constant 0 : index
57 // UNROLL-BY-1-NEXT: %{{.*}} = "test.foo"(%[[C0]]) : (index) -> i32