1; RUN: opt < %s -loop-unroll -unroll-runtime -unroll-count=2 -verify-scev-maps -S | FileCheck %s
2
3; Check SCEV expansion uses existing value when unrolling an inner loop with runtime trip count in a loop nest.
4; CHECK-LABEL: @foo(
5; CHECK: select
6; CHECK-NOT: select
7; CHECK: ret
8
9define void @foo(i32 %xfL, i32 %scaleL) local_unnamed_addr {
10entry:
11  br label %for.body
12
13for.body:                                         ; preds = %for.body5, %for.body, %entry
14  %xfL.addr.033 = phi i32 [ %xfL, %entry ], [ %add, %for.body5 ]
15  %add = add nsw i32 %xfL.addr.033, %scaleL
16  %shr = ashr i32 %add, 16
17  %cmp.i = icmp slt i32 0, %shr
18  %.sroa.speculated = select i1 %cmp.i, i32 0, i32 %shr
19  %cmp425 = icmp slt i32 0, %.sroa.speculated
20  br i1 %cmp425, label %for.body5.preheader, label %for.end
21
22for.body5.preheader:                              ; preds = %for.body
23  %tmp0 = sext i32 %.sroa.speculated to i64
24  br label %for.body5
25
26for.body5:                                        ; preds = %for.body5, %for.body5.preheader
27  %indvars.iv = phi i64 [ 0, %for.body5.preheader ], [ %indvars.iv.next, %for.body5 ]
28  %indvars.iv.next = add nsw i64 %indvars.iv, 1
29  %cmp4 = icmp slt i64 %indvars.iv.next, %tmp0
30  br i1 %cmp4, label %for.body5, label %for.body
31
32for.end:
33  ret void
34}
35
36