1 target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128"
2 ; RUN: opt < %s -alignment-from-assumptions -S | FileCheck %s
3 ; RUN: opt < %s -passes=alignment-from-assumptions -S | FileCheck %s
5 define i32 @foo(i32* nocapture %a) nounwind uwtable readonly {
7 %ptrint = ptrtoint i32* %a to i64
8 %maskedptr = and i64 %ptrint, 31
9 %maskcond = icmp eq i64 %maskedptr, 0
10 tail call void @llvm.assume(i1 %maskcond)
11 %0 = load i32, i32* %a, align 4
15 ; CHECK: load i32, i32* {{[^,]+}}, align 32
19 define i32 @foo2(i32* nocapture %a) nounwind uwtable readonly {
21 %ptrint = ptrtoint i32* %a to i64
22 %offsetptr = add i64 %ptrint, 24
23 %maskedptr = and i64 %offsetptr, 31
24 %maskcond = icmp eq i64 %maskedptr, 0
25 tail call void @llvm.assume(i1 %maskcond)
26 %arrayidx = getelementptr inbounds i32, i32* %a, i64 2
27 %0 = load i32, i32* %arrayidx, align 4
31 ; CHECK: load i32, i32* {{[^,]+}}, align 16
35 define i32 @foo2a(i32* nocapture %a) nounwind uwtable readonly {
37 %ptrint = ptrtoint i32* %a to i64
38 %offsetptr = add i64 %ptrint, 28
39 %maskedptr = and i64 %offsetptr, 31
40 %maskcond = icmp eq i64 %maskedptr, 0
41 tail call void @llvm.assume(i1 %maskcond)
42 %arrayidx = getelementptr inbounds i32, i32* %a, i64 -1
43 %0 = load i32, i32* %arrayidx, align 4
47 ; CHECK: load i32, i32* {{[^,]+}}, align 32
51 define i32 @goo(i32* nocapture %a) nounwind uwtable readonly {
53 %ptrint = ptrtoint i32* %a to i64
54 %maskedptr = and i64 %ptrint, 31
55 %maskcond = icmp eq i64 %maskedptr, 0
56 tail call void @llvm.assume(i1 %maskcond)
57 %0 = load i32, i32* %a, align 4
61 ; CHECK: load i32, i32* {{[^,]+}}, align 32
65 define i32 @hoo(i32* nocapture %a) nounwind uwtable readonly {
67 %ptrint = ptrtoint i32* %a to i64
68 %maskedptr = and i64 %ptrint, 31
69 %maskcond = icmp eq i64 %maskedptr, 0
70 tail call void @llvm.assume(i1 %maskcond)
73 for.body: ; preds = %entry, %for.body
74 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
75 %r.06 = phi i32 [ 0, %entry ], [ %add, %for.body ]
76 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
77 %0 = load i32, i32* %arrayidx, align 4
78 %add = add nsw i32 %0, %r.06
79 %indvars.iv.next = add i64 %indvars.iv, 8
80 %1 = trunc i64 %indvars.iv.next to i32
81 %cmp = icmp slt i32 %1, 2048
82 br i1 %cmp, label %for.body, label %for.end
84 for.end: ; preds = %for.body
85 %add.lcssa = phi i32 [ %add, %for.body ]
89 ; CHECK: load i32, i32* %arrayidx, align 32
90 ; CHECK: ret i32 %add.lcssa
94 ; def hoo2(a, id, num):
95 ; for i0 in range(id*64, 4096, num*64):
96 ; for i1 in range(0, 4096, 32):
97 ; for i2 in range(0, 4096, 32):
98 ; load(a, i0+i1+i2+32)
99 define void @hoo2(i32* nocapture %a, i64 %id, i64 %num) nounwind uwtable readonly {
101 %ptrint = ptrtoint i32* %a to i64
102 %maskedptr = and i64 %ptrint, 31
103 %maskcond = icmp eq i64 %maskedptr, 0
104 tail call void @llvm.assume(i1 %maskcond)
105 %id.mul = shl nsw i64 %id, 6
106 %num.mul = shl nsw i64 %num, 6
110 %i0 = phi i64 [ %id.mul, %entry ], [ %i0.next, %for0.end ]
114 %i1 = phi i64 [ 0, %for0.body ], [ %i1.next, %for1.end ]
118 %i2 = phi i64 [ 0, %for1.body ], [ %i2.next, %for2.body ]
120 %t1 = add nuw nsw i64 %i0, %i1
121 %t2 = add nuw nsw i64 %t1, %i2
122 %t3 = add nuw nsw i64 %t2, 32
123 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %t3
124 %x = load i32, i32* %arrayidx, align 4
126 %i2.next = add nuw nsw i64 %i2, 32
127 %cmp2 = icmp ult i64 %i2.next, 4096
128 br i1 %cmp2, label %for2.body, label %for1.end
131 %i1.next = add nuw nsw i64 %i1, 32
132 %cmp1 = icmp ult i64 %i1.next, 4096
133 br i1 %cmp1, label %for1.body, label %for0.end
136 %i0.next = add nuw nsw i64 %i0, %num.mul
137 %cmp0 = icmp ult i64 %i0.next, 4096
138 br i1 %cmp0, label %for0.body, label %return
144 ; CHECK: load i32, i32* %arrayidx, align 32
148 define i32 @joo(i32* nocapture %a) nounwind uwtable readonly {
150 %ptrint = ptrtoint i32* %a to i64
151 %maskedptr = and i64 %ptrint, 31
152 %maskcond = icmp eq i64 %maskedptr, 0
153 tail call void @llvm.assume(i1 %maskcond)
156 for.body: ; preds = %entry, %for.body
157 %indvars.iv = phi i64 [ 4, %entry ], [ %indvars.iv.next, %for.body ]
158 %r.06 = phi i32 [ 0, %entry ], [ %add, %for.body ]
159 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
160 %0 = load i32, i32* %arrayidx, align 4
161 %add = add nsw i32 %0, %r.06
162 %indvars.iv.next = add i64 %indvars.iv, 8
163 %1 = trunc i64 %indvars.iv.next to i32
164 %cmp = icmp slt i32 %1, 2048
165 br i1 %cmp, label %for.body, label %for.end
167 for.end: ; preds = %for.body
168 %add.lcssa = phi i32 [ %add, %for.body ]
172 ; CHECK: load i32, i32* %arrayidx, align 16
173 ; CHECK: ret i32 %add.lcssa
176 define i32 @koo(i32* nocapture %a) nounwind uwtable readonly {
178 %ptrint = ptrtoint i32* %a to i64
179 %maskedptr = and i64 %ptrint, 31
180 %maskcond = icmp eq i64 %maskedptr, 0
181 tail call void @llvm.assume(i1 %maskcond)
184 for.body: ; preds = %entry, %for.body
185 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
186 %r.06 = phi i32 [ 0, %entry ], [ %add, %for.body ]
187 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
188 %0 = load i32, i32* %arrayidx, align 4
189 %add = add nsw i32 %0, %r.06
190 %indvars.iv.next = add i64 %indvars.iv, 4
191 %1 = trunc i64 %indvars.iv.next to i32
192 %cmp = icmp slt i32 %1, 2048
193 br i1 %cmp, label %for.body, label %for.end
195 for.end: ; preds = %for.body
196 %add.lcssa = phi i32 [ %add, %for.body ]
200 ; CHECK: load i32, i32* %arrayidx, align 16
201 ; CHECK: ret i32 %add.lcssa
204 define i32 @koo2(i32* nocapture %a) nounwind uwtable readonly {
206 %ptrint = ptrtoint i32* %a to i64
207 %maskedptr = and i64 %ptrint, 31
208 %maskcond = icmp eq i64 %maskedptr, 0
209 tail call void @llvm.assume(i1 %maskcond)
212 for.body: ; preds = %entry, %for.body
213 %indvars.iv = phi i64 [ -4, %entry ], [ %indvars.iv.next, %for.body ]
214 %r.06 = phi i32 [ 0, %entry ], [ %add, %for.body ]
215 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
216 %0 = load i32, i32* %arrayidx, align 4
217 %add = add nsw i32 %0, %r.06
218 %indvars.iv.next = add i64 %indvars.iv, 4
219 %1 = trunc i64 %indvars.iv.next to i32
220 %cmp = icmp slt i32 %1, 2048
221 br i1 %cmp, label %for.body, label %for.end
223 for.end: ; preds = %for.body
224 %add.lcssa = phi i32 [ %add, %for.body ]
228 ; CHECK: load i32, i32* %arrayidx, align 16
229 ; CHECK: ret i32 %add.lcssa
232 define i32 @moo(i32* nocapture %a) nounwind uwtable {
234 %ptrint = ptrtoint i32* %a to i64
235 %maskedptr = and i64 %ptrint, 31
236 %maskcond = icmp eq i64 %maskedptr, 0
237 tail call void @llvm.assume(i1 %maskcond)
238 %0 = bitcast i32* %a to i8*
239 tail call void @llvm.memset.p0i8.i64(i8* align 4 %0, i8 0, i64 64, i1 false)
243 ; CHECK: @llvm.memset.p0i8.i64(i8* align 32 %0, i8 0, i64 64, i1 false)
244 ; CHECK: ret i32 undef
247 define i32 @moo2(i32* nocapture %a, i32* nocapture %b) nounwind uwtable {
249 %ptrint = ptrtoint i32* %a to i64
250 %maskedptr = and i64 %ptrint, 31
251 %maskcond = icmp eq i64 %maskedptr, 0
252 tail call void @llvm.assume(i1 %maskcond)
253 %ptrint1 = ptrtoint i32* %b to i64
254 %maskedptr3 = and i64 %ptrint1, 127
255 %maskcond4 = icmp eq i64 %maskedptr3, 0
256 tail call void @llvm.assume(i1 %maskcond4)
257 %0 = bitcast i32* %a to i8*
258 %1 = bitcast i32* %b to i8*
259 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %0, i8* align 4 %1, i64 64, i1 false)
263 ; CHECK: @llvm.memcpy.p0i8.p0i8.i64(i8* align 32 %0, i8* align 128 %1, i64 64, i1 false)
264 ; CHECK: ret i32 undef
267 declare void @llvm.assume(i1) nounwind
269 declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind
270 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) nounwind