1 ; RUN: opt < %s -indvars -S | FileCheck %s
2 target triple = "aarch64--linux-gnu"
4 ; Check the loop exit i32 compare instruction and operand are widened to i64
5 ; instead of truncating IV before its use in the i32 compare instruction.
7 @idx = common global i32 0, align 4
8 @e = common global i32 0, align 4
9 @ptr = common global i32* null, align 8
12 ; CHECK: for.body.lr.ph:
21 store i32 -1, i32* @idx, align 4
22 %0 = load i32* @e, align 4
23 %cmp4 = icmp slt i32 %0, 0
24 br i1 %cmp4, label %for.end.loopexit, label %for.body.lr.ph
27 %1 = load i32** @ptr, align 8
28 %2 = load i32* @e, align 4
32 %inc = add nsw i32 %i.05, 1
33 %cmp = icmp slt i32 %i.05, %2
34 br i1 %cmp, label %for.body, label %for.cond.for.end.loopexit_crit_edge
37 %i.05 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.cond ]
38 %idxprom = sext i32 %i.05 to i64
39 %arrayidx = getelementptr inbounds i32* %1, i64 %idxprom
40 %3 = load i32* %arrayidx, align 4
41 %tobool = icmp eq i32 %3, 0
42 br i1 %tobool, label %if.then, label %for.cond
45 %i.05.lcssa = phi i32 [ %i.05, %for.body ]
46 store i32 %i.05.lcssa, i32* @idx, align 4
49 for.cond.for.end.loopexit_crit_edge:
50 br label %for.end.loopexit
56 %4 = load i32* @idx, align 4
62 ; CHECK: %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
63 ; CHECK: %cmp2.us = icmp slt i64
64 ; CHECK-NOT: %2 = trunc i64 %indvars.iv.next to i32
65 ; CHECK-NOT: %cmp2.us = icmp slt i32
67 define void @test2([8 x i8]* %a, i8* %b, i8 %limit) {
69 %conv = zext i8 %limit to i32
70 br i1 undef, label %for.cond1.preheader, label %for.cond1.preheader.us
72 for.cond1.preheader.us:
73 %storemerge5.us = phi i32 [ 0, %entry ], [ %inc14.us, %for.inc13.us ]
74 br i1 true, label %for.body4.lr.ph.us, label %for.inc13.us
77 %inc14.us = add nsw i32 %storemerge5.us, 1
78 %cmp.us = icmp slt i32 %inc14.us, 4
79 br i1 %cmp.us, label %for.cond1.preheader.us, label %for.end
82 %storemerge14.us = phi i32 [ 0, %for.body4.lr.ph.us ], [ %inc.us, %for.body4.us ]
83 %idxprom.us = sext i32 %storemerge14.us to i64
84 %arrayidx6.us = getelementptr inbounds [8 x i8]* %a, i64 %idxprom5.us, i64 %idxprom.us
85 %0 = load i8* %arrayidx6.us, align 1
86 %idxprom7.us = zext i8 %0 to i64
87 %arrayidx8.us = getelementptr inbounds i8* %b, i64 %idxprom7.us
88 %1 = load i8* %arrayidx8.us, align 1
89 store i8 %1, i8* %arrayidx6.us, align 1
90 %inc.us = add nsw i32 %storemerge14.us, 1
91 %cmp2.us = icmp slt i32 %inc.us, %conv
92 br i1 %cmp2.us, label %for.body4.us, label %for.inc13.us
95 %idxprom5.us = sext i32 %storemerge5.us to i64
96 br label %for.body4.us
99 %storemerge5 = phi i32 [ 0, %entry ], [ %inc14, %for.inc13 ]
100 br i1 false, label %for.inc13, label %for.inc13
103 %inc14 = add nsw i32 %storemerge5, 1
104 %cmp = icmp slt i32 %inc14, 4
105 br i1 %cmp, label %for.cond1.preheader, label %for.end
111 ; CHECK-LABEL: @test3
115 ; CHECK: icmp slt i64
117 define i32 @test3(i32* %a, i32 %b) {
122 %sum.0 = phi i32 [ 0, %entry ], [ %add, %for.body ]
123 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
124 %cmp = icmp slt i32 %i.0, %b
125 br i1 %cmp, label %for.body, label %for.end
128 %idxprom = sext i32 %i.0 to i64
129 %arrayidx = getelementptr inbounds i32* %a, i64 %idxprom
130 %0 = load i32* %arrayidx, align 4
131 %add = add nsw i32 %sum.0, %0
132 %inc = add nsw i32 %i.0, 1
139 declare i32 @fn1(i8 signext)
142 ; CHECK-LABEL: @test4
147 define i32 @test4(i32 %a) {
152 %c.07 = phi i8 [ -3, %entry ], [ %dec, %for.body ]
153 %conv6 = zext i8 %c.07 to i32
154 %or = or i32 %a, %conv6
155 %conv3 = trunc i32 %or to i8
156 %call = call i32 @fn1(i8 signext %conv3)
157 %dec = add i8 %c.07, -1
158 %cmp = icmp sgt i8 %dec, -14
159 br i1 %cmp, label %for.body, label %for.end
165 ; CHECK-LABEL: @test5
169 ; CHECK: icmp ule i64
171 define i32 @test5(i32* %a, i32 %b) {
176 %sum.0 = phi i32 [ 0, %entry ], [ %add, %for.body ]
177 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
178 %cmp = icmp ule i32 %i.0, %b
179 br i1 %cmp, label %for.body, label %for.end
182 %idxprom = zext i32 %i.0 to i64
183 %arrayidx = getelementptr inbounds i32* %a, i64 %idxprom
184 %0 = load i32* %arrayidx, align 4
185 %add = add nsw i32 %sum.0, %0
186 %inc = add nsw i32 %i.0, 1