@@ -489,3 +489,32 @@ func.func @static_loop_unroll_with_integer_iv() -> (f32, f32) {
489489// UNROLL-BY-3-NEXT: scf.yield %[[EADD]], %[[EMUL]] : f32, f32
490490// UNROLL-BY-3-NEXT: }
491491// UNROLL-BY-3-NEXT: return %[[EFOR]]#0, %[[EFOR]]#1 : f32, f32
492+
493+ // -----
494+
495+ // Test loop unrolling when the yielded value is defined above the loop.
496+ func.func @loop_unroll_static_yield_value_defined_above (%init: i32 ) {
497+ %c42 = arith.constant 42 : i32
498+ %c0 = arith.constant 0 : index
499+ %c1 = arith.constant 1 : index
500+ %c4 = arith.constant 4 : index
501+ %103:2 = scf.for %i = %c0 to %c4 step %c1
502+ iter_args (%iter1 = %c42 , %iter2 = %init ) -> (i32 , i32 ) {
503+ %0 = arith.andi %iter2 , %iter1 : i32
504+ scf.yield %0 , %init : i32 , i32
505+ }
506+ return
507+ }
508+ // UNROLL-OUTER-BY-2-LABEL: @loop_unroll_static_yield_value_defined_above(
509+ // UNROLL-OUTER-BY-2-SAME: %[[INIT:.*]]: i32) {
510+ // UNROLL-OUTER-BY-2-DAG: %[[C42:.*]] = arith.constant 42 : i32
511+ // UNROLL-OUTER-BY-2-DAG: %[[C0:.*]] = arith.constant 0 : index
512+ // UNROLL-OUTER-BY-2-DAG: %[[C4:.*]] = arith.constant 4 : index
513+ // UNROLL-OUTER-BY-2-DAG: %[[C2:.*]] = arith.constant 2 : index
514+ // UNROLL-OUTER-BY-2: scf.for %{{.*}} = %[[C0]] to %[[C4]] step %[[C2]]
515+ // UNROLL-OUTER-BY-2-SAME: iter_args(%[[ITER1:.*]] = %[[C42]],
516+ // UNROLL-OUTER-BY-2-SAME: %[[ITER2:.*]] = %[[INIT]])
517+ // UNROLL-OUTER-BY-2: %[[SUM:.*]] = arith.andi %[[ITER2]], %[[ITER1]]
518+ // UNROLL-OUTER-BY-2: %[[SUM1:.*]] = arith.andi %[[INIT]], %[[SUM]]
519+ // UNROLL-OUTER-BY-2: scf.yield %[[SUM1]], %[[INIT]] : i32, i32
520+
0 commit comments