• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-n32-S64"
2; RUN: opt < %s -alignment-from-assumptions -S | FileCheck %s
3; RUN: opt < %s -passes=alignment-from-assumptions -S | FileCheck %s
4
5define i32 @foo(i32* nocapture %a) nounwind uwtable readonly {
6entry:
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
12  ret i32 %0
13
14; CHECK-LABEL: @foo
15; CHECK: load i32, i32* {{[^,]+}}, align 32
16; CHECK: ret i32
17}
18
19define i32 @foo2(i32* nocapture %a) nounwind uwtable readonly {
20entry:
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
28  ret i32 %0
29
30; CHECK-LABEL: @foo2
31; CHECK: load i32, i32* {{[^,]+}}, align 16
32; CHECK: ret i32
33}
34
35define i32 @foo2a(i32* nocapture %a) nounwind uwtable readonly {
36entry:
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
44  ret i32 %0
45
46; CHECK-LABEL: @foo2a
47; CHECK: load i32, i32* {{[^,]+}}, align 32
48; CHECK: ret i32
49}
50
51define i32 @goo(i32* nocapture %a) nounwind uwtable readonly {
52entry:
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
58  ret i32 %0
59
60; CHECK-LABEL: @goo
61; CHECK: load i32, i32* {{[^,]+}}, align 32
62; CHECK: ret i32
63}
64
65define i32 @hoo(i32* nocapture %a) nounwind uwtable readonly {
66entry:
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)
71  br label %for.body
72
73for.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
83
84for.end:                                          ; preds = %for.body
85  %add.lcssa = phi i32 [ %add, %for.body ]
86  ret i32 %add.lcssa
87
88; CHECK-LABEL: @hoo
89; CHECK: load i32, i32* %arrayidx, align 32
90; CHECK: ret i32 %add.lcssa
91}
92
93define i32 @joo(i32* nocapture %a) nounwind uwtable readonly {
94entry:
95  %ptrint = ptrtoint i32* %a to i64
96  %maskedptr = and i64 %ptrint, 31
97  %maskcond = icmp eq i64 %maskedptr, 0
98  tail call void @llvm.assume(i1 %maskcond)
99  br label %for.body
100
101for.body:                                         ; preds = %entry, %for.body
102  %indvars.iv = phi i64 [ 4, %entry ], [ %indvars.iv.next, %for.body ]
103  %r.06 = phi i32 [ 0, %entry ], [ %add, %for.body ]
104  %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
105  %0 = load i32, i32* %arrayidx, align 4
106  %add = add nsw i32 %0, %r.06
107  %indvars.iv.next = add i64 %indvars.iv, 8
108  %1 = trunc i64 %indvars.iv.next to i32
109  %cmp = icmp slt i32 %1, 2048
110  br i1 %cmp, label %for.body, label %for.end
111
112for.end:                                          ; preds = %for.body
113  %add.lcssa = phi i32 [ %add, %for.body ]
114  ret i32 %add.lcssa
115
116; CHECK-LABEL: @joo
117; CHECK: load i32, i32* %arrayidx, align 16
118; CHECK: ret i32 %add.lcssa
119}
120
121define i32 @koo(i32* nocapture %a) nounwind uwtable readonly {
122entry:
123  %ptrint = ptrtoint i32* %a to i64
124  %maskedptr = and i64 %ptrint, 31
125  %maskcond = icmp eq i64 %maskedptr, 0
126  tail call void @llvm.assume(i1 %maskcond)
127  br label %for.body
128
129for.body:                                         ; preds = %entry, %for.body
130  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
131  %r.06 = phi i32 [ 0, %entry ], [ %add, %for.body ]
132  %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
133  %0 = load i32, i32* %arrayidx, align 4
134  %add = add nsw i32 %0, %r.06
135  %indvars.iv.next = add i64 %indvars.iv, 4
136  %1 = trunc i64 %indvars.iv.next to i32
137  %cmp = icmp slt i32 %1, 2048
138  br i1 %cmp, label %for.body, label %for.end
139
140for.end:                                          ; preds = %for.body
141  %add.lcssa = phi i32 [ %add, %for.body ]
142  ret i32 %add.lcssa
143
144; CHECK-LABEL: @koo
145; CHECK: load i32, i32* %arrayidx, align 16
146; CHECK: ret i32 %add.lcssa
147}
148
149define i32 @koo2(i32* nocapture %a) nounwind uwtable readonly {
150entry:
151  %ptrint = ptrtoint i32* %a to i64
152  %maskedptr = and i64 %ptrint, 31
153  %maskcond = icmp eq i64 %maskedptr, 0
154  tail call void @llvm.assume(i1 %maskcond)
155  br label %for.body
156
157for.body:                                         ; preds = %entry, %for.body
158  %indvars.iv = phi i64 [ -4, %entry ], [ %indvars.iv.next, %for.body ]
159  %r.06 = phi i32 [ 0, %entry ], [ %add, %for.body ]
160  %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
161  %0 = load i32, i32* %arrayidx, align 4
162  %add = add nsw i32 %0, %r.06
163  %indvars.iv.next = add i64 %indvars.iv, 4
164  %1 = trunc i64 %indvars.iv.next to i32
165  %cmp = icmp slt i32 %1, 2048
166  br i1 %cmp, label %for.body, label %for.end
167
168for.end:                                          ; preds = %for.body
169  %add.lcssa = phi i32 [ %add, %for.body ]
170  ret i32 %add.lcssa
171
172; CHECK-LABEL: @koo2
173; CHECK: load i32, i32* %arrayidx, align 16
174; CHECK: ret i32 %add.lcssa
175}
176
177define i32 @moo(i32* nocapture %a) nounwind uwtable {
178entry:
179  %ptrint = ptrtoint i32* %a to i64
180  %maskedptr = and i64 %ptrint, 31
181  %maskcond = icmp eq i64 %maskedptr, 0
182  tail call void @llvm.assume(i1 %maskcond)
183  %0 = bitcast i32* %a to i8*
184  tail call void @llvm.memset.p0i8.i64(i8* %0, i8 0, i64 64, i32 4, i1 false)
185  ret i32 undef
186
187; CHECK-LABEL: @moo
188; CHECK: @llvm.memset.p0i8.i64(i8* %0, i8 0, i64 64, i32 32, i1 false)
189; CHECK: ret i32 undef
190}
191
192define i32 @moo2(i32* nocapture %a, i32* nocapture %b) nounwind uwtable {
193entry:
194  %ptrint = ptrtoint i32* %a to i64
195  %maskedptr = and i64 %ptrint, 31
196  %maskcond = icmp eq i64 %maskedptr, 0
197  tail call void @llvm.assume(i1 %maskcond)
198  %ptrint1 = ptrtoint i32* %b to i64
199  %maskedptr3 = and i64 %ptrint1, 127
200  %maskcond4 = icmp eq i64 %maskedptr3, 0
201  tail call void @llvm.assume(i1 %maskcond4)
202  %0 = bitcast i32* %a to i8*
203  %1 = bitcast i32* %b to i8*
204  tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %0, i8* %1, i64 64, i32 4, i1 false)
205  ret i32 undef
206
207; CHECK-LABEL: @moo2
208; CHECK: @llvm.memcpy.p0i8.p0i8.i64(i8* %0, i8* %1, i64 64, i32 32, i1 false)
209; CHECK: ret i32 undef
210}
211
212declare void @llvm.assume(i1) nounwind
213
214declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
215declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
216
217