1 ; RUN: opt -S -basicaa -licm < %s | FileCheck %s
2 ; RUN: opt -aa-pipeline=basic-aa -passes='require<opt-remark-emit>,loop(simplify-cfg,licm)' -S < %s | FileCheck %s
3 ; RUN: opt -S -basicaa -licm -enable-mssa-loop-dependency=true -verify-memoryssa < %s | FileCheck %s
5 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
6 target triple = "x86_64-unknown-linux-gnu"
8 ; Make sure the basic alloca pointer hoisting works:
10 ; CHECK: load i32, i32* %c, align 4
13 ; Function Attrs: nounwind uwtable
14 define void @test1(i32* nocapture %a, i32* nocapture readonly %b, i32 %n) #0 {
16 %cmp6 = icmp sgt i32 %n, 0
18 br i1 %cmp6, label %for.body, label %for.end
20 for.body: ; preds = %entry, %for.inc
21 %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
22 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
23 %0 = load i32, i32* %arrayidx, align 4
24 %cmp1 = icmp sgt i32 %0, 0
25 br i1 %cmp1, label %if.then, label %for.inc
27 if.then: ; preds = %for.body
28 %1 = load i32, i32* %c, align 4
29 %arrayidx3 = getelementptr inbounds i32, i32* %b, i64 %indvars.iv
30 %2 = load i32, i32* %arrayidx3, align 4
31 %mul = mul nsw i32 %2, %1
32 store i32 %mul, i32* %arrayidx, align 4
35 for.inc: ; preds = %for.body, %if.then
36 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
37 %lftr.wideiv = trunc i64 %indvars.iv.next to i32
38 %exitcond = icmp eq i32 %lftr.wideiv, %n
39 br i1 %exitcond, label %for.end, label %for.body
41 for.end: ; preds = %for.inc, %entry
45 ; Make sure the basic alloca pointer hoisting works through a bitcast to a
46 ; pointer to a smaller type:
48 ; CHECK: load i32, i32* %c, align 4
51 ; Function Attrs: nounwind uwtable
52 define void @test2(i32* nocapture %a, i32* nocapture readonly %b, i32 %n) #0 {
54 %cmp6 = icmp sgt i32 %n, 0
56 %c = bitcast i64* %ca to i32*
57 br i1 %cmp6, label %for.body, label %for.end
59 for.body: ; preds = %entry, %for.inc
60 %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
61 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
62 %0 = load i32, i32* %arrayidx, align 4
63 %cmp1 = icmp sgt i32 %0, 0
64 br i1 %cmp1, label %if.then, label %for.inc
66 if.then: ; preds = %for.body
67 %1 = load i32, i32* %c, align 4
68 %arrayidx3 = getelementptr inbounds i32, i32* %b, i64 %indvars.iv
69 %2 = load i32, i32* %arrayidx3, align 4
70 %mul = mul nsw i32 %2, %1
71 store i32 %mul, i32* %arrayidx, align 4
74 for.inc: ; preds = %for.body, %if.then
75 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
76 %lftr.wideiv = trunc i64 %indvars.iv.next to i32
77 %exitcond = icmp eq i32 %lftr.wideiv, %n
78 br i1 %exitcond, label %for.end, label %for.body
80 for.end: ; preds = %for.inc, %entry
84 ; Make sure the basic alloca pointer hoisting works through an addrspacecast
85 ; CHECK-LABEL: @test2_addrspacecast
86 ; CHECK: load i32, i32 addrspace(1)* %c, align 4
89 ; Function Attrs: nounwind uwtable
90 define void @test2_addrspacecast(i32 addrspace(1)* nocapture %a, i32 addrspace(1)* nocapture readonly %b, i32 %n) #0 {
92 %cmp6 = icmp sgt i32 %n, 0
94 %c = addrspacecast i64* %ca to i32 addrspace(1)*
95 br i1 %cmp6, label %for.body, label %for.end
97 for.body: ; preds = %entry, %for.inc
98 %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
99 %arrayidx = getelementptr inbounds i32, i32 addrspace(1)* %a, i64 %indvars.iv
100 %0 = load i32, i32 addrspace(1)* %arrayidx, align 4
101 %cmp1 = icmp sgt i32 %0, 0
102 br i1 %cmp1, label %if.then, label %for.inc
104 if.then: ; preds = %for.body
105 %1 = load i32, i32 addrspace(1)* %c, align 4
106 %arrayidx3 = getelementptr inbounds i32, i32 addrspace(1)* %b, i64 %indvars.iv
107 %2 = load i32, i32 addrspace(1)* %arrayidx3, align 4
108 %mul = mul nsw i32 %2, %1
109 store i32 %mul, i32 addrspace(1)* %arrayidx, align 4
112 for.inc: ; preds = %for.body, %if.then
113 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
114 %lftr.wideiv = trunc i64 %indvars.iv.next to i32
115 %exitcond = icmp eq i32 %lftr.wideiv, %n
116 br i1 %exitcond, label %for.end, label %for.body
118 for.end: ; preds = %for.inc, %entry
122 ; Make sure the basic alloca pointer hoisting works through a bitcast to a
123 ; pointer to a smaller type (where the bitcast also needs to be hoisted):
124 ; CHECK-LABEL: @test3
125 ; CHECK: load i32, i32* %c, align 4
128 ; Function Attrs: nounwind uwtable
129 define void @test3(i32* nocapture %a, i32* nocapture readonly %b, i32 %n) #0 {
131 %cmp6 = icmp sgt i32 %n, 0
133 br i1 %cmp6, label %for.body, label %for.end
135 for.body: ; preds = %entry, %for.inc
136 %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
137 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
138 %0 = load i32, i32* %arrayidx, align 4
139 %cmp1 = icmp sgt i32 %0, 0
140 br i1 %cmp1, label %if.then, label %for.inc
142 if.then: ; preds = %for.body
143 %c = bitcast i64* %ca to i32*
144 %1 = load i32, i32* %c, align 4
145 %arrayidx3 = getelementptr inbounds i32, i32* %b, i64 %indvars.iv
146 %2 = load i32, i32* %arrayidx3, align 4
147 %mul = mul nsw i32 %2, %1
148 store i32 %mul, i32* %arrayidx, align 4
151 for.inc: ; preds = %for.body, %if.then
152 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
153 %lftr.wideiv = trunc i64 %indvars.iv.next to i32
154 %exitcond = icmp eq i32 %lftr.wideiv, %n
155 br i1 %exitcond, label %for.end, label %for.body
157 for.end: ; preds = %for.inc, %entry
161 ; Make sure the basic alloca pointer hoisting does not happen through a bitcast
162 ; to a pointer to a larger type:
163 ; CHECK-LABEL: @test4
165 ; CHECK: load i32, i32* %c, align 4
167 ; Function Attrs: nounwind uwtable
168 define void @test4(i32* nocapture %a, i32* nocapture readonly %b, i32 %n) #0 {
170 %cmp6 = icmp sgt i32 %n, 0
172 %c = bitcast i16* %ca to i32*
173 br i1 %cmp6, label %for.body, label %for.end
175 for.body: ; preds = %entry, %for.inc
176 %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
177 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
178 %0 = load i32, i32* %arrayidx, align 4
179 %cmp1 = icmp sgt i32 %0, 0
180 br i1 %cmp1, label %if.then, label %for.inc
182 if.then: ; preds = %for.body
183 %1 = load i32, i32* %c, align 4
184 %arrayidx3 = getelementptr inbounds i32, i32* %b, i64 %indvars.iv
185 %2 = load i32, i32* %arrayidx3, align 4
186 %mul = mul nsw i32 %2, %1
187 store i32 %mul, i32* %arrayidx, align 4
190 for.inc: ; preds = %for.body, %if.then
191 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
192 %lftr.wideiv = trunc i64 %indvars.iv.next to i32
193 %exitcond = icmp eq i32 %lftr.wideiv, %n
194 br i1 %exitcond, label %for.end, label %for.body
196 for.end: ; preds = %for.inc, %entry
200 ; Don't crash on bitcasts to unsized types.
201 ; CHECK-LABEL: @test5
203 ; CHECK: load i32, i32* %c, align 4
207 ; Function Attrs: nounwind uwtable
208 define void @test5(i32* nocapture %a, i32* nocapture readonly %b, i32 %n) #0 {
210 %cmp6 = icmp sgt i32 %n, 0
212 %cab = bitcast i16* %ca to %atype*
213 %c = bitcast %atype* %cab to i32*
214 br i1 %cmp6, label %for.body, label %for.end
216 for.body: ; preds = %entry, %for.inc
217 %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
218 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
219 %0 = load i32, i32* %arrayidx, align 4
220 %cmp1 = icmp sgt i32 %0, 0
221 br i1 %cmp1, label %if.then, label %for.inc
223 if.then: ; preds = %for.body
224 %1 = load i32, i32* %c, align 4
225 %arrayidx3 = getelementptr inbounds i32, i32* %b, i64 %indvars.iv
226 %2 = load i32, i32* %arrayidx3, align 4
227 %mul = mul nsw i32 %2, %1
228 store i32 %mul, i32* %arrayidx, align 4
231 for.inc: ; preds = %for.body, %if.then
232 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
233 %lftr.wideiv = trunc i64 %indvars.iv.next to i32
234 %exitcond = icmp eq i32 %lftr.wideiv, %n
235 br i1 %exitcond, label %for.end, label %for.body
237 for.end: ; preds = %for.inc, %entry
241 attributes #0 = { nounwind uwtable }