1// RUN: mlir-opt %s --test-loop-unrolling="unroll-factor=3" -split-input-file -canonicalize | FileCheck %s 2 3// CHECK-LABEL: scf_loop_unroll_single 4func @scf_loop_unroll_single(%arg0 : f32, %arg1 : f32) -> f32 { 5 %from = constant 0 : index 6 %to = constant 10 : index 7 %step = constant 1 : index 8 %sum = scf.for %iv = %from to %to step %step iter_args(%sum_iter = %arg0) -> (f32) { 9 %next = addf %sum_iter, %arg1 : f32 10 scf.yield %next : f32 11 } 12 // CHECK: %[[SUM:.*]] = scf.for %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%[[V0:.*]] = 13 // CHECK-NEXT: %[[V1:.*]] = addf %[[V0]] 14 // CHECK-NEXT: %[[V2:.*]] = addf %[[V1]] 15 // CHECK-NEXT: %[[V3:.*]] = addf %[[V2]] 16 // CHECK-NEXT: scf.yield %[[V3]] 17 // CHECK-NEXT: } 18 // CHECK-NEXT: %[[RES:.*]] = addf %[[SUM]], 19 // CHECK-NEXT: return %[[RES]] 20 return %sum : f32 21} 22 23// CHECK-LABEL: scf_loop_unroll_double_symbolic_ub 24// CHECK-SAME: (%{{.*}}: f32, %{{.*}}: f32, %[[N:.*]]: index) 25func @scf_loop_unroll_double_symbolic_ub(%arg0 : f32, %arg1 : f32, %n : index) -> (f32,f32) { 26 %from = constant 0 : index 27 %step = constant 1 : index 28 %sum:2 = scf.for %iv = %from to %n step %step iter_args(%i0 = %arg0, %i1 = %arg1) -> (f32, f32) { 29 %sum0 = addf %i0, %arg0 : f32 30 %sum1 = addf %i1, %arg1 : f32 31 scf.yield %sum0, %sum1 : f32, f32 32 } 33 return %sum#0, %sum#1 : f32, f32 34 // CHECK: %[[C0:.*]] = constant 0 : index 35 // CHECK-NEXT: %[[C1:.*]] = constant 1 : index 36 // CHECK-NEXT: %[[C3:.*]] = constant 3 : index 37 // CHECK-NEXT: %[[REM:.*]] = remi_signed %[[N]], %[[C3]] 38 // CHECK-NEXT: %[[UB:.*]] = subi %[[N]], %[[REM]] 39 // CHECK-NEXT: %[[SUM:.*]]:2 = scf.for {{.*}} = %[[C0]] to %[[UB]] step %[[C3]] iter_args 40 // CHECK: } 41 // CHECK-NEXT: %[[SUM1:.*]]:2 = scf.for {{.*}} = %[[UB]] to %[[N]] step %[[C1]] iter_args(%[[V1:.*]] = %[[SUM]]#0, %[[V2:.*]] = %[[SUM]]#1) 42 // CHECK: } 43 // CHECK-NEXT: return %[[SUM1]]#0, %[[SUM1]]#1 44} 45