1 ; RUN: opt < %s -indvars -S | FileCheck %s
2 target triple = "aarch64--linux-gnu"
4 ; Provide legal integer types.
5 target datalayout = "n8:16:32:64"
8 ; Check the loop exit i32 compare instruction and operand are widened to i64
9 ; instead of truncating IV before its use in the i32 compare instruction.
11 @idx = common global i32 0, align 4
12 @e = common global i32 0, align 4
13 @ptr = common global i32* null, align 8
16 ; CHECK: for.body.lr.ph:
25 store i32 -1, i32* @idx, align 4
26 %0 = load i32, i32* @e, align 4
27 %cmp4 = icmp slt i32 %0, 0
28 br i1 %cmp4, label %for.end.loopexit, label %for.body.lr.ph
31 %1 = load i32*, i32** @ptr, align 8
32 %2 = load i32, i32* @e, align 4
36 %inc = add nsw i32 %i.05, 1
37 %cmp = icmp slt i32 %i.05, %2
38 br i1 %cmp, label %for.body, label %for.cond.for.end.loopexit_crit_edge
41 %i.05 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.cond ]
42 %idxprom = sext i32 %i.05 to i64
43 %arrayidx = getelementptr inbounds i32, i32* %1, i64 %idxprom
44 %3 = load i32, i32* %arrayidx, align 4
45 %tobool = icmp eq i32 %3, 0
46 br i1 %tobool, label %if.then, label %for.cond
49 %i.05.lcssa = phi i32 [ %i.05, %for.body ]
50 store i32 %i.05.lcssa, i32* @idx, align 4
53 for.cond.for.end.loopexit_crit_edge:
54 br label %for.end.loopexit
60 %4 = load i32, i32* @idx, align 4
66 ; CHECK: %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
67 ; CHECK: %cmp2.us = icmp slt i64
68 ; CHECK-NOT: %2 = trunc i64 %indvars.iv.next to i32
69 ; CHECK-NOT: %cmp2.us = icmp slt i32
71 define void @test2([8 x i8]* %a, i8* %b, i8 %limit) {
73 %conv = zext i8 %limit to i32
74 br i1 undef, label %for.cond1.preheader, label %for.cond1.preheader.us
76 for.cond1.preheader.us:
77 %storemerge5.us = phi i32 [ 0, %entry ], [ %inc14.us, %for.inc13.us ]
78 br i1 true, label %for.body4.lr.ph.us, label %for.inc13.us
81 %inc14.us = add nsw i32 %storemerge5.us, 1
82 %cmp.us = icmp slt i32 %inc14.us, 4
83 br i1 %cmp.us, label %for.cond1.preheader.us, label %for.end
86 %storemerge14.us = phi i32 [ 0, %for.body4.lr.ph.us ], [ %inc.us, %for.body4.us ]
87 %idxprom.us = sext i32 %storemerge14.us to i64
88 %arrayidx6.us = getelementptr inbounds [8 x i8], [8 x i8]* %a, i64 %idxprom5.us, i64 %idxprom.us
89 %0 = load i8, i8* %arrayidx6.us, align 1
90 %idxprom7.us = zext i8 %0 to i64
91 %arrayidx8.us = getelementptr inbounds i8, i8* %b, i64 %idxprom7.us
92 %1 = load i8, i8* %arrayidx8.us, align 1
93 store i8 %1, i8* %arrayidx6.us, align 1
94 %inc.us = add nsw i32 %storemerge14.us, 1
95 %cmp2.us = icmp slt i32 %inc.us, %conv
96 br i1 %cmp2.us, label %for.body4.us, label %for.inc13.us
99 %idxprom5.us = sext i32 %storemerge5.us to i64
100 br label %for.body4.us
103 %storemerge5 = phi i32 [ 0, %entry ], [ %inc14, %for.inc13 ]
104 br i1 false, label %for.inc13, label %for.inc13
107 %inc14 = add nsw i32 %storemerge5, 1
108 %cmp = icmp slt i32 %inc14, 4
109 br i1 %cmp, label %for.cond1.preheader, label %for.end
115 ; CHECK-LABEL: @test3
119 ; CHECK: icmp slt i64
121 define i32 @test3(i32* %a, i32 %b) {
126 %sum.0 = phi i32 [ 0, %entry ], [ %add, %for.body ]
127 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
128 %cmp = icmp slt i32 %i.0, %b
129 br i1 %cmp, label %for.body, label %for.end
132 %idxprom = sext i32 %i.0 to i64
133 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom
134 %0 = load i32, i32* %arrayidx, align 4
135 %add = add nsw i32 %sum.0, %0
136 %inc = add nsw i32 %i.0, 1
143 declare i32 @fn1(i8 signext)
146 ; CHECK-LABEL: @test4
151 define i32 @test4(i32 %a) {
156 %c.07 = phi i8 [ -3, %entry ], [ %dec, %for.body ]
157 %conv6 = zext i8 %c.07 to i32
158 %or = or i32 %a, %conv6
159 %conv3 = trunc i32 %or to i8
160 %call = call i32 @fn1(i8 signext %conv3)
161 %dec = add i8 %c.07, -1
162 %cmp = icmp sgt i8 %dec, -14
163 br i1 %cmp, label %for.body, label %for.end
169 ; CHECK-LABEL: @test5
173 ; CHECK: icmp ule i64
175 define i32 @test5(i32* %a, i32 %b) {
180 %sum.0 = phi i32 [ 0, %entry ], [ %add, %for.body ]
181 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
182 %cmp = icmp ule i32 %i.0, %b
183 br i1 %cmp, label %for.body, label %for.end
186 %idxprom = zext i32 %i.0 to i64
187 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom
188 %0 = load i32, i32* %arrayidx, align 4
189 %add = add nsw i32 %sum.0, %0
190 %inc = add nsw i32 %i.0, 1