1 ; RUN: opt < %s -passes=loop-unroll -unroll-runtime -unroll-count=2 -S | FileCheck %s
3 ; Check SCEV expansion uses existing value when unrolling an inner loop with runtime trip count in a loop nest.
4 ; The outer loop gets unrolled twice, so we see 2 selects in the outer loop blocks.
6 ; CHECK-LABEL: for.body.loopexit:
8 ; CHECK-LABEL: for.body:
13 define void @foo(i32 %xfL, i32 %scaleL) local_unnamed_addr {
17 for.body: ; preds = %for.body5, %for.body, %entry
18 %xfL.addr.033 = phi i32 [ %xfL, %entry ], [ %add, %for.body5 ]
19 %add = add nsw i32 %xfL.addr.033, %scaleL
20 %shr = ashr i32 %add, 16
21 %cmp.i = icmp slt i32 10, %shr
22 %.sroa.speculated = select i1 %cmp.i, i32 0, i32 %shr
23 %cmp425 = icmp slt i32 0, %.sroa.speculated
24 br i1 %cmp425, label %for.body5.preheader, label %for.end
26 for.body5.preheader: ; preds = %for.body
27 %tmp0 = sext i32 %.sroa.speculated to i64
30 for.body5: ; preds = %for.body5, %for.body5.preheader
31 %indvars.iv = phi i64 [ 0, %for.body5.preheader ], [ %indvars.iv.next, %for.body5 ]
32 %indvars.iv.next = add nsw i64 %indvars.iv, 1
33 %cmp4 = icmp slt i64 %indvars.iv.next, %tmp0
34 br i1 %cmp4, label %for.body5, label %for.body