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 %cmp23 = icmp eq i8 %limit, 0
71 br i1 %cmp23, label %for.cond1.preheader, label %for.cond1.preheader.us
73 for.cond1.preheader.us:
74 %storemerge5.us = phi i32 [ 0, %entry ], [ %inc14.us, %for.inc13.us ]
75 br i1 true, label %for.body4.lr.ph.us, label %for.inc13.us
78 %inc14.us = add nsw i32 %storemerge5.us, 1
79 %cmp.us = icmp slt i32 %inc14.us, 4
80 br i1 %cmp.us, label %for.cond1.preheader.us, label %for.end
83 %storemerge14.us = phi i32 [ 0, %for.body4.lr.ph.us ], [ %inc.us, %for.body4.us ]
84 %idxprom.us = sext i32 %storemerge14.us to i64
85 %arrayidx6.us = getelementptr inbounds [8 x i8]* %a, i64 %idxprom5.us, i64 %idxprom.us
86 %0 = load i8* %arrayidx6.us, align 1
87 %idxprom7.us = zext i8 %0 to i64
88 %arrayidx8.us = getelementptr inbounds i8* %b, i64 %idxprom7.us
89 %1 = load i8* %arrayidx8.us, align 1
90 store i8 %1, i8* %arrayidx6.us, align 1
91 %inc.us = add nsw i32 %storemerge14.us, 1
92 %cmp2.us = icmp slt i32 %inc.us, %conv
93 br i1 %cmp2.us, label %for.body4.us, label %for.inc13.us
96 %idxprom5.us = sext i32 %storemerge5.us to i64
97 br label %for.body4.us
100 %storemerge5 = phi i32 [ 0, %entry ], [ %inc14, %for.inc13 ]
101 br i1 false, label %for.inc13, label %for.inc13
104 %inc14 = add nsw i32 %storemerge5, 1
105 %cmp = icmp slt i32 %inc14, 4
106 br i1 %cmp, label %for.cond1.preheader, label %for.end
112 ; CHECK-LABEL: @test3
116 ; CHECK: icmp slt i64
118 define i32 @test3(i32* %a, i32 %b) {
123 %sum.0 = phi i32 [ 0, %entry ], [ %add, %for.body ]
124 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
125 %cmp = icmp slt i32 %i.0, %b
126 br i1 %cmp, label %for.body, label %for.end
129 %idxprom = sext i32 %i.0 to i64
130 %arrayidx = getelementptr inbounds i32* %a, i64 %idxprom
131 %0 = load i32* %arrayidx, align 4
132 %add = add nsw i32 %sum.0, %0
133 %inc = add nsw i32 %i.0, 1
140 ; CHECK-LABEL: @test4
144 ; CHECK: icmp ule i64
146 define i32 @test4(i32* %a, i32 %b) {
151 %sum.0 = phi i32 [ 0, %entry ], [ %add, %for.body ]
152 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
153 %cmp = icmp ule i32 %i.0, %b
154 br i1 %cmp, label %for.body, label %for.end
157 %idxprom = sext i32 %i.0 to i64
158 %arrayidx = getelementptr inbounds i32* %a, i64 %idxprom
159 %0 = load i32* %arrayidx, align 4
160 %add = add nsw i32 %sum.0, %0
161 %inc = add nsw i32 %i.0, 1