comparison llvm/test/Transforms/CodeGenPrepare/X86/sink-addrmode-base.ll @ 252:1f2b6ac9f198 llvm-original

LLVM16-1
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 18 Aug 2023 09:04:13 +0900
parents 1d019706d866
children
comparison
equal deleted inserted replaced
237:c80f45b162ad 252:1f2b6ac9f198
3 target datalayout = 3 target datalayout =
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" 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" 5 target triple = "x86_64-unknown-linux-gnu"
6 6
7 ; Can we sink for different base if there is no phi for base? 7 ; Can we sink for different base if there is no phi for base?
8 define i32 @test1(i1 %cond, i64* %b1, i64* %b2) { 8 define i32 @test1(i1 %cond, ptr %b1, ptr %b2) {
9 ; CHECK-LABEL: @test1 9 ; CHECK-LABEL: @test1
10 entry: 10 entry:
11 %a1 = getelementptr inbounds i64, i64* %b1, i64 5 11 %a1 = getelementptr inbounds i64, ptr %b1, i64 5
12 %c1 = bitcast i64* %a1 to i32* 12 br i1 %cond, label %if.then, label %fallthrough
13 br i1 %cond, label %if.then, label %fallthrough 13
14 14 if.then:
15 if.then: 15 %a2 = getelementptr inbounds i64, ptr %b2, i64 5
16 %a2 = getelementptr inbounds i64, i64* %b2, i64 5 16 br label %fallthrough
17 %c2 = bitcast i64* %a2 to i32* 17
18 br label %fallthrough 18 fallthrough:
19 19 ; CHECK-YES: sunk_phi
20 fallthrough: 20 ; CHECK-NO-LABEL: fallthrough:
21 ; CHECK-YES: sunk_phi 21 ; CHECK-NO: phi
22 ; CHECK-NO-LABEL: fallthrough: 22 ; CHECK-NO-NEXT: load
23 ; CHECK-NO: phi 23 %c = phi ptr [%a1, %entry], [%a2, %if.then]
24 ; CHECK-NO-NEXT: load 24 %v = load i32, ptr %c, align 4
25 %c = phi i32* [%c1, %entry], [%c2, %if.then]
26 %v = load i32, i32* %c, align 4
27 ret i32 %v 25 ret i32 %v
28 } 26 }
29 27
30 ; Can we sink for different base if there is phi for base? 28 ; Can we sink for different base if there is phi for base?
31 define i32 @test2(i1 %cond, i64* %b1, i64* %b2) { 29 define i32 @test2(i1 %cond, ptr %b1, ptr %b2) {
32 ; CHECK-LABEL: @test2 30 ; CHECK-LABEL: @test2
33 entry: 31 entry:
34 %a1 = getelementptr inbounds i64, i64* %b1, i64 5 32 %a1 = getelementptr inbounds i64, ptr %b1, i64 5
35 %c1 = bitcast i64* %a1 to i32* 33 br i1 %cond, label %if.then, label %fallthrough
36 br i1 %cond, label %if.then, label %fallthrough 34
37 35 if.then:
38 if.then: 36 %a2 = getelementptr inbounds i64, ptr %b2, i64 5
39 %a2 = getelementptr inbounds i64, i64* %b2, i64 5
40 %c2 = bitcast i64* %a2 to i32*
41 br label %fallthrough 37 br label %fallthrough
42 38
43 fallthrough: 39 fallthrough:
44 ; CHECK: getelementptr inbounds i8, {{.+}} 40 40 ; CHECK: getelementptr inbounds i8, {{.+}} 40
45 %b = phi i64* [%b1, %entry], [%b2, %if.then] 41 %b = phi ptr [%b1, %entry], [%b2, %if.then]
46 %c = phi i32* [%c1, %entry], [%c2, %if.then] 42 %c = phi ptr [%a1, %entry], [%a2, %if.then]
47 %v = load i32, i32* %c, align 4 43 %v = load i32, ptr %c, align 4
48 ret i32 %v 44 ret i32 %v
49 } 45 }
50 46
51 ; Can we sink for different base if there is phi for base but not valid one? 47 ; Can we sink for different base if there is phi for base but not valid one?
52 define i32 @test3(i1 %cond, i64* %b1, i64* %b2) { 48 define i32 @test3(i1 %cond, ptr %b1, ptr %b2) {
53 ; CHECK-LABEL: @test3 49 ; CHECK-LABEL: @test3
54 entry: 50 entry:
55 %a1 = getelementptr inbounds i64, i64* %b1, i64 5 51 %a1 = getelementptr inbounds i64, ptr %b1, i64 5
56 %c1 = bitcast i64* %a1 to i32* 52 br i1 %cond, label %if.then, label %fallthrough
57 br i1 %cond, label %if.then, label %fallthrough 53
58 54 if.then:
59 if.then: 55 %a2 = getelementptr inbounds i64, ptr %b2, i64 5
60 %a2 = getelementptr inbounds i64, i64* %b2, i64 5 56 br label %fallthrough
61 %c2 = bitcast i64* %a2 to i32* 57
62 br label %fallthrough 58 fallthrough:
63 59 ; CHECK-YES: sunk_phi
64 fallthrough: 60 ; CHECK-NO-LABEL: fallthrough:
65 ; CHECK-YES: sunk_phi 61 ; CHECK-NO: phi
66 ; CHECK-NO-LABEL: fallthrough: 62 ; CHECK-NO: phi
67 ; CHECK-NO: phi 63 ; CHECK-NO-NEXT: load
68 ; CHECK-NO: phi 64 %b = phi ptr [%b2, %entry], [%b1, %if.then]
69 ; CHECK-NO-NEXT: load 65 %c = phi ptr [%a1, %entry], [%a2, %if.then]
70 %b = phi i64* [%b2, %entry], [%b1, %if.then] 66 %v = load i32, ptr %c, align 4
71 %c = phi i32* [%c1, %entry], [%c2, %if.then]
72 %v = load i32, i32* %c, align 4
73 ret i32 %v 67 ret i32 %v
74 } 68 }
75 69
76 ; Can we sink for different base if both addresses are in the same block? 70 ; Can we sink for different base if both addresses are in the same block?
77 define i32 @test4(i1 %cond, i64* %b1, i64* %b2) { 71 define i32 @test4(i1 %cond, ptr %b1, ptr %b2) {
78 ; CHECK-LABEL: @test4 72 ; CHECK-LABEL: @test4
79 entry: 73 entry:
80 %a1 = getelementptr inbounds i64, i64* %b1, i64 5 74 %a1 = getelementptr inbounds i64, ptr %b1, i64 5
81 %c1 = bitcast i64* %a1 to i32* 75 %a2 = getelementptr inbounds i64, ptr %b2, i64 5
82 %a2 = getelementptr inbounds i64, i64* %b2, i64 5 76 br i1 %cond, label %if.then, label %fallthrough
83 %c2 = bitcast i64* %a2 to i32* 77
84 br i1 %cond, label %if.then, label %fallthrough 78 if.then:
85 79 br label %fallthrough
86 if.then: 80
87 br label %fallthrough 81 fallthrough:
88 82 ; CHECK-YES: sunk_phi
89 fallthrough: 83 ; CHECK-NO-LABEL: fallthrough:
90 ; CHECK-YES: sunk_phi 84 ; CHECK-NO: phi
91 ; CHECK-NO-LABEL: fallthrough: 85 ; CHECK-NO-NEXT: load
92 ; CHECK-NO: phi 86 %c = phi ptr [%a1, %entry], [%a2, %if.then]
93 ; CHECK-NO-NEXT: load 87 %v = load i32, ptr %c, align 4
94 %c = phi i32* [%c1, %entry], [%c2, %if.then]
95 %v = load i32, i32* %c, align 4
96 ret i32 %v 88 ret i32 %v
97 } 89 }
98 90
99 ; Can we sink for different base if there is phi for base? 91 ; Can we sink for different base if there is phi for base?
100 ; Both addresses are in the same block. 92 ; Both addresses are in the same block.
101 define i32 @test5(i1 %cond, i64* %b1, i64* %b2) { 93 define i32 @test5(i1 %cond, ptr %b1, ptr %b2) {
102 ; CHECK-LABEL: @test5 94 ; CHECK-LABEL: @test5
103 entry: 95 entry:
104 %a1 = getelementptr inbounds i64, i64* %b1, i64 5 96 %a1 = getelementptr inbounds i64, ptr %b1, i64 5
105 %c1 = bitcast i64* %a1 to i32* 97 %a2 = getelementptr inbounds i64, ptr %b2, i64 5
106 %a2 = getelementptr inbounds i64, i64* %b2, i64 5
107 %c2 = bitcast i64* %a2 to i32*
108 br i1 %cond, label %if.then, label %fallthrough 98 br i1 %cond, label %if.then, label %fallthrough
109 99
110 if.then: 100 if.then:
111 br label %fallthrough 101 br label %fallthrough
112 102
113 fallthrough: 103 fallthrough:
114 ; CHECK: getelementptr inbounds i8, {{.+}} 40 104 ; CHECK: getelementptr inbounds i8, {{.+}} 40
115 %b = phi i64* [%b1, %entry], [%b2, %if.then] 105 %b = phi ptr [%b1, %entry], [%b2, %if.then]
116 %c = phi i32* [%c1, %entry], [%c2, %if.then] 106 %c = phi ptr [%a1, %entry], [%a2, %if.then]
117 %v = load i32, i32* %c, align 4 107 %v = load i32, ptr %c, align 4
118 ret i32 %v 108 ret i32 %v
119 } 109 }
120 110
121 ; Can we sink for different base if there is phi for base but not valid one? 111 ; Can we sink for different base if there is phi for base but not valid one?
122 ; Both addresses are in the same block. 112 ; Both addresses are in the same block.
123 define i32 @test6(i1 %cond, i64* %b1, i64* %b2) { 113 define i32 @test6(i1 %cond, ptr %b1, ptr %b2) {
124 ; CHECK-LABEL: @test6 114 ; CHECK-LABEL: @test6
125 entry: 115 entry:
126 %a1 = getelementptr inbounds i64, i64* %b1, i64 5 116 %a1 = getelementptr inbounds i64, ptr %b1, i64 5
127 %c1 = bitcast i64* %a1 to i32* 117 %a2 = getelementptr inbounds i64, ptr %b2, i64 5
128 %a2 = getelementptr inbounds i64, i64* %b2, i64 5 118 br i1 %cond, label %if.then, label %fallthrough
129 %c2 = bitcast i64* %a2 to i32* 119
130 br i1 %cond, label %if.then, label %fallthrough 120 if.then:
131 121 br label %fallthrough
132 if.then: 122
133 br label %fallthrough 123 fallthrough:
134 124 ; CHECK-YES: sunk_phi
135 fallthrough: 125 ; CHECK-NO-LABEL: fallthrough:
136 ; CHECK-YES: sunk_phi 126 ; CHECK-NO: phi
137 ; CHECK-NO-LABEL: fallthrough: 127 ; CHECK-NO-NEXT: phi
138 ; CHECK-NO: phi 128 ; CHECK-NO-NEXT: load
139 ; CHECK-NO-NEXT: phi 129 %b = phi ptr [%b2, %entry], [%b1, %if.then]
140 ; CHECK-NO-NEXT: load 130 %c = phi ptr [%a1, %entry], [%a2, %if.then]
141 %b = phi i64* [%b2, %entry], [%b1, %if.then] 131 %v = load i32, ptr %c, align 4
142 %c = phi i32* [%c1, %entry], [%c2, %if.then]
143 %v = load i32, i32* %c, align 4
144 ret i32 %v 132 ret i32 %v
145 } 133 }
146 134
147 ; case with a loop. No phi node. 135 ; case with a loop. No phi node.
148 define i32 @test7(i32 %N, i1 %cond, i64* %b1, i64* %b2) { 136 define i32 @test7(i32 %N, i1 %cond, ptr %b1, ptr %b2) {
149 ; CHECK-LABEL: @test7 137 ; CHECK-LABEL: @test7
150 entry: 138 entry:
151 %a1 = getelementptr inbounds i64, i64* %b1, i64 5 139 %a1 = getelementptr inbounds i64, ptr %b1, i64 5
152 %c1 = bitcast i64* %a1 to i32*
153 br label %loop 140 br label %loop
154 141
155 loop: 142 loop:
156 ; CHECK-LABEL: loop: 143 ; CHECK-LABEL: loop:
157 ; CHECK-YES: sunk_phi 144 ; CHECK-YES: sunk_phi
158 %iv = phi i32 [0, %entry], [%iv.inc, %fallthrough] 145 %iv = phi i32 [0, %entry], [%iv.inc, %fallthrough]
159 %c3 = phi i32* [%c1, %entry], [%c, %fallthrough] 146 %c3 = phi ptr [%a1, %entry], [%c, %fallthrough]
160 br i1 %cond, label %if.then, label %fallthrough 147 br i1 %cond, label %if.then, label %fallthrough
161 148
162 if.then: 149 if.then:
163 %a2 = getelementptr inbounds i64, i64* %b2, i64 5 150 %a2 = getelementptr inbounds i64, ptr %b2, i64 5
164 %c2 = bitcast i64* %a2 to i32* 151 br label %fallthrough
165 br label %fallthrough 152
166 153 fallthrough:
167 fallthrough: 154 ; CHECK-YES: sunk_phi
168 ; CHECK-YES: sunk_phi 155 ; CHECK-NO-LABEL: fallthrough:
169 ; CHECK-NO-LABEL: fallthrough: 156 ; CHECK-NO: phi
170 ; CHECK-NO: phi 157 ; CHECK-NO-NEXT: load
171 ; CHECK-NO-NEXT: load 158 %c = phi ptr [%c3, %loop], [%a2, %if.then]
172 %c = phi i32* [%c3, %loop], [%c2, %if.then] 159 %v = load volatile i32, ptr %c, align 4
173 %v = load volatile i32, i32* %c, align 4
174 %iv.inc = add i32 %iv, 1 160 %iv.inc = add i32 %iv, 1
175 %cmp = icmp slt i32 %iv.inc, %N 161 %cmp = icmp slt i32 %iv.inc, %N
176 br i1 %cmp, label %loop, label %exit 162 br i1 %cmp, label %loop, label %exit
177 163
178 exit: 164 exit:
179 ret i32 %v 165 ret i32 %v
180 } 166 }
181 167
182 ; case with a loop. There is phi node. 168 ; case with a loop. There is phi node.
183 define i32 @test8(i32 %N, i1 %cond, i64* %b1, i64* %b2) { 169 define i32 @test8(i32 %N, i1 %cond, ptr %b1, ptr %b2) {
184 ; CHECK-LABEL: @test8 170 ; CHECK-LABEL: @test8
185 entry: 171 entry:
186 %a1 = getelementptr inbounds i64, i64* %b1, i64 5 172 %a1 = getelementptr inbounds i64, ptr %b1, i64 5
187 %c1 = bitcast i64* %a1 to i32*
188 br label %loop 173 br label %loop
189 174
190 loop: 175 loop:
191 %iv = phi i32 [0, %entry], [%iv.inc, %fallthrough] 176 %iv = phi i32 [0, %entry], [%iv.inc, %fallthrough]
192 %c3 = phi i32* [%c1, %entry], [%c, %fallthrough] 177 %c3 = phi ptr [%a1, %entry], [%c, %fallthrough]
193 %b3 = phi i64* [%b1, %entry], [%b, %fallthrough] 178 %b3 = phi ptr [%b1, %entry], [%b, %fallthrough]
194 br i1 %cond, label %if.then, label %fallthrough 179 br i1 %cond, label %if.then, label %fallthrough
195 180
196 if.then: 181 if.then:
197 %a2 = getelementptr inbounds i64, i64* %b2, i64 5 182 %a2 = getelementptr inbounds i64, ptr %b2, i64 5
198 %c2 = bitcast i64* %a2 to i32*
199 br label %fallthrough 183 br label %fallthrough
200 184
201 fallthrough: 185 fallthrough:
202 ; CHECK: getelementptr inbounds i8, {{.+}} 40 186 ; CHECK: getelementptr inbounds i8, {{.+}} 40
203 %c = phi i32* [%c3, %loop], [%c2, %if.then] 187 %c = phi ptr [%c3, %loop], [%a2, %if.then]
204 %b = phi i64* [%b3, %loop], [%b2, %if.then] 188 %b = phi ptr [%b3, %loop], [%b2, %if.then]
205 %v = load volatile i32, i32* %c, align 4 189 %v = load volatile i32, ptr %c, align 4
206 %iv.inc = add i32 %iv, 1 190 %iv.inc = add i32 %iv, 1
207 %cmp = icmp slt i32 %iv.inc, %N 191 %cmp = icmp slt i32 %iv.inc, %N
208 br i1 %cmp, label %loop, label %exit 192 br i1 %cmp, label %loop, label %exit
209 193
210 exit: 194 exit:
211 ret i32 %v 195 ret i32 %v
212 } 196 }
213 197
214 ; case with a loop. There is phi node but it does not fit. 198 ; case with a loop. There is phi node but it does not fit.
215 define i32 @test9(i32 %N, i1 %cond, i64* %b1, i64* %b2) { 199 define i32 @test9(i32 %N, i1 %cond, ptr %b1, ptr %b2) {
216 ; CHECK-LABEL: @test9 200 ; CHECK-LABEL: @test9
217 entry: 201 entry:
218 %a1 = getelementptr inbounds i64, i64* %b1, i64 5 202 %a1 = getelementptr inbounds i64, ptr %b1, i64 5
219 %c1 = bitcast i64* %a1 to i32*
220 br label %loop 203 br label %loop
221 204
222 loop: 205 loop:
223 ; CHECK-LABEL: loop: 206 ; CHECK-LABEL: loop:
224 ; CHECK-YES: sunk_phi 207 ; CHECK-YES: sunk_phi
225 %iv = phi i32 [0, %entry], [%iv.inc, %fallthrough] 208 %iv = phi i32 [0, %entry], [%iv.inc, %fallthrough]
226 %c3 = phi i32* [%c1, %entry], [%c, %fallthrough] 209 %c3 = phi ptr [%a1, %entry], [%c, %fallthrough]
227 %b3 = phi i64* [%b1, %entry], [%b2, %fallthrough] 210 %b3 = phi ptr [%b1, %entry], [%b2, %fallthrough]
228 br i1 %cond, label %if.then, label %fallthrough 211 br i1 %cond, label %if.then, label %fallthrough
229 212
230 if.then: 213 if.then:
231 %a2 = getelementptr inbounds i64, i64* %b2, i64 5 214 %a2 = getelementptr inbounds i64, ptr %b2, i64 5
232 %c2 = bitcast i64* %a2 to i32* 215 br label %fallthrough
233 br label %fallthrough 216
234 217 fallthrough:
235 fallthrough: 218 ; CHECK-YES: sunk_phi
236 ; CHECK-YES: sunk_phi 219 ; CHECK-NO-LABEL: fallthrough:
237 ; CHECK-NO-LABEL: fallthrough: 220 ; CHECK-NO: phi
238 ; CHECK-NO: phi 221 ; CHECK-NO-NEXT: phi
239 ; CHECK-NO-NEXT: phi 222 ; CHECK-NO-NEXT: load
240 ; CHECK-NO-NEXT: load 223 %c = phi ptr [%c3, %loop], [%a2, %if.then]
241 %c = phi i32* [%c3, %loop], [%c2, %if.then] 224 %b = phi ptr [%b3, %loop], [%b2, %if.then]
242 %b = phi i64* [%b3, %loop], [%b2, %if.then] 225 %v = load volatile i32, ptr %c, align 4
243 %v = load volatile i32, i32* %c, align 4
244 %iv.inc = add i32 %iv, 1 226 %iv.inc = add i32 %iv, 1
245 %cmp = icmp slt i32 %iv.inc, %N 227 %cmp = icmp slt i32 %iv.inc, %N
246 br i1 %cmp, label %loop, label %exit 228 br i1 %cmp, label %loop, label %exit
247 229
248 exit: 230 exit:
249 ret i32 %v 231 ret i32 %v
250 } 232 }
251 233
252 ; Case through a loop. No phi node. 234 ; Case through a loop. No phi node.
253 define i32 @test10(i32 %N, i1 %cond, i64* %b1, i64* %b2) { 235 define i32 @test10(i32 %N, i1 %cond, ptr %b1, ptr %b2) {
254 ; CHECK-LABEL: @test10 236 ; CHECK-LABEL: @test10
255 entry: 237 entry:
256 %a1 = getelementptr inbounds i64, i64* %b1, i64 5 238 %a1 = getelementptr inbounds i64, ptr %b1, i64 5
257 %c1 = bitcast i64* %a1 to i32* 239 br i1 %cond, label %if.then, label %fallthrough
258 br i1 %cond, label %if.then, label %fallthrough 240
259 241 if.then:
260 if.then: 242 %a2 = getelementptr inbounds i64, ptr %b2, i64 5
261 %a2 = getelementptr inbounds i64, i64* %b2, i64 5
262 %c2 = bitcast i64* %a2 to i32*
263 br label %fallthrough 243 br label %fallthrough
264 244
265 fallthrough: 245 fallthrough:
266 ; CHECK-YES: sunk_phi 246 ; CHECK-YES: sunk_phi
267 ; CHECK-NO-LABEL: fallthrough: 247 ; CHECK-NO-LABEL: fallthrough:
268 ; CHECK-NO-NEXT: phi 248 ; CHECK-NO-NEXT: phi
269 ; CHECK-NO-NEXT: br 249 ; CHECK-NO-NEXT: br
270 %c = phi i32* [%c1, %entry], [%c2, %if.then] 250 %c = phi ptr [%a1, %entry], [%a2, %if.then]
271 br label %loop 251 br label %loop
272 252
273 loop: 253 loop:
274 %iv = phi i32 [0, %fallthrough], [%iv.inc, %loop] 254 %iv = phi i32 [0, %fallthrough], [%iv.inc, %loop]
275 %iv.inc = add i32 %iv, 1 255 %iv.inc = add i32 %iv, 1
276 %cmp = icmp slt i32 %iv.inc, %N 256 %cmp = icmp slt i32 %iv.inc, %N
277 br i1 %cmp, label %loop, label %exit 257 br i1 %cmp, label %loop, label %exit
278 258
279 exit: 259 exit:
280 ; CHECK-YES: sunkaddr 260 ; CHECK-YES: sunkaddr
281 %v = load volatile i32, i32* %c, align 4 261 %v = load volatile i32, ptr %c, align 4
282 ret i32 %v 262 ret i32 %v
283 } 263 }
284 264
285 ; Case through a loop. There is a phi. 265 ; Case through a loop. There is a phi.
286 define i32 @test11(i32 %N, i1 %cond, i64* %b1, i64* %b2) { 266 define i32 @test11(i32 %N, i1 %cond, ptr %b1, ptr %b2) {
287 ; CHECK-LABEL: @test11 267 ; CHECK-LABEL: @test11
288 entry: 268 entry:
289 %a1 = getelementptr inbounds i64, i64* %b1, i64 5 269 %a1 = getelementptr inbounds i64, ptr %b1, i64 5
290 %c1 = bitcast i64* %a1 to i32* 270 br i1 %cond, label %if.then, label %fallthrough
291 br i1 %cond, label %if.then, label %fallthrough 271
292 272 if.then:
293 if.then: 273 %a2 = getelementptr inbounds i64, ptr %b2, i64 5
294 %a2 = getelementptr inbounds i64, i64* %b2, i64 5
295 %c2 = bitcast i64* %a2 to i32*
296 br label %fallthrough 274 br label %fallthrough
297 275
298 fallthrough: 276 fallthrough:
299 ; CHECK: phi 277 ; CHECK: phi
300 ; CHECK: phi 278 ; CHECK: phi
301 ; CHECK: br 279 ; CHECK: br
302 %c = phi i32* [%c1, %entry], [%c2, %if.then] 280 %c = phi ptr [%a1, %entry], [%a2, %if.then]
303 %b = phi i64* [%b1, %entry], [%b2, %if.then] 281 %b = phi ptr [%b1, %entry], [%b2, %if.then]
304 br label %loop 282 br label %loop
305 283
306 loop: 284 loop:
307 %iv = phi i32 [0, %fallthrough], [%iv.inc, %loop] 285 %iv = phi i32 [0, %fallthrough], [%iv.inc, %loop]
308 %iv.inc = add i32 %iv, 1 286 %iv.inc = add i32 %iv, 1
309 %cmp = icmp slt i32 %iv.inc, %N 287 %cmp = icmp slt i32 %iv.inc, %N
310 br i1 %cmp, label %loop, label %exit 288 br i1 %cmp, label %loop, label %exit
311 289
312 exit: 290 exit:
313 ; CHECK: sunkaddr 291 ; CHECK: sunkaddr
314 %v = load volatile i32, i32* %c, align 4 292 %v = load volatile i32, ptr %c, align 4
315 ret i32 %v 293 ret i32 %v
316 } 294 }
317 295
318 ; Complex case with address value from previous iteration. 296 ; Complex case with address value from previous iteration.
319 define i32 @test12(i32 %N, i1 %cond, i64* %b1, i64* %b2, i64* %b3) { 297 define i32 @test12(i32 %N, i1 %cond, ptr %b1, ptr %b2, ptr %b3) {
320 ; CHECK-LABEL: @test12 298 ; CHECK-LABEL: @test12
321 entry: 299 entry:
322 %a1 = getelementptr inbounds i64, i64* %b1, i64 5 300 %a1 = getelementptr inbounds i64, ptr %b1, i64 5
323 %c1 = bitcast i64* %a1 to i32*
324 br label %loop 301 br label %loop
325 302
326 loop: 303 loop:
327 ; CHECK-LABEL: loop: 304 ; CHECK-LABEL: loop:
328 ; CHECK-YES: sunk_phi 305 ; CHECK-YES: sunk_phi
329 ; CHECK-NO: phi 306 ; CHECK-NO: phi
330 ; CHECK-NO-NEXT: phi 307 ; CHECK-NO-NEXT: phi
331 ; CHECK-NO-NEXT: phi 308 ; CHECK-NO-NEXT: phi
332 ; CHECK-NO-NEXT: br 309 ; CHECK-NO-NEXT: br
333 %iv = phi i32 [0, %entry], [%iv.inc, %backedge] 310 %iv = phi i32 [0, %entry], [%iv.inc, %backedge]
334 %c3 = phi i32* [%c1, %entry], [%c, %backedge] 311 %c3 = phi ptr [%a1, %entry], [%c, %backedge]
335 %b4 = phi i64* [%b1, %entry], [%b5, %backedge] 312 %b4 = phi ptr [%b1, %entry], [%b5, %backedge]
336 br i1 %cond, label %if.then, label %fallthrough 313 br i1 %cond, label %if.then, label %fallthrough
337 314
338 if.then: 315 if.then:
339 %a2 = getelementptr inbounds i64, i64* %b2, i64 5 316 %a2 = getelementptr inbounds i64, ptr %b2, i64 5
340 %c2 = bitcast i64* %a2 to i32*
341 br label %fallthrough 317 br label %fallthrough
342 318
343 fallthrough: 319 fallthrough:
344 ; CHECK-LABEL: fallthrough: 320 ; CHECK-LABEL: fallthrough:
345 ; CHECK-YES: sunk_phi 321 ; CHECK-YES: sunk_phi
346 ; CHECK-NO: phi 322 ; CHECK-NO: phi
347 ; CHECK-NO-NEXT: phi 323 ; CHECK-NO-NEXT: phi
348 ; CHECK-NO-NEXT: load 324 ; CHECK-NO-NEXT: load
349 %c = phi i32* [%c3, %loop], [%c2, %if.then] 325 %c = phi ptr [%c3, %loop], [%a2, %if.then]
350 %b6 = phi i64* [%b4, %loop], [%b2, %if.then] 326 %b6 = phi ptr [%b4, %loop], [%b2, %if.then]
351 %v = load volatile i32, i32* %c, align 4 327 %v = load volatile i32, ptr %c, align 4
352 %a4 = getelementptr inbounds i64, i64* %b4, i64 5 328 %a4 = getelementptr inbounds i64, ptr %b4, i64 5
353 %c4 = bitcast i64* %a4 to i32*
354 %cmp = icmp slt i32 %iv, 20 329 %cmp = icmp slt i32 %iv, 20
355 br i1 %cmp, label %backedge, label %if.then.2 330 br i1 %cmp, label %backedge, label %if.then.2
356 331
357 if.then.2: 332 if.then.2:
358 br label %backedge 333 br label %backedge
359 334
360 backedge: 335 backedge:
361 %b5 = phi i64* [%b4, %fallthrough], [%b6, %if.then.2] 336 %b5 = phi ptr [%b4, %fallthrough], [%b6, %if.then.2]
362 %iv.inc = add i32 %iv, 1 337 %iv.inc = add i32 %iv, 1
363 %cmp2 = icmp slt i32 %iv.inc, %N 338 %cmp2 = icmp slt i32 %iv.inc, %N
364 br i1 %cmp2, label %loop, label %exit 339 br i1 %cmp2, label %loop, label %exit
365 340
366 exit: 341 exit:
367 ret i32 %v 342 ret i32 %v
368 } 343 }
369 344
370 %struct.S = type {i32, i32} 345 %struct.S = type {i32, i32}
371 ; Case with index 346 ; Case with index
372 define i32 @test13(i1 %cond, %struct.S* %b1, %struct.S* %b2, i64 %Index) { 347 define i32 @test13(i1 %cond, ptr %b1, ptr %b2, i64 %Index) {
373 ; CHECK-LABEL: @test13 348 ; CHECK-LABEL: @test13
374 entry: 349 entry:
375 %a1 = getelementptr inbounds %struct.S, %struct.S* %b1, i64 %Index, i32 1 350 %a1 = getelementptr inbounds %struct.S, ptr %b1, i64 %Index, i32 1
376 br i1 %cond, label %if.then, label %fallthrough 351 br i1 %cond, label %if.then, label %fallthrough
377 352
378 if.then: 353 if.then:
379 %i2 = mul i64 %Index, 2 354 %i2 = mul i64 %Index, 2
380 %a2 = getelementptr inbounds %struct.S, %struct.S* %b2, i64 %Index, i32 1 355 %a2 = getelementptr inbounds %struct.S, ptr %b2, i64 %Index, i32 1
381 br label %fallthrough 356 br label %fallthrough
382 357
383 fallthrough: 358 fallthrough:
384 ; CHECK-YES: sunk_phi 359 ; CHECK-YES: sunk_phi
385 ; CHECK-NO-LABEL: fallthrough: 360 ; CHECK-NO-LABEL: fallthrough:
386 ; CHECK-NO-NEXT: phi 361 ; CHECK-NO-NEXT: phi
387 ; CHECK-NO-NEXT: load 362 ; CHECK-NO-NEXT: load
388 %a = phi i32* [%a1, %entry], [%a2, %if.then] 363 %a = phi ptr [%a1, %entry], [%a2, %if.then]
389 %v = load i32, i32* %a, align 4 364 %v = load i32, ptr %a, align 4
390 ret i32 %v 365 ret i32 %v
391 } 366 }
392 367
393 ; Select of Select case. 368 ; Select of Select case.
394 define i64 @test14(i1 %c1, i1 %c2, i64* %b1, i64* %b2, i64* %b3) { 369 define i64 @test14(i1 %c1, i1 %c2, ptr %b1, ptr %b2, ptr %b3) {
395 ; CHECK-LABEL: @test14 370 ; CHECK-LABEL: @test14
396 entry: 371 entry:
397 ; CHECK-LABEL: entry: 372 ; CHECK-LABEL: entry:
398 %g1 = getelementptr inbounds i64, i64* %b1, i64 5 373 %g1 = getelementptr inbounds i64, ptr %b1, i64 5
399 %g2 = getelementptr inbounds i64, i64* %b2, i64 5 374 %g2 = getelementptr inbounds i64, ptr %b2, i64 5
400 %g3 = getelementptr inbounds i64, i64* %b3, i64 5 375 %g3 = getelementptr inbounds i64, ptr %b3, i64 5
401 %s1 = select i1 %c1, i64* %g1, i64* %g2 376 %s1 = select i1 %c1, ptr %g1, ptr %g2
402 %s2 = select i1 %c2, i64* %s1, i64* %g3 377 %s2 = select i1 %c2, ptr %s1, ptr %g3
403 ; CHECK: sunkaddr 378 ; CHECK: sunkaddr
404 %v = load i64 , i64* %s2, align 8 379 %v = load i64 , ptr %s2, align 8
405 ret i64 %v 380 ret i64 %v
406 } 381 }
407 382
408 ; Select of Phi case. 383 ; Select of Phi case.
409 define i64 @test15(i1 %c1, i1 %c2, i64* %b1, i64* %b2, i64* %b3) { 384 define i64 @test15(i1 %c1, i1 %c2, ptr %b1, ptr %b2, ptr %b3) {
410 ; CHECK-LABEL: @test15 385 ; CHECK-LABEL: @test15
411 entry: 386 entry:
412 %g1 = getelementptr inbounds i64, i64* %b1, i64 5 387 %g1 = getelementptr inbounds i64, ptr %b1, i64 5
413 %g2 = getelementptr inbounds i64, i64* %b2, i64 5 388 %g2 = getelementptr inbounds i64, ptr %b2, i64 5
414 %g3 = getelementptr inbounds i64, i64* %b3, i64 5 389 %g3 = getelementptr inbounds i64, ptr %b3, i64 5
415 br i1 %c1, label %if.then, label %fallthrough 390 br i1 %c1, label %if.then, label %fallthrough
416 391
417 if.then: 392 if.then:
418 br label %fallthrough 393 br label %fallthrough
419 394
420 fallthrough: 395 fallthrough:
421 ; CHECK-LABEL: fallthrough: 396 ; CHECK-LABEL: fallthrough:
422 %p1 = phi i64* [%g1, %entry], [%g2, %if.then] 397 %p1 = phi ptr [%g1, %entry], [%g2, %if.then]
423 %s1 = select i1 %c2, i64* %p1, i64* %g3 398 %s1 = select i1 %c2, ptr %p1, ptr %g3
424 ; CHECK-YES: sunkaddr 399 ; CHECK-YES: sunkaddr
425 ; CHECK-NO: phi 400 ; CHECK-NO: phi
426 ; CHECK-NO-NEXT: select 401 ; CHECK-NO-NEXT: select
427 ; CHECK-NO-NEXT: load 402 ; CHECK-NO-NEXT: load
428 %v = load i64 , i64* %s1, align 8 403 %v = load i64 , ptr %s1, align 8
429 ret i64 %v 404 ret i64 %v
430 } 405 }
431 406
432 ; Select of Phi case. Phi exists 407 ; Select of Phi case. Phi exists
433 define i64 @test16(i1 %c1, i1 %c2, i64* %b1, i64* %b2, i64* %b3) { 408 define i64 @test16(i1 %c1, i1 %c2, ptr %b1, ptr %b2, ptr %b3) {
434 ; CHECK-LABEL: @test16 409 ; CHECK-LABEL: @test16
435 entry: 410 entry:
436 %g1 = getelementptr inbounds i64, i64* %b1, i64 5 411 %g1 = getelementptr inbounds i64, ptr %b1, i64 5
437 %g2 = getelementptr inbounds i64, i64* %b2, i64 5 412 %g2 = getelementptr inbounds i64, ptr %b2, i64 5
438 %g3 = getelementptr inbounds i64, i64* %b3, i64 5 413 %g3 = getelementptr inbounds i64, ptr %b3, i64 5
439 br i1 %c1, label %if.then, label %fallthrough 414 br i1 %c1, label %if.then, label %fallthrough
440 415
441 if.then: 416 if.then:
442 br label %fallthrough 417 br label %fallthrough
443 418
444 fallthrough: 419 fallthrough:
445 ; CHECK-LABEL: fallthrough: 420 ; CHECK-LABEL: fallthrough:
446 %p = phi i64* [%b1, %entry], [%b2, %if.then] 421 %p = phi ptr [%b1, %entry], [%b2, %if.then]
447 %p1 = phi i64* [%g1, %entry], [%g2, %if.then] 422 %p1 = phi ptr [%g1, %entry], [%g2, %if.then]
448 %s1 = select i1 %c2, i64* %p1, i64* %g3 423 %s1 = select i1 %c2, ptr %p1, ptr %g3
449 ; CHECK: sunkaddr 424 ; CHECK: sunkaddr
450 %v = load i64 , i64* %s1, align 8 425 %v = load i64 , ptr %s1, align 8
451 ret i64 %v 426 ret i64 %v
452 } 427 }
453 428
454 ; Phi of Select case. 429 ; Phi of Select case.
455 define i64 @test17(i1 %c1, i1 %c2, i64* %b1, i64* %b2, i64* %b3) { 430 define i64 @test17(i1 %c1, i1 %c2, ptr %b1, ptr %b2, ptr %b3) {
456 ; CHECK-LABEL: @test17 431 ; CHECK-LABEL: @test17
457 entry: 432 entry:
458 %g1 = getelementptr inbounds i64, i64* %b1, i64 5 433 %g1 = getelementptr inbounds i64, ptr %b1, i64 5
459 %g2 = getelementptr inbounds i64, i64* %b2, i64 5 434 %g2 = getelementptr inbounds i64, ptr %b2, i64 5
460 %g3 = getelementptr inbounds i64, i64* %b3, i64 5 435 %g3 = getelementptr inbounds i64, ptr %b3, i64 5
461 %s1 = select i1 %c2, i64* %g1, i64* %g2 436 %s1 = select i1 %c2, ptr %g1, ptr %g2
462 br i1 %c1, label %if.then, label %fallthrough 437 br i1 %c1, label %if.then, label %fallthrough
463 438
464 if.then: 439 if.then:
465 br label %fallthrough 440 br label %fallthrough
466 441
467 fallthrough: 442 fallthrough:
468 ; CHECK-LABEL: fallthrough: 443 ; CHECK-LABEL: fallthrough:
469 %p1 = phi i64* [%s1, %entry], [%g3, %if.then] 444 %p1 = phi ptr [%s1, %entry], [%g3, %if.then]
470 ; CHECK-YES: sunkaddr 445 ; CHECK-YES: sunkaddr
471 ; CHECK-NO: phi 446 ; CHECK-NO: phi
472 ; CHECK-NO-NEXT: load 447 ; CHECK-NO-NEXT: load
473 %v = load i64 , i64* %p1, align 8 448 %v = load i64 , ptr %p1, align 8
474 ret i64 %v 449 ret i64 %v
475 } 450 }
476 451
477 ; The same two addr modes by different paths 452 ; The same two addr modes by different paths
478 define i32 @test18(i1 %cond1, i1 %cond2, i64* %b1, i64* %b2) { 453 define i32 @test18(i1 %cond1, i1 %cond2, ptr %b1, ptr %b2) {
479 ; CHECK-LABEL: @test18 454 ; CHECK-LABEL: @test18
480 entry: 455 entry:
481 %g1 = getelementptr inbounds i64, i64* %b2, i64 5 456 %g1 = getelementptr inbounds i64, ptr %b2, i64 5
482 %bc1 = bitcast i64* %g1 to i32*
483 br i1 %cond1, label %if.then1, label %if.then2 457 br i1 %cond1, label %if.then1, label %if.then2
484 458
485 if.then1: 459 if.then1:
486 %g2 = getelementptr inbounds i64, i64* %b1, i64 5 460 %g2 = getelementptr inbounds i64, ptr %b1, i64 5
487 %bc2 = bitcast i64* %g2 to i32*
488 br label %fallthrough 461 br label %fallthrough
489 462
490 if.then2: 463 if.then2:
491 %bc1_1 = bitcast i64* %g1 to i32*
492 br i1 %cond2, label %fallthrough, label %if.then3 464 br i1 %cond2, label %fallthrough, label %if.then3
493 465
494 if.then3: 466 if.then3:
495 %bc1_2 = bitcast i64* %g1 to i32* 467 br label %fallthrough
496 br label %fallthrough 468
497 469 fallthrough:
498 fallthrough: 470 ; CHECK-YES: sunk_phi
499 ; CHECK-YES: sunk_phi 471 ; CHECK-NO-LABEL: fallthrough:
500 ; CHECK-NO-LABEL: fallthrough: 472 ; CHECK-NO: phi
501 ; CHECK-NO: phi 473 ; CHECK-NO-NEXT: load
502 ; CHECK-NO-NEXT: load 474 %c = phi ptr [%g2, %if.then1], [%g1, %if.then2], [%g1, %if.then3]
503 %c = phi i32* [%bc2, %if.then1], [%bc1_1, %if.then2], [%bc1_2, %if.then3] 475 %v1 = load i32, ptr %c, align 4
504 %v1 = load i32, i32* %c, align 4 476 %g1_1 = getelementptr inbounds i64, ptr %b2, i64 5
505 %g1_1 = getelementptr inbounds i64, i64* %b2, i64 5 477 %v2 = load i32, ptr %g1_1, align 4
506 %bc1_1_1 = bitcast i64* %g1_1 to i32*
507 %v2 = load i32, i32* %bc1_1_1, align 4
508 %v = add i32 %v1, %v2 478 %v = add i32 %v1, %v2
509 ret i32 %v 479 ret i32 %v
510 } 480 }
511 481
512 ; Different types but null is the first? 482 ; Different types but null is the first?