1 ; RUN: opt -S -codegenprepare < %s | FileCheck %s
4 "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
5 target triple = "x86_64-unknown-linux-gnu"
7 @x = external global [1 x [2 x <4 x float>]]
9 ; Can we sink single addressing mode computation to use?
10 define void @test1(i1 %cond, i64* %base) {
12 ; CHECK: getelementptr inbounds i8, {{.+}} 40
14 %addr = getelementptr inbounds i64, i64* %base, i64 5
15 %casted = bitcast i64* %addr to i32*
16 br i1 %cond, label %if.then, label %fallthrough
19 %v = load i32, i32* %casted, align 4
26 declare void @foo(i32)
28 ; Make sure sinking two copies of addressing mode into different blocks works
29 define void @test2(i1 %cond, i64* %base) {
32 %addr = getelementptr inbounds i64, i64* %base, i64 5
33 %casted = bitcast i64* %addr to i32*
34 br i1 %cond, label %if.then, label %fallthrough
37 ; CHECK-LABEL: if.then:
38 ; CHECK: getelementptr inbounds i8, {{.+}} 40
39 %v1 = load i32, i32* %casted, align 4
40 call void @foo(i32 %v1)
41 %cmp = icmp eq i32 %v1, 0
42 br i1 %cmp, label %next, label %fallthrough
46 ; CHECK: getelementptr inbounds i8, {{.+}} 40
47 %v2 = load i32, i32* %casted, align 4
48 call void @foo(i32 %v2)
55 ; If we have two loads in the same block, only need one copy of addressing mode
56 ; - instruction selection will duplicate if needed
57 define void @test3(i1 %cond, i64* %base) {
60 %addr = getelementptr inbounds i64, i64* %base, i64 5
61 %casted = bitcast i64* %addr to i32*
62 br i1 %cond, label %if.then, label %fallthrough
65 ; CHECK-LABEL: if.then:
66 ; CHECK: getelementptr inbounds i8, {{.+}} 40
67 %v1 = load i32, i32* %casted, align 4
68 call void @foo(i32 %v1)
69 ; CHECK-NOT: getelementptr inbounds i8, {{.+}} 40
70 %v2 = load i32, i32* %casted, align 4
71 call void @foo(i32 %v2)
78 ; Can we still sink addressing mode if there's a cold use of the
80 define void @test4(i1 %cond, i64* %base) {
83 %addr = getelementptr inbounds i64, i64* %base, i64 5
84 %casted = bitcast i64* %addr to i32*
85 br i1 %cond, label %if.then, label %fallthrough
88 ; CHECK-LABEL: if.then:
89 ; CHECK: getelementptr inbounds i8, {{.+}} 40
90 %v1 = load i32, i32* %casted, align 4
91 call void @foo(i32 %v1)
92 %cmp = icmp eq i32 %v1, 0
93 br i1 %cmp, label %rare.1, label %fallthrough
99 ; CHECK-LABEL: rare.1:
100 ; CHECK: getelementptr inbounds i8, {{.+}} 40
101 call void @slowpath(i32 %v1, i32* %casted) cold
102 br label %fallthrough
105 ; Negative test - don't want to duplicate addressing into hot path
106 define void @test5(i1 %cond, i64* %base) {
107 ; CHECK-LABEL: @test5
109 ; CHECK: %addr = getelementptr inbounds
110 %addr = getelementptr inbounds i64, i64* %base, i64 5
111 %casted = bitcast i64* %addr to i32*
112 br i1 %cond, label %if.then, label %fallthrough
115 ; CHECK-LABEL: if.then:
116 ; CHECK-NOT: getelementptr inbounds i8, {{.+}} 40
117 %v1 = load i32, i32* %casted, align 4
118 call void @foo(i32 %v1)
119 %cmp = icmp eq i32 %v1, 0
120 br i1 %cmp, label %rare.1, label %fallthrough
126 call void @slowpath(i32 %v1, i32* %casted) ;; NOT COLD
127 br label %fallthrough
130 ; Negative test - opt for size
131 define void @test6(i1 %cond, i64* %base) minsize {
132 ; CHECK-LABEL: @test6
134 ; CHECK: %addr = getelementptr
135 %addr = getelementptr inbounds i64, i64* %base, i64 5
136 %casted = bitcast i64* %addr to i32*
137 br i1 %cond, label %if.then, label %fallthrough
140 ; CHECK-LABEL: if.then:
141 ; CHECK-NOT: getelementptr inbounds i8, {{.+}} 40
142 %v1 = load i32, i32* %casted, align 4
143 call void @foo(i32 %v1)
144 %cmp = icmp eq i32 %v1, 0
145 br i1 %cmp, label %rare.1, label %fallthrough
151 call void @slowpath(i32 %v1, i32* %casted) cold
152 br label %fallthrough
156 ; Make sure sinking two copies of addressing mode into different blocks works
157 ; when there are cold paths for each.
158 define void @test7(i1 %cond, i64* %base) {
159 ; CHECK-LABEL: @test7
161 %addr = getelementptr inbounds i64, i64* %base, i64 5
162 %casted = bitcast i64* %addr to i32*
163 br i1 %cond, label %if.then, label %fallthrough
166 ; CHECK-LABEL: if.then:
167 ; CHECK: getelementptr inbounds i8, {{.+}} 40
168 %v1 = load i32, i32* %casted, align 4
169 call void @foo(i32 %v1)
170 %cmp = icmp eq i32 %v1, 0
171 br i1 %cmp, label %rare.1, label %next
175 ; CHECK: getelementptr inbounds i8, {{.+}} 40
176 %v2 = load i32, i32* %casted, align 4
177 call void @foo(i32 %v2)
178 %cmp2 = icmp eq i32 %v2, 0
179 br i1 %cmp2, label %rare.1, label %fallthrough
185 ; CHECK-LABEL: rare.1:
186 ; CHECK: getelementptr inbounds i8, {{.+}} 40
187 call void @slowpath(i32 %v1, i32* %casted) cold
191 ; CHECK-LABEL: rare.2:
192 ; CHECK: getelementptr inbounds i8, {{.+}} 40
193 call void @slowpath(i32 %v2, i32* %casted) cold
194 br label %fallthrough
197 declare void @slowpath(i32, i32*)
199 ; Make sure we don't end up in an infinite loop after we fail to sink.
200 ; CHECK-LABEL: define void @test8
201 ; CHECK: %ptr = getelementptr i8, i8* %aFOO_load_ptr2int_2void, i32 undef
202 define void @test8() {
204 %aFOO_load = load float*, float** undef
205 %aFOO_load_ptr2int = ptrtoint float* %aFOO_load to i64
206 %aFOO_load_ptr2int_broadcast_init = insertelement <4 x i64> undef, i64 %aFOO_load_ptr2int, i32 0
207 %aFOO_load_ptr2int_2void = inttoptr i64 %aFOO_load_ptr2int to i8*
208 %ptr = getelementptr i8, i8* %aFOO_load_ptr2int_2void, i32 undef
212 %ptr.i143 = bitcast i8* %ptr to <4 x float>*
213 %valall.i144 = load <4 x float>, <4 x float>* %ptr.i143, align 4
214 %x_offset = getelementptr [1 x [2 x <4 x float>]], [1 x [2 x <4 x float>]]* @x, i32 0, i64 0
215 br label %pl_loop.i.i122
218 br label %pl_loop.i.i122
221 ; Make sure we can sink address computation even
222 ; if there is a cycle in phi nodes.
223 define void @test9(i1 %cond, i64* %base) {
224 ; CHECK-LABEL: @test9
226 %addr = getelementptr inbounds i64, i64* %base, i64 5
227 %casted = bitcast i64* %addr to i32*
231 %iv = phi i32 [0, %entry], [%iv.inc, %backedge]
232 %casted.loop = phi i32* [%casted, %entry], [%casted.merged, %backedge]
233 br i1 %cond, label %if.then, label %backedge
236 call void @foo(i32 %iv)
237 %addr.1 = getelementptr inbounds i64, i64* %base, i64 5
238 %casted.1 = bitcast i64* %addr.1 to i32*
242 ; CHECK-LABEL: backedge:
243 ; CHECK: getelementptr inbounds i8, {{.+}} 40
244 %casted.merged = phi i32* [%casted.loop, %header], [%casted.1, %if.then]
245 %v = load i32, i32* %casted.merged, align 4
246 call void @foo(i32 %v)
247 %iv.inc = add i32 %iv, 1
248 %cmp = icmp slt i32 %iv.inc, 1000
249 br i1 %cmp, label %header, label %exit
255 ; Make sure we can eliminate a select when both arguments perform equivalent
256 ; address computation.
257 define void @test10(i1 %cond, i64* %base) {
258 ; CHECK-LABEL: @test10
259 ; CHECK: getelementptr inbounds i8, {{.+}} 40
262 %gep1 = getelementptr inbounds i64, i64* %base, i64 5
263 %gep1.casted = bitcast i64* %gep1 to i32*
264 %base.casted = bitcast i64* %base to i32*
265 %gep2 = getelementptr inbounds i32, i32* %base.casted, i64 10
266 %casted.merged = select i1 %cond, i32* %gep1.casted, i32* %gep2
267 %v = load i32, i32* %casted.merged, align 4
268 call void @foo(i32 %v)
272 ; Found by fuzzer, getSExtValue of > 64 bit constant
273 define void @i96_mul(i1* %base, i96 %offset) {
275 ;; RHS = 0x7FFFFFFFFFFFFFFFFFFFFFFF
276 %B84 = mul i96 %offset, 39614081257132168796771975167
277 %G23 = getelementptr i1, i1* %base, i96 %B84
278 store i1 false, i1* %G23