xref: /aosp_15_r20/external/llvm/test/Transforms/SROA/basictest.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -sroa -S | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -passes=sroa -S | FileCheck %s
3*9880d681SAndroid Build Coastguard Worker
4*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-p:64:64:64-p1:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-n8:16:32:64"
5*9880d681SAndroid Build Coastguard Worker
6*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.lifetime.start(i64, i8* nocapture)
7*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.lifetime.end(i64, i8* nocapture)
8*9880d681SAndroid Build Coastguard Worker
9*9880d681SAndroid Build Coastguard Workerdefine i32 @test0() {
10*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test0(
11*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
12*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32
13*9880d681SAndroid Build Coastguard Worker
14*9880d681SAndroid Build Coastguard Workerentry:
15*9880d681SAndroid Build Coastguard Worker  %a1 = alloca i32
16*9880d681SAndroid Build Coastguard Worker  %a2 = alloca float
17*9880d681SAndroid Build Coastguard Worker
18*9880d681SAndroid Build Coastguard Worker  %a1.i8 = bitcast i32* %a1 to i8*
19*9880d681SAndroid Build Coastguard Worker  call void @llvm.lifetime.start(i64 4, i8* %a1.i8)
20*9880d681SAndroid Build Coastguard Worker
21*9880d681SAndroid Build Coastguard Worker  store i32 0, i32* %a1
22*9880d681SAndroid Build Coastguard Worker  %v1 = load i32, i32* %a1
23*9880d681SAndroid Build Coastguard Worker
24*9880d681SAndroid Build Coastguard Worker  call void @llvm.lifetime.end(i64 4, i8* %a1.i8)
25*9880d681SAndroid Build Coastguard Worker
26*9880d681SAndroid Build Coastguard Worker  %a2.i8 = bitcast float* %a2 to i8*
27*9880d681SAndroid Build Coastguard Worker  call void @llvm.lifetime.start(i64 4, i8* %a2.i8)
28*9880d681SAndroid Build Coastguard Worker
29*9880d681SAndroid Build Coastguard Worker  store float 0.0, float* %a2
30*9880d681SAndroid Build Coastguard Worker  %v2 = load float , float * %a2
31*9880d681SAndroid Build Coastguard Worker  %v2.int = bitcast float %v2 to i32
32*9880d681SAndroid Build Coastguard Worker  %sum1 = add i32 %v1, %v2.int
33*9880d681SAndroid Build Coastguard Worker
34*9880d681SAndroid Build Coastguard Worker  call void @llvm.lifetime.end(i64 4, i8* %a2.i8)
35*9880d681SAndroid Build Coastguard Worker
36*9880d681SAndroid Build Coastguard Worker  ret i32 %sum1
37*9880d681SAndroid Build Coastguard Worker}
38*9880d681SAndroid Build Coastguard Worker
39*9880d681SAndroid Build Coastguard Workerdefine i32 @test1() {
40*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test1(
41*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
42*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32 0
43*9880d681SAndroid Build Coastguard Worker
44*9880d681SAndroid Build Coastguard Workerentry:
45*9880d681SAndroid Build Coastguard Worker  %X = alloca { i32, float }
46*9880d681SAndroid Build Coastguard Worker  %Y = getelementptr { i32, float }, { i32, float }* %X, i64 0, i32 0
47*9880d681SAndroid Build Coastguard Worker  store i32 0, i32* %Y
48*9880d681SAndroid Build Coastguard Worker  %Z = load i32, i32* %Y
49*9880d681SAndroid Build Coastguard Worker  ret i32 %Z
50*9880d681SAndroid Build Coastguard Worker}
51*9880d681SAndroid Build Coastguard Worker
52*9880d681SAndroid Build Coastguard Workerdefine i64 @test2(i64 %X) {
53*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test2(
54*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
55*9880d681SAndroid Build Coastguard Worker; CHECK: ret i64 %X
56*9880d681SAndroid Build Coastguard Worker
57*9880d681SAndroid Build Coastguard Workerentry:
58*9880d681SAndroid Build Coastguard Worker  %A = alloca [8 x i8]
59*9880d681SAndroid Build Coastguard Worker  %B = bitcast [8 x i8]* %A to i64*
60*9880d681SAndroid Build Coastguard Worker  store i64 %X, i64* %B
61*9880d681SAndroid Build Coastguard Worker  br label %L2
62*9880d681SAndroid Build Coastguard Worker
63*9880d681SAndroid Build Coastguard WorkerL2:
64*9880d681SAndroid Build Coastguard Worker  %Z = load i64, i64* %B
65*9880d681SAndroid Build Coastguard Worker  ret i64 %Z
66*9880d681SAndroid Build Coastguard Worker}
67*9880d681SAndroid Build Coastguard Worker
68*9880d681SAndroid Build Coastguard Workerdefine void @test3(i8* %dst, i8* %src) {
69*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test3(
70*9880d681SAndroid Build Coastguard Worker
71*9880d681SAndroid Build Coastguard Workerentry:
72*9880d681SAndroid Build Coastguard Worker  %a = alloca [300 x i8]
73*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:  alloca
74*9880d681SAndroid Build Coastguard Worker; CHECK:      %[[test3_a1:.*]] = alloca [42 x i8]
75*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[test3_a2:.*]] = alloca [99 x i8]
76*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[test3_a3:.*]] = alloca [16 x i8]
77*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[test3_a4:.*]] = alloca [42 x i8]
78*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[test3_a5:.*]] = alloca [7 x i8]
79*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[test3_a6:.*]] = alloca [7 x i8]
80*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[test3_a7:.*]] = alloca [85 x i8]
81*9880d681SAndroid Build Coastguard Worker
82*9880d681SAndroid Build Coastguard Worker  %b = getelementptr [300 x i8], [300 x i8]* %a, i64 0, i64 0
83*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %b, i8* %src, i32 300, i32 1, i1 false)
84*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds [42 x i8], [42 x i8]* %[[test3_a1]], i64 0, i64 0
85*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %src, i32 42
86*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds i8, i8* %src, i64 42
87*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[test3_r1:.*]] = load i8, i8* %[[gep]]
88*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds i8, i8* %src, i64 43
89*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds [99 x i8], [99 x i8]* %[[test3_a2]], i64 0, i64 0
90*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 99
91*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds i8, i8* %src, i64 142
92*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds [16 x i8], [16 x i8]* %[[test3_a3]], i64 0, i64 0
93*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 16
94*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds i8, i8* %src, i64 158
95*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds [42 x i8], [42 x i8]* %[[test3_a4]], i64 0, i64 0
96*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 42
97*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds i8, i8* %src, i64 200
98*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test3_a5]], i64 0, i64 0
99*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 7
100*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds i8, i8* %src, i64 207
101*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[test3_r2:.*]] = load i8, i8* %[[gep]]
102*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds i8, i8* %src, i64 208
103*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test3_a6]], i64 0, i64 0
104*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 7
105*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds i8, i8* %src, i64 215
106*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds [85 x i8], [85 x i8]* %[[test3_a7]], i64 0, i64 0
107*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 85
108*9880d681SAndroid Build Coastguard Worker
109*9880d681SAndroid Build Coastguard Worker  ; Clobber a single element of the array, this should be promotable.
110*9880d681SAndroid Build Coastguard Worker  %c = getelementptr [300 x i8], [300 x i8]* %a, i64 0, i64 42
111*9880d681SAndroid Build Coastguard Worker  store i8 0, i8* %c
112*9880d681SAndroid Build Coastguard Worker
113*9880d681SAndroid Build Coastguard Worker  ; Make a sequence of overlapping stores to the array. These overlap both in
114*9880d681SAndroid Build Coastguard Worker  ; forward strides and in shrinking accesses.
115*9880d681SAndroid Build Coastguard Worker  %overlap.1.i8 = getelementptr [300 x i8], [300 x i8]* %a, i64 0, i64 142
116*9880d681SAndroid Build Coastguard Worker  %overlap.2.i8 = getelementptr [300 x i8], [300 x i8]* %a, i64 0, i64 143
117*9880d681SAndroid Build Coastguard Worker  %overlap.3.i8 = getelementptr [300 x i8], [300 x i8]* %a, i64 0, i64 144
118*9880d681SAndroid Build Coastguard Worker  %overlap.4.i8 = getelementptr [300 x i8], [300 x i8]* %a, i64 0, i64 145
119*9880d681SAndroid Build Coastguard Worker  %overlap.5.i8 = getelementptr [300 x i8], [300 x i8]* %a, i64 0, i64 146
120*9880d681SAndroid Build Coastguard Worker  %overlap.6.i8 = getelementptr [300 x i8], [300 x i8]* %a, i64 0, i64 147
121*9880d681SAndroid Build Coastguard Worker  %overlap.7.i8 = getelementptr [300 x i8], [300 x i8]* %a, i64 0, i64 148
122*9880d681SAndroid Build Coastguard Worker  %overlap.8.i8 = getelementptr [300 x i8], [300 x i8]* %a, i64 0, i64 149
123*9880d681SAndroid Build Coastguard Worker  %overlap.9.i8 = getelementptr [300 x i8], [300 x i8]* %a, i64 0, i64 150
124*9880d681SAndroid Build Coastguard Worker  %overlap.1.i16 = bitcast i8* %overlap.1.i8 to i16*
125*9880d681SAndroid Build Coastguard Worker  %overlap.1.i32 = bitcast i8* %overlap.1.i8 to i32*
126*9880d681SAndroid Build Coastguard Worker  %overlap.1.i64 = bitcast i8* %overlap.1.i8 to i64*
127*9880d681SAndroid Build Coastguard Worker  %overlap.2.i64 = bitcast i8* %overlap.2.i8 to i64*
128*9880d681SAndroid Build Coastguard Worker  %overlap.3.i64 = bitcast i8* %overlap.3.i8 to i64*
129*9880d681SAndroid Build Coastguard Worker  %overlap.4.i64 = bitcast i8* %overlap.4.i8 to i64*
130*9880d681SAndroid Build Coastguard Worker  %overlap.5.i64 = bitcast i8* %overlap.5.i8 to i64*
131*9880d681SAndroid Build Coastguard Worker  %overlap.6.i64 = bitcast i8* %overlap.6.i8 to i64*
132*9880d681SAndroid Build Coastguard Worker  %overlap.7.i64 = bitcast i8* %overlap.7.i8 to i64*
133*9880d681SAndroid Build Coastguard Worker  %overlap.8.i64 = bitcast i8* %overlap.8.i8 to i64*
134*9880d681SAndroid Build Coastguard Worker  %overlap.9.i64 = bitcast i8* %overlap.9.i8 to i64*
135*9880d681SAndroid Build Coastguard Worker  store i8 1, i8* %overlap.1.i8
136*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [16 x i8], [16 x i8]* %[[test3_a3]], i64 0, i64 0
137*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i8 1, i8* %[[gep]]
138*9880d681SAndroid Build Coastguard Worker  store i16 1, i16* %overlap.1.i16
139*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast [16 x i8]* %[[test3_a3]] to i16*
140*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i16 1, i16* %[[bitcast]]
141*9880d681SAndroid Build Coastguard Worker  store i32 1, i32* %overlap.1.i32
142*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast [16 x i8]* %[[test3_a3]] to i32*
143*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i32 1, i32* %[[bitcast]]
144*9880d681SAndroid Build Coastguard Worker  store i64 1, i64* %overlap.1.i64
145*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast [16 x i8]* %[[test3_a3]] to i64*
146*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i64 1, i64* %[[bitcast]]
147*9880d681SAndroid Build Coastguard Worker  store i64 2, i64* %overlap.2.i64
148*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [16 x i8], [16 x i8]* %[[test3_a3]], i64 0, i64 1
149*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast i8* %[[gep]] to i64*
150*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i64 2, i64* %[[bitcast]]
151*9880d681SAndroid Build Coastguard Worker  store i64 3, i64* %overlap.3.i64
152*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [16 x i8], [16 x i8]* %[[test3_a3]], i64 0, i64 2
153*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast i8* %[[gep]] to i64*
154*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i64 3, i64* %[[bitcast]]
155*9880d681SAndroid Build Coastguard Worker  store i64 4, i64* %overlap.4.i64
156*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [16 x i8], [16 x i8]* %[[test3_a3]], i64 0, i64 3
157*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast i8* %[[gep]] to i64*
158*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i64 4, i64* %[[bitcast]]
159*9880d681SAndroid Build Coastguard Worker  store i64 5, i64* %overlap.5.i64
160*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [16 x i8], [16 x i8]* %[[test3_a3]], i64 0, i64 4
161*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast i8* %[[gep]] to i64*
162*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i64 5, i64* %[[bitcast]]
163*9880d681SAndroid Build Coastguard Worker  store i64 6, i64* %overlap.6.i64
164*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [16 x i8], [16 x i8]* %[[test3_a3]], i64 0, i64 5
165*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast i8* %[[gep]] to i64*
166*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i64 6, i64* %[[bitcast]]
167*9880d681SAndroid Build Coastguard Worker  store i64 7, i64* %overlap.7.i64
168*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [16 x i8], [16 x i8]* %[[test3_a3]], i64 0, i64 6
169*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast i8* %[[gep]] to i64*
170*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i64 7, i64* %[[bitcast]]
171*9880d681SAndroid Build Coastguard Worker  store i64 8, i64* %overlap.8.i64
172*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [16 x i8], [16 x i8]* %[[test3_a3]], i64 0, i64 7
173*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast i8* %[[gep]] to i64*
174*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i64 8, i64* %[[bitcast]]
175*9880d681SAndroid Build Coastguard Worker  store i64 9, i64* %overlap.9.i64
176*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [16 x i8], [16 x i8]* %[[test3_a3]], i64 0, i64 8
177*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast i8* %[[gep]] to i64*
178*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i64 9, i64* %[[bitcast]]
179*9880d681SAndroid Build Coastguard Worker
180*9880d681SAndroid Build Coastguard Worker  ; Make two sequences of overlapping stores with more gaps and irregularities.
181*9880d681SAndroid Build Coastguard Worker  %overlap2.1.0.i8 = getelementptr [300 x i8], [300 x i8]* %a, i64 0, i64 200
182*9880d681SAndroid Build Coastguard Worker  %overlap2.1.1.i8 = getelementptr [300 x i8], [300 x i8]* %a, i64 0, i64 201
183*9880d681SAndroid Build Coastguard Worker  %overlap2.1.2.i8 = getelementptr [300 x i8], [300 x i8]* %a, i64 0, i64 202
184*9880d681SAndroid Build Coastguard Worker  %overlap2.1.3.i8 = getelementptr [300 x i8], [300 x i8]* %a, i64 0, i64 203
185*9880d681SAndroid Build Coastguard Worker
186*9880d681SAndroid Build Coastguard Worker  %overlap2.2.0.i8 = getelementptr [300 x i8], [300 x i8]* %a, i64 0, i64 208
187*9880d681SAndroid Build Coastguard Worker  %overlap2.2.1.i8 = getelementptr [300 x i8], [300 x i8]* %a, i64 0, i64 209
188*9880d681SAndroid Build Coastguard Worker  %overlap2.2.2.i8 = getelementptr [300 x i8], [300 x i8]* %a, i64 0, i64 210
189*9880d681SAndroid Build Coastguard Worker  %overlap2.2.3.i8 = getelementptr [300 x i8], [300 x i8]* %a, i64 0, i64 211
190*9880d681SAndroid Build Coastguard Worker
191*9880d681SAndroid Build Coastguard Worker  %overlap2.1.0.i16 = bitcast i8* %overlap2.1.0.i8 to i16*
192*9880d681SAndroid Build Coastguard Worker  %overlap2.1.0.i32 = bitcast i8* %overlap2.1.0.i8 to i32*
193*9880d681SAndroid Build Coastguard Worker  %overlap2.1.1.i32 = bitcast i8* %overlap2.1.1.i8 to i32*
194*9880d681SAndroid Build Coastguard Worker  %overlap2.1.2.i32 = bitcast i8* %overlap2.1.2.i8 to i32*
195*9880d681SAndroid Build Coastguard Worker  %overlap2.1.3.i32 = bitcast i8* %overlap2.1.3.i8 to i32*
196*9880d681SAndroid Build Coastguard Worker  store i8 1,  i8*  %overlap2.1.0.i8
197*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test3_a5]], i64 0, i64 0
198*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i8 1, i8* %[[gep]]
199*9880d681SAndroid Build Coastguard Worker  store i16 1, i16* %overlap2.1.0.i16
200*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast [7 x i8]* %[[test3_a5]] to i16*
201*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i16 1, i16* %[[bitcast]]
202*9880d681SAndroid Build Coastguard Worker  store i32 1, i32* %overlap2.1.0.i32
203*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast [7 x i8]* %[[test3_a5]] to i32*
204*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i32 1, i32* %[[bitcast]]
205*9880d681SAndroid Build Coastguard Worker  store i32 2, i32* %overlap2.1.1.i32
206*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test3_a5]], i64 0, i64 1
207*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast i8* %[[gep]] to i32*
208*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i32 2, i32* %[[bitcast]]
209*9880d681SAndroid Build Coastguard Worker  store i32 3, i32* %overlap2.1.2.i32
210*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test3_a5]], i64 0, i64 2
211*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast i8* %[[gep]] to i32*
212*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i32 3, i32* %[[bitcast]]
213*9880d681SAndroid Build Coastguard Worker  store i32 4, i32* %overlap2.1.3.i32
214*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test3_a5]], i64 0, i64 3
215*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast i8* %[[gep]] to i32*
216*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i32 4, i32* %[[bitcast]]
217*9880d681SAndroid Build Coastguard Worker
218*9880d681SAndroid Build Coastguard Worker  %overlap2.2.0.i32 = bitcast i8* %overlap2.2.0.i8 to i32*
219*9880d681SAndroid Build Coastguard Worker  %overlap2.2.1.i16 = bitcast i8* %overlap2.2.1.i8 to i16*
220*9880d681SAndroid Build Coastguard Worker  %overlap2.2.1.i32 = bitcast i8* %overlap2.2.1.i8 to i32*
221*9880d681SAndroid Build Coastguard Worker  %overlap2.2.2.i32 = bitcast i8* %overlap2.2.2.i8 to i32*
222*9880d681SAndroid Build Coastguard Worker  %overlap2.2.3.i32 = bitcast i8* %overlap2.2.3.i8 to i32*
223*9880d681SAndroid Build Coastguard Worker  store i32 1, i32* %overlap2.2.0.i32
224*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast [7 x i8]* %[[test3_a6]] to i32*
225*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i32 1, i32* %[[bitcast]]
226*9880d681SAndroid Build Coastguard Worker  store i8 1,  i8*  %overlap2.2.1.i8
227*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test3_a6]], i64 0, i64 1
228*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i8 1, i8* %[[gep]]
229*9880d681SAndroid Build Coastguard Worker  store i16 1, i16* %overlap2.2.1.i16
230*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test3_a6]], i64 0, i64 1
231*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast i8* %[[gep]] to i16*
232*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i16 1, i16* %[[bitcast]]
233*9880d681SAndroid Build Coastguard Worker  store i32 1, i32* %overlap2.2.1.i32
234*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test3_a6]], i64 0, i64 1
235*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast i8* %[[gep]] to i32*
236*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i32 1, i32* %[[bitcast]]
237*9880d681SAndroid Build Coastguard Worker  store i32 3, i32* %overlap2.2.2.i32
238*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test3_a6]], i64 0, i64 2
239*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast i8* %[[gep]] to i32*
240*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i32 3, i32* %[[bitcast]]
241*9880d681SAndroid Build Coastguard Worker  store i32 4, i32* %overlap2.2.3.i32
242*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test3_a6]], i64 0, i64 3
243*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast i8* %[[gep]] to i32*
244*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i32 4, i32* %[[bitcast]]
245*9880d681SAndroid Build Coastguard Worker
246*9880d681SAndroid Build Coastguard Worker  %overlap2.prefix = getelementptr i8, i8* %overlap2.1.1.i8, i64 -4
247*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %overlap2.prefix, i8* %src, i32 8, i32 1, i1 false)
248*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds [42 x i8], [42 x i8]* %[[test3_a4]], i64 0, i64 39
249*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %src, i32 3
250*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds i8, i8* %src, i64 3
251*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test3_a5]], i64 0, i64 0
252*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 5
253*9880d681SAndroid Build Coastguard Worker
254*9880d681SAndroid Build Coastguard Worker  ; Bridge between the overlapping areas
255*9880d681SAndroid Build Coastguard Worker  call void @llvm.memset.p0i8.i32(i8* %overlap2.1.2.i8, i8 42, i32 8, i32 1, i1 false)
256*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test3_a5]], i64 0, i64 2
257*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memset.p0i8.i32(i8* %[[gep]], i8 42, i32 5
258*9880d681SAndroid Build Coastguard Worker; ...promoted i8 store...
259*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test3_a6]], i64 0, i64 0
260*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memset.p0i8.i32(i8* %[[gep]], i8 42, i32 2
261*9880d681SAndroid Build Coastguard Worker
262*9880d681SAndroid Build Coastguard Worker  ; Entirely within the second overlap.
263*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %overlap2.2.1.i8, i8* %src, i32 5, i32 1, i1 false)
264*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test3_a6]], i64 0, i64 1
265*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep]], i8* %src, i32 5
266*9880d681SAndroid Build Coastguard Worker
267*9880d681SAndroid Build Coastguard Worker  ; Trailing past the second overlap.
268*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %overlap2.2.2.i8, i8* %src, i32 8, i32 1, i1 false)
269*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test3_a6]], i64 0, i64 2
270*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep]], i8* %src, i32 5
271*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds i8, i8* %src, i64 5
272*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds [85 x i8], [85 x i8]* %[[test3_a7]], i64 0, i64 0
273*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 3
274*9880d681SAndroid Build Coastguard Worker
275*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %b, i32 300, i32 1, i1 false)
276*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [42 x i8], [42 x i8]* %[[test3_a1]], i64 0, i64 0
277*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %[[gep]], i32 42
278*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds i8, i8* %dst, i64 42
279*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i8 0, i8* %[[gep]]
280*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds i8, i8* %dst, i64 43
281*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds [99 x i8], [99 x i8]* %[[test3_a2]], i64 0, i64 0
282*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 99
283*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds i8, i8* %dst, i64 142
284*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds [16 x i8], [16 x i8]* %[[test3_a3]], i64 0, i64 0
285*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 16
286*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds i8, i8* %dst, i64 158
287*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds [42 x i8], [42 x i8]* %[[test3_a4]], i64 0, i64 0
288*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 42
289*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds i8, i8* %dst, i64 200
290*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test3_a5]], i64 0, i64 0
291*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 7
292*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds i8, i8* %dst, i64 207
293*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i8 42, i8* %[[gep]]
294*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds i8, i8* %dst, i64 208
295*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test3_a6]], i64 0, i64 0
296*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 7
297*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds i8, i8* %dst, i64 215
298*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds [85 x i8], [85 x i8]* %[[test3_a7]], i64 0, i64 0
299*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 85
300*9880d681SAndroid Build Coastguard Worker
301*9880d681SAndroid Build Coastguard Worker  ret void
302*9880d681SAndroid Build Coastguard Worker}
303*9880d681SAndroid Build Coastguard Worker
304*9880d681SAndroid Build Coastguard Workerdefine void @test4(i8* %dst, i8* %src) {
305*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test4(
306*9880d681SAndroid Build Coastguard Worker
307*9880d681SAndroid Build Coastguard Workerentry:
308*9880d681SAndroid Build Coastguard Worker  %a = alloca [100 x i8]
309*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:  alloca
310*9880d681SAndroid Build Coastguard Worker; CHECK:      %[[test4_a1:.*]] = alloca [20 x i8]
311*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[test4_a2:.*]] = alloca [7 x i8]
312*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[test4_a3:.*]] = alloca [10 x i8]
313*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[test4_a4:.*]] = alloca [7 x i8]
314*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[test4_a5:.*]] = alloca [7 x i8]
315*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[test4_a6:.*]] = alloca [40 x i8]
316*9880d681SAndroid Build Coastguard Worker
317*9880d681SAndroid Build Coastguard Worker  %b = getelementptr [100 x i8], [100 x i8]* %a, i64 0, i64 0
318*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %b, i8* %src, i32 100, i32 1, i1 false)
319*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [20 x i8], [20 x i8]* %[[test4_a1]], i64 0, i64 0
320*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep]], i8* %src, i32 20
321*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds i8, i8* %src, i64 20
322*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast i8* %[[gep]] to i16*
323*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[test4_r1:.*]] = load i16, i16* %[[bitcast]]
324*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds i8, i8* %src, i64 22
325*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[test4_r2:.*]] = load i8, i8* %[[gep]]
326*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds i8, i8* %src, i64 23
327*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test4_a2]], i64 0, i64 0
328*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 7
329*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds i8, i8* %src, i64 30
330*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds [10 x i8], [10 x i8]* %[[test4_a3]], i64 0, i64 0
331*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 10
332*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds i8, i8* %src, i64 40
333*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast i8* %[[gep]] to i16*
334*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[test4_r3:.*]] = load i16, i16* %[[bitcast]]
335*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds i8, i8* %src, i64 42
336*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[test4_r4:.*]] = load i8, i8* %[[gep]]
337*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds i8, i8* %src, i64 43
338*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test4_a4]], i64 0, i64 0
339*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 7
340*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds i8, i8* %src, i64 50
341*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast i8* %[[gep]] to i16*
342*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[test4_r5:.*]] = load i16, i16* %[[bitcast]]
343*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds i8, i8* %src, i64 52
344*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[test4_r6:.*]] = load i8, i8* %[[gep]]
345*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds i8, i8* %src, i64 53
346*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test4_a5]], i64 0, i64 0
347*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 7
348*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds i8, i8* %src, i64 60
349*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds [40 x i8], [40 x i8]* %[[test4_a6]], i64 0, i64 0
350*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 40
351*9880d681SAndroid Build Coastguard Worker
352*9880d681SAndroid Build Coastguard Worker  %a.src.1 = getelementptr [100 x i8], [100 x i8]* %a, i64 0, i64 20
353*9880d681SAndroid Build Coastguard Worker  %a.dst.1 = getelementptr [100 x i8], [100 x i8]* %a, i64 0, i64 40
354*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %a.dst.1, i8* %a.src.1, i32 10, i32 1, i1 false)
355*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test4_a4]], i64 0, i64 0
356*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test4_a2]], i64 0, i64 0
357*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 7
358*9880d681SAndroid Build Coastguard Worker
359*9880d681SAndroid Build Coastguard Worker  ; Clobber a single element of the array, this should be promotable, and be deleted.
360*9880d681SAndroid Build Coastguard Worker  %c = getelementptr [100 x i8], [100 x i8]* %a, i64 0, i64 42
361*9880d681SAndroid Build Coastguard Worker  store i8 0, i8* %c
362*9880d681SAndroid Build Coastguard Worker
363*9880d681SAndroid Build Coastguard Worker  %a.src.2 = getelementptr [100 x i8], [100 x i8]* %a, i64 0, i64 50
364*9880d681SAndroid Build Coastguard Worker  call void @llvm.memmove.p0i8.p0i8.i32(i8* %a.dst.1, i8* %a.src.2, i32 10, i32 1, i1 false)
365*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test4_a4]], i64 0, i64 0
366*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test4_a5]], i64 0, i64 0
367*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 7
368*9880d681SAndroid Build Coastguard Worker
369*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %b, i32 100, i32 1, i1 false)
370*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds [20 x i8], [20 x i8]* %[[test4_a1]], i64 0, i64 0
371*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %[[gep]], i32 20
372*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds i8, i8* %dst, i64 20
373*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast i8* %[[gep]] to i16*
374*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i16 %[[test4_r1]], i16* %[[bitcast]]
375*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds i8, i8* %dst, i64 22
376*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i8 %[[test4_r2]], i8* %[[gep]]
377*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds i8, i8* %dst, i64 23
378*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test4_a2]], i64 0, i64 0
379*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 7
380*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds i8, i8* %dst, i64 30
381*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds [10 x i8], [10 x i8]* %[[test4_a3]], i64 0, i64 0
382*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 10
383*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds i8, i8* %dst, i64 40
384*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast i8* %[[gep]] to i16*
385*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i16 %[[test4_r5]], i16* %[[bitcast]]
386*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds i8, i8* %dst, i64 42
387*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i8 %[[test4_r6]], i8* %[[gep]]
388*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds i8, i8* %dst, i64 43
389*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test4_a4]], i64 0, i64 0
390*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 7
391*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds i8, i8* %dst, i64 50
392*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[bitcast:.*]] = bitcast i8* %[[gep]] to i16*
393*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i16 %[[test4_r5]], i16* %[[bitcast]]
394*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr inbounds i8, i8* %dst, i64 52
395*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i8 %[[test4_r6]], i8* %[[gep]]
396*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds i8, i8* %dst, i64 53
397*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds [7 x i8], [7 x i8]* %[[test4_a5]], i64 0, i64 0
398*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 7
399*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_dst:.*]] = getelementptr inbounds i8, i8* %dst, i64 60
400*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep_src:.*]] = getelementptr inbounds [40 x i8], [40 x i8]* %[[test4_a6]], i64 0, i64 0
401*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[gep_dst]], i8* %[[gep_src]], i32 40
402*9880d681SAndroid Build Coastguard Worker
403*9880d681SAndroid Build Coastguard Worker  ret void
404*9880d681SAndroid Build Coastguard Worker}
405*9880d681SAndroid Build Coastguard Worker
406*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
407*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.memcpy.p1i8.p0i8.i32(i8 addrspace(1)* nocapture, i8* nocapture, i32, i32, i1) nounwind
408*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.memmove.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
409*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i32, i1) nounwind
410*9880d681SAndroid Build Coastguard Worker
411*9880d681SAndroid Build Coastguard Workerdefine i16 @test5() {
412*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test5(
413*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca float
414*9880d681SAndroid Build Coastguard Worker; CHECK:      %[[cast:.*]] = bitcast float 0.0{{.*}} to i32
415*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[shr:.*]] = lshr i32 %[[cast]], 16
416*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[trunc:.*]] = trunc i32 %[[shr]] to i16
417*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ret i16 %[[trunc]]
418*9880d681SAndroid Build Coastguard Worker
419*9880d681SAndroid Build Coastguard Workerentry:
420*9880d681SAndroid Build Coastguard Worker  %a = alloca [4 x i8]
421*9880d681SAndroid Build Coastguard Worker  %fptr = bitcast [4 x i8]* %a to float*
422*9880d681SAndroid Build Coastguard Worker  store float 0.0, float* %fptr
423*9880d681SAndroid Build Coastguard Worker  %ptr = getelementptr [4 x i8], [4 x i8]* %a, i32 0, i32 2
424*9880d681SAndroid Build Coastguard Worker  %iptr = bitcast i8* %ptr to i16*
425*9880d681SAndroid Build Coastguard Worker  %val = load i16, i16* %iptr
426*9880d681SAndroid Build Coastguard Worker  ret i16 %val
427*9880d681SAndroid Build Coastguard Worker}
428*9880d681SAndroid Build Coastguard Worker
429*9880d681SAndroid Build Coastguard Workerdefine i32 @test6() {
430*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test6(
431*9880d681SAndroid Build Coastguard Worker; CHECK: alloca i32
432*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store volatile i32
433*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: load i32, i32*
434*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ret i32
435*9880d681SAndroid Build Coastguard Worker
436*9880d681SAndroid Build Coastguard Workerentry:
437*9880d681SAndroid Build Coastguard Worker  %a = alloca [4 x i8]
438*9880d681SAndroid Build Coastguard Worker  %ptr = getelementptr [4 x i8], [4 x i8]* %a, i32 0, i32 0
439*9880d681SAndroid Build Coastguard Worker  call void @llvm.memset.p0i8.i32(i8* %ptr, i8 42, i32 4, i32 1, i1 true)
440*9880d681SAndroid Build Coastguard Worker  %iptr = bitcast i8* %ptr to i32*
441*9880d681SAndroid Build Coastguard Worker  %val = load i32, i32* %iptr
442*9880d681SAndroid Build Coastguard Worker  ret i32 %val
443*9880d681SAndroid Build Coastguard Worker}
444*9880d681SAndroid Build Coastguard Worker
445*9880d681SAndroid Build Coastguard Workerdefine void @test7(i8* %src, i8* %dst) {
446*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test7(
447*9880d681SAndroid Build Coastguard Worker; CHECK: alloca i32
448*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: bitcast i8* %src to i32*
449*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: load volatile i32, i32*
450*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store volatile i32
451*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: bitcast i8* %dst to i32*
452*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: load volatile i32, i32*
453*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store volatile i32
454*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ret
455*9880d681SAndroid Build Coastguard Worker
456*9880d681SAndroid Build Coastguard Workerentry:
457*9880d681SAndroid Build Coastguard Worker  %a = alloca [4 x i8]
458*9880d681SAndroid Build Coastguard Worker  %ptr = getelementptr [4 x i8], [4 x i8]* %a, i32 0, i32 0
459*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %ptr, i8* %src, i32 4, i32 1, i1 true)
460*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %ptr, i32 4, i32 1, i1 true)
461*9880d681SAndroid Build Coastguard Worker  ret void
462*9880d681SAndroid Build Coastguard Worker}
463*9880d681SAndroid Build Coastguard Worker
464*9880d681SAndroid Build Coastguard Worker
465*9880d681SAndroid Build Coastguard Worker%S1 = type { i32, i32, [16 x i8] }
466*9880d681SAndroid Build Coastguard Worker%S2 = type { %S1*, %S2* }
467*9880d681SAndroid Build Coastguard Worker
468*9880d681SAndroid Build Coastguard Workerdefine %S2 @test8(%S2* %s2) {
469*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test8(
470*9880d681SAndroid Build Coastguard Workerentry:
471*9880d681SAndroid Build Coastguard Worker  %new = alloca %S2
472*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
473*9880d681SAndroid Build Coastguard Worker
474*9880d681SAndroid Build Coastguard Worker  %s2.next.ptr = getelementptr %S2, %S2* %s2, i64 0, i32 1
475*9880d681SAndroid Build Coastguard Worker  %s2.next = load %S2*, %S2** %s2.next.ptr
476*9880d681SAndroid Build Coastguard Worker; CHECK:      %[[gep:.*]] = getelementptr %S2, %S2* %s2, i64 0, i32 1
477*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[next:.*]] = load %S2*, %S2** %[[gep]]
478*9880d681SAndroid Build Coastguard Worker
479*9880d681SAndroid Build Coastguard Worker  %s2.next.s1.ptr = getelementptr %S2, %S2* %s2.next, i64 0, i32 0
480*9880d681SAndroid Build Coastguard Worker  %s2.next.s1 = load %S1*, %S1** %s2.next.s1.ptr
481*9880d681SAndroid Build Coastguard Worker  %new.s1.ptr = getelementptr %S2, %S2* %new, i64 0, i32 0
482*9880d681SAndroid Build Coastguard Worker  store %S1* %s2.next.s1, %S1** %new.s1.ptr
483*9880d681SAndroid Build Coastguard Worker  %s2.next.next.ptr = getelementptr %S2, %S2* %s2.next, i64 0, i32 1
484*9880d681SAndroid Build Coastguard Worker  %s2.next.next = load %S2*, %S2** %s2.next.next.ptr
485*9880d681SAndroid Build Coastguard Worker  %new.next.ptr = getelementptr %S2, %S2* %new, i64 0, i32 1
486*9880d681SAndroid Build Coastguard Worker  store %S2* %s2.next.next, %S2** %new.next.ptr
487*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr %S2, %S2* %[[next]], i64 0, i32 0
488*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[next_s1:.*]] = load %S1*, %S1** %[[gep]]
489*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[gep:.*]] = getelementptr %S2, %S2* %[[next]], i64 0, i32 1
490*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[next_next:.*]] = load %S2*, %S2** %[[gep]]
491*9880d681SAndroid Build Coastguard Worker
492*9880d681SAndroid Build Coastguard Worker  %new.s1 = load %S1*, %S1** %new.s1.ptr
493*9880d681SAndroid Build Coastguard Worker  %result1 = insertvalue %S2 undef, %S1* %new.s1, 0
494*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[result1:.*]] = insertvalue %S2 undef, %S1* %[[next_s1]], 0
495*9880d681SAndroid Build Coastguard Worker  %new.next = load %S2*, %S2** %new.next.ptr
496*9880d681SAndroid Build Coastguard Worker  %result2 = insertvalue %S2 %result1, %S2* %new.next, 1
497*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[result2:.*]] = insertvalue %S2 %[[result1]], %S2* %[[next_next]], 1
498*9880d681SAndroid Build Coastguard Worker  ret %S2 %result2
499*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ret %S2 %[[result2]]
500*9880d681SAndroid Build Coastguard Worker}
501*9880d681SAndroid Build Coastguard Worker
502*9880d681SAndroid Build Coastguard Workerdefine i64 @test9() {
503*9880d681SAndroid Build Coastguard Worker; Ensure we can handle loads off the end of an alloca even when wrapped in
504*9880d681SAndroid Build Coastguard Worker; weird bit casts and types. This is valid IR due to the alignment and masking
505*9880d681SAndroid Build Coastguard Worker; off the bits past the end of the alloca.
506*9880d681SAndroid Build Coastguard Worker;
507*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test9(
508*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
509*9880d681SAndroid Build Coastguard Worker; CHECK:      %[[b2:.*]] = zext i8 26 to i64
510*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[s2:.*]] = shl i64 %[[b2]], 16
511*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[m2:.*]] = and i64 undef, -16711681
512*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[i2:.*]] = or i64 %[[m2]], %[[s2]]
513*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[b1:.*]] = zext i8 0 to i64
514*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[s1:.*]] = shl i64 %[[b1]], 8
515*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[m1:.*]] = and i64 %[[i2]], -65281
516*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[i1:.*]] = or i64 %[[m1]], %[[s1]]
517*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[b0:.*]] = zext i8 0 to i64
518*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[m0:.*]] = and i64 %[[i1]], -256
519*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[i0:.*]] = or i64 %[[m0]], %[[b0]]
520*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[result:.*]] = and i64 %[[i0]], 16777215
521*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ret i64 %[[result]]
522*9880d681SAndroid Build Coastguard Worker
523*9880d681SAndroid Build Coastguard Workerentry:
524*9880d681SAndroid Build Coastguard Worker  %a = alloca { [3 x i8] }, align 8
525*9880d681SAndroid Build Coastguard Worker  %gep1 = getelementptr inbounds { [3 x i8] }, { [3 x i8] }* %a, i32 0, i32 0, i32 0
526*9880d681SAndroid Build Coastguard Worker  store i8 0, i8* %gep1, align 1
527*9880d681SAndroid Build Coastguard Worker  %gep2 = getelementptr inbounds { [3 x i8] }, { [3 x i8] }* %a, i32 0, i32 0, i32 1
528*9880d681SAndroid Build Coastguard Worker  store i8 0, i8* %gep2, align 1
529*9880d681SAndroid Build Coastguard Worker  %gep3 = getelementptr inbounds { [3 x i8] }, { [3 x i8] }* %a, i32 0, i32 0, i32 2
530*9880d681SAndroid Build Coastguard Worker  store i8 26, i8* %gep3, align 1
531*9880d681SAndroid Build Coastguard Worker  %cast = bitcast { [3 x i8] }* %a to { i64 }*
532*9880d681SAndroid Build Coastguard Worker  %elt = getelementptr inbounds { i64 }, { i64 }* %cast, i32 0, i32 0
533*9880d681SAndroid Build Coastguard Worker  %load = load i64, i64* %elt
534*9880d681SAndroid Build Coastguard Worker  %result = and i64 %load, 16777215
535*9880d681SAndroid Build Coastguard Worker  ret i64 %result
536*9880d681SAndroid Build Coastguard Worker}
537*9880d681SAndroid Build Coastguard Worker
538*9880d681SAndroid Build Coastguard Workerdefine %S2* @test10() {
539*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test10(
540*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca %S2*
541*9880d681SAndroid Build Coastguard Worker; CHECK: ret %S2* null
542*9880d681SAndroid Build Coastguard Worker
543*9880d681SAndroid Build Coastguard Workerentry:
544*9880d681SAndroid Build Coastguard Worker  %a = alloca [8 x i8]
545*9880d681SAndroid Build Coastguard Worker  %ptr = getelementptr [8 x i8], [8 x i8]* %a, i32 0, i32 0
546*9880d681SAndroid Build Coastguard Worker  call void @llvm.memset.p0i8.i32(i8* %ptr, i8 0, i32 8, i32 1, i1 false)
547*9880d681SAndroid Build Coastguard Worker  %s2ptrptr = bitcast i8* %ptr to %S2**
548*9880d681SAndroid Build Coastguard Worker  %s2ptr = load %S2*, %S2** %s2ptrptr
549*9880d681SAndroid Build Coastguard Worker  ret %S2* %s2ptr
550*9880d681SAndroid Build Coastguard Worker}
551*9880d681SAndroid Build Coastguard Worker
552*9880d681SAndroid Build Coastguard Workerdefine i32 @test11() {
553*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test11(
554*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
555*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32 0
556*9880d681SAndroid Build Coastguard Worker
557*9880d681SAndroid Build Coastguard Workerentry:
558*9880d681SAndroid Build Coastguard Worker  %X = alloca i32
559*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %good, label %bad
560*9880d681SAndroid Build Coastguard Worker
561*9880d681SAndroid Build Coastguard Workergood:
562*9880d681SAndroid Build Coastguard Worker  %Y = getelementptr i32, i32* %X, i64 0
563*9880d681SAndroid Build Coastguard Worker  store i32 0, i32* %Y
564*9880d681SAndroid Build Coastguard Worker  %Z = load i32, i32* %Y
565*9880d681SAndroid Build Coastguard Worker  ret i32 %Z
566*9880d681SAndroid Build Coastguard Worker
567*9880d681SAndroid Build Coastguard Workerbad:
568*9880d681SAndroid Build Coastguard Worker  %Y2 = getelementptr i32, i32* %X, i64 1
569*9880d681SAndroid Build Coastguard Worker  store i32 0, i32* %Y2
570*9880d681SAndroid Build Coastguard Worker  %Z2 = load i32, i32* %Y2
571*9880d681SAndroid Build Coastguard Worker  ret i32 %Z2
572*9880d681SAndroid Build Coastguard Worker}
573*9880d681SAndroid Build Coastguard Worker
574*9880d681SAndroid Build Coastguard Workerdefine i8 @test12() {
575*9880d681SAndroid Build Coastguard Worker; We fully promote these to the i24 load or store size, resulting in just masks
576*9880d681SAndroid Build Coastguard Worker; and other operations that instcombine will fold, but no alloca.
577*9880d681SAndroid Build Coastguard Worker;
578*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test12(
579*9880d681SAndroid Build Coastguard Worker
580*9880d681SAndroid Build Coastguard Workerentry:
581*9880d681SAndroid Build Coastguard Worker  %a = alloca [3 x i8]
582*9880d681SAndroid Build Coastguard Worker  %b = alloca [3 x i8]
583*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
584*9880d681SAndroid Build Coastguard Worker
585*9880d681SAndroid Build Coastguard Worker  %a0ptr = getelementptr [3 x i8], [3 x i8]* %a, i64 0, i32 0
586*9880d681SAndroid Build Coastguard Worker  store i8 0, i8* %a0ptr
587*9880d681SAndroid Build Coastguard Worker  %a1ptr = getelementptr [3 x i8], [3 x i8]* %a, i64 0, i32 1
588*9880d681SAndroid Build Coastguard Worker  store i8 0, i8* %a1ptr
589*9880d681SAndroid Build Coastguard Worker  %a2ptr = getelementptr [3 x i8], [3 x i8]* %a, i64 0, i32 2
590*9880d681SAndroid Build Coastguard Worker  store i8 0, i8* %a2ptr
591*9880d681SAndroid Build Coastguard Worker  %aiptr = bitcast [3 x i8]* %a to i24*
592*9880d681SAndroid Build Coastguard Worker  %ai = load i24, i24* %aiptr
593*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: store
594*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: load
595*9880d681SAndroid Build Coastguard Worker; CHECK:      %[[ext2:.*]] = zext i8 0 to i24
596*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[shift2:.*]] = shl i24 %[[ext2]], 16
597*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[mask2:.*]] = and i24 undef, 65535
598*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[insert2:.*]] = or i24 %[[mask2]], %[[shift2]]
599*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[ext1:.*]] = zext i8 0 to i24
600*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[shift1:.*]] = shl i24 %[[ext1]], 8
601*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[mask1:.*]] = and i24 %[[insert2]], -65281
602*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[insert1:.*]] = or i24 %[[mask1]], %[[shift1]]
603*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[ext0:.*]] = zext i8 0 to i24
604*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[mask0:.*]] = and i24 %[[insert1]], -256
605*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[insert0:.*]] = or i24 %[[mask0]], %[[ext0]]
606*9880d681SAndroid Build Coastguard Worker
607*9880d681SAndroid Build Coastguard Worker  %biptr = bitcast [3 x i8]* %b to i24*
608*9880d681SAndroid Build Coastguard Worker  store i24 %ai, i24* %biptr
609*9880d681SAndroid Build Coastguard Worker  %b0ptr = getelementptr [3 x i8], [3 x i8]* %b, i64 0, i32 0
610*9880d681SAndroid Build Coastguard Worker  %b0 = load i8, i8* %b0ptr
611*9880d681SAndroid Build Coastguard Worker  %b1ptr = getelementptr [3 x i8], [3 x i8]* %b, i64 0, i32 1
612*9880d681SAndroid Build Coastguard Worker  %b1 = load i8, i8* %b1ptr
613*9880d681SAndroid Build Coastguard Worker  %b2ptr = getelementptr [3 x i8], [3 x i8]* %b, i64 0, i32 2
614*9880d681SAndroid Build Coastguard Worker  %b2 = load i8, i8* %b2ptr
615*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: store
616*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: load
617*9880d681SAndroid Build Coastguard Worker; CHECK:      %[[trunc0:.*]] = trunc i24 %[[insert0]] to i8
618*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[shift1:.*]] = lshr i24 %[[insert0]], 8
619*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[trunc1:.*]] = trunc i24 %[[shift1]] to i8
620*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[shift2:.*]] = lshr i24 %[[insert0]], 16
621*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[trunc2:.*]] = trunc i24 %[[shift2]] to i8
622*9880d681SAndroid Build Coastguard Worker
623*9880d681SAndroid Build Coastguard Worker  %bsum0 = add i8 %b0, %b1
624*9880d681SAndroid Build Coastguard Worker  %bsum1 = add i8 %bsum0, %b2
625*9880d681SAndroid Build Coastguard Worker  ret i8 %bsum1
626*9880d681SAndroid Build Coastguard Worker; CHECK:      %[[sum0:.*]] = add i8 %[[trunc0]], %[[trunc1]]
627*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[sum1:.*]] = add i8 %[[sum0]], %[[trunc2]]
628*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ret i8 %[[sum1]]
629*9880d681SAndroid Build Coastguard Worker}
630*9880d681SAndroid Build Coastguard Worker
631*9880d681SAndroid Build Coastguard Workerdefine i32 @test13() {
632*9880d681SAndroid Build Coastguard Worker; Ensure we don't crash and handle undefined loads that straddle the end of the
633*9880d681SAndroid Build Coastguard Worker; allocation.
634*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test13(
635*9880d681SAndroid Build Coastguard Worker; CHECK:      %[[value:.*]] = zext i8 0 to i16
636*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[ret:.*]] = zext i16 %[[value]] to i32
637*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ret i32 %[[ret]]
638*9880d681SAndroid Build Coastguard Worker
639*9880d681SAndroid Build Coastguard Workerentry:
640*9880d681SAndroid Build Coastguard Worker  %a = alloca [3 x i8], align 2
641*9880d681SAndroid Build Coastguard Worker  %b0ptr = getelementptr [3 x i8], [3 x i8]* %a, i64 0, i32 0
642*9880d681SAndroid Build Coastguard Worker  store i8 0, i8* %b0ptr
643*9880d681SAndroid Build Coastguard Worker  %b1ptr = getelementptr [3 x i8], [3 x i8]* %a, i64 0, i32 1
644*9880d681SAndroid Build Coastguard Worker  store i8 0, i8* %b1ptr
645*9880d681SAndroid Build Coastguard Worker  %b2ptr = getelementptr [3 x i8], [3 x i8]* %a, i64 0, i32 2
646*9880d681SAndroid Build Coastguard Worker  store i8 0, i8* %b2ptr
647*9880d681SAndroid Build Coastguard Worker  %iptrcast = bitcast [3 x i8]* %a to i16*
648*9880d681SAndroid Build Coastguard Worker  %iptrgep = getelementptr i16, i16* %iptrcast, i64 1
649*9880d681SAndroid Build Coastguard Worker  %i = load i16, i16* %iptrgep
650*9880d681SAndroid Build Coastguard Worker  %ret = zext i16 %i to i32
651*9880d681SAndroid Build Coastguard Worker  ret i32 %ret
652*9880d681SAndroid Build Coastguard Worker}
653*9880d681SAndroid Build Coastguard Worker
654*9880d681SAndroid Build Coastguard Worker%test14.struct = type { [3 x i32] }
655*9880d681SAndroid Build Coastguard Worker
656*9880d681SAndroid Build Coastguard Workerdefine void @test14(...) nounwind uwtable {
657*9880d681SAndroid Build Coastguard Worker; This is a strange case where we split allocas into promotable partitions, but
658*9880d681SAndroid Build Coastguard Worker; also gain enough data to prove they must be dead allocas due to GEPs that walk
659*9880d681SAndroid Build Coastguard Worker; across two adjacent allocas. Test that we don't try to promote or otherwise
660*9880d681SAndroid Build Coastguard Worker; do bad things to these dead allocas, they should just be removed.
661*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test14(
662*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: entry:
663*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ret void
664*9880d681SAndroid Build Coastguard Worker
665*9880d681SAndroid Build Coastguard Workerentry:
666*9880d681SAndroid Build Coastguard Worker  %a = alloca %test14.struct
667*9880d681SAndroid Build Coastguard Worker  %p = alloca %test14.struct*
668*9880d681SAndroid Build Coastguard Worker  %0 = bitcast %test14.struct* %a to i8*
669*9880d681SAndroid Build Coastguard Worker  %1 = getelementptr i8, i8* %0, i64 12
670*9880d681SAndroid Build Coastguard Worker  %2 = bitcast i8* %1 to %test14.struct*
671*9880d681SAndroid Build Coastguard Worker  %3 = getelementptr inbounds %test14.struct, %test14.struct* %2, i32 0, i32 0
672*9880d681SAndroid Build Coastguard Worker  %4 = getelementptr inbounds %test14.struct, %test14.struct* %a, i32 0, i32 0
673*9880d681SAndroid Build Coastguard Worker  %5 = bitcast [3 x i32]* %3 to i32*
674*9880d681SAndroid Build Coastguard Worker  %6 = bitcast [3 x i32]* %4 to i32*
675*9880d681SAndroid Build Coastguard Worker  %7 = load i32, i32* %6, align 4
676*9880d681SAndroid Build Coastguard Worker  store i32 %7, i32* %5, align 4
677*9880d681SAndroid Build Coastguard Worker  %8 = getelementptr inbounds i32, i32* %5, i32 1
678*9880d681SAndroid Build Coastguard Worker  %9 = getelementptr inbounds i32, i32* %6, i32 1
679*9880d681SAndroid Build Coastguard Worker  %10 = load i32, i32* %9, align 4
680*9880d681SAndroid Build Coastguard Worker  store i32 %10, i32* %8, align 4
681*9880d681SAndroid Build Coastguard Worker  %11 = getelementptr inbounds i32, i32* %5, i32 2
682*9880d681SAndroid Build Coastguard Worker  %12 = getelementptr inbounds i32, i32* %6, i32 2
683*9880d681SAndroid Build Coastguard Worker  %13 = load i32, i32* %12, align 4
684*9880d681SAndroid Build Coastguard Worker  store i32 %13, i32* %11, align 4
685*9880d681SAndroid Build Coastguard Worker  ret void
686*9880d681SAndroid Build Coastguard Worker}
687*9880d681SAndroid Build Coastguard Worker
688*9880d681SAndroid Build Coastguard Workerdefine i32 @test15(i1 %flag) nounwind uwtable {
689*9880d681SAndroid Build Coastguard Worker; Ensure that when there are dead instructions using an alloca that are not
690*9880d681SAndroid Build Coastguard Worker; loads or stores we still delete them during partitioning and rewriting.
691*9880d681SAndroid Build Coastguard Worker; Otherwise we'll go to promote them while thy still have unpromotable uses.
692*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test15(
693*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: entry:
694*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   br label %loop
695*9880d681SAndroid Build Coastguard Worker; CHECK:      loop:
696*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   br label %loop
697*9880d681SAndroid Build Coastguard Worker
698*9880d681SAndroid Build Coastguard Workerentry:
699*9880d681SAndroid Build Coastguard Worker  %l0 = alloca i64
700*9880d681SAndroid Build Coastguard Worker  %l1 = alloca i64
701*9880d681SAndroid Build Coastguard Worker  %l2 = alloca i64
702*9880d681SAndroid Build Coastguard Worker  %l3 = alloca i64
703*9880d681SAndroid Build Coastguard Worker  br label %loop
704*9880d681SAndroid Build Coastguard Worker
705*9880d681SAndroid Build Coastguard Workerloop:
706*9880d681SAndroid Build Coastguard Worker  %dead3 = phi i8* [ %gep3, %loop ], [ null, %entry ]
707*9880d681SAndroid Build Coastguard Worker
708*9880d681SAndroid Build Coastguard Worker  store i64 1879048192, i64* %l0, align 8
709*9880d681SAndroid Build Coastguard Worker  %bc0 = bitcast i64* %l0 to i8*
710*9880d681SAndroid Build Coastguard Worker  %gep0 = getelementptr i8, i8* %bc0, i64 3
711*9880d681SAndroid Build Coastguard Worker  %dead0 = bitcast i8* %gep0 to i64*
712*9880d681SAndroid Build Coastguard Worker
713*9880d681SAndroid Build Coastguard Worker  store i64 1879048192, i64* %l1, align 8
714*9880d681SAndroid Build Coastguard Worker  %bc1 = bitcast i64* %l1 to i8*
715*9880d681SAndroid Build Coastguard Worker  %gep1 = getelementptr i8, i8* %bc1, i64 3
716*9880d681SAndroid Build Coastguard Worker  %dead1 = getelementptr i8, i8* %gep1, i64 1
717*9880d681SAndroid Build Coastguard Worker
718*9880d681SAndroid Build Coastguard Worker  store i64 1879048192, i64* %l2, align 8
719*9880d681SAndroid Build Coastguard Worker  %bc2 = bitcast i64* %l2 to i8*
720*9880d681SAndroid Build Coastguard Worker  %gep2.1 = getelementptr i8, i8* %bc2, i64 1
721*9880d681SAndroid Build Coastguard Worker  %gep2.2 = getelementptr i8, i8* %bc2, i64 3
722*9880d681SAndroid Build Coastguard Worker  ; Note that this select should get visited multiple times due to using two
723*9880d681SAndroid Build Coastguard Worker  ; different GEPs off the same alloca. We should only delete it once.
724*9880d681SAndroid Build Coastguard Worker  %dead2 = select i1 %flag, i8* %gep2.1, i8* %gep2.2
725*9880d681SAndroid Build Coastguard Worker
726*9880d681SAndroid Build Coastguard Worker  store i64 1879048192, i64* %l3, align 8
727*9880d681SAndroid Build Coastguard Worker  %bc3 = bitcast i64* %l3 to i8*
728*9880d681SAndroid Build Coastguard Worker  %gep3 = getelementptr i8, i8* %bc3, i64 3
729*9880d681SAndroid Build Coastguard Worker
730*9880d681SAndroid Build Coastguard Worker  br label %loop
731*9880d681SAndroid Build Coastguard Worker}
732*9880d681SAndroid Build Coastguard Worker
733*9880d681SAndroid Build Coastguard Workerdefine void @test16(i8* %src, i8* %dst) {
734*9880d681SAndroid Build Coastguard Worker; Ensure that we can promote an alloca of [3 x i8] to an i24 SSA value.
735*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test16(
736*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
737*9880d681SAndroid Build Coastguard Worker; CHECK:      %[[srccast:.*]] = bitcast i8* %src to i24*
738*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: load i24, i24* %[[srccast]]
739*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[dstcast:.*]] = bitcast i8* %dst to i24*
740*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i24 0, i24* %[[dstcast]]
741*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ret void
742*9880d681SAndroid Build Coastguard Worker
743*9880d681SAndroid Build Coastguard Workerentry:
744*9880d681SAndroid Build Coastguard Worker  %a = alloca [3 x i8]
745*9880d681SAndroid Build Coastguard Worker  %ptr = getelementptr [3 x i8], [3 x i8]* %a, i32 0, i32 0
746*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %ptr, i8* %src, i32 4, i32 1, i1 false)
747*9880d681SAndroid Build Coastguard Worker  %cast = bitcast i8* %ptr to i24*
748*9880d681SAndroid Build Coastguard Worker  store i24 0, i24* %cast
749*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %ptr, i32 4, i32 1, i1 false)
750*9880d681SAndroid Build Coastguard Worker  ret void
751*9880d681SAndroid Build Coastguard Worker}
752*9880d681SAndroid Build Coastguard Worker
753*9880d681SAndroid Build Coastguard Workerdefine void @test17(i8* %src, i8* %dst) {
754*9880d681SAndroid Build Coastguard Worker; Ensure that we can rewrite unpromotable memcpys which extend past the end of
755*9880d681SAndroid Build Coastguard Worker; the alloca.
756*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test17(
757*9880d681SAndroid Build Coastguard Worker; CHECK:      %[[a:.*]] = alloca [3 x i8]
758*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[ptr:.*]] = getelementptr [3 x i8], [3 x i8]* %[[a]], i32 0, i32 0
759*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[ptr]], i8* %src,
760*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %[[ptr]],
761*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ret void
762*9880d681SAndroid Build Coastguard Worker
763*9880d681SAndroid Build Coastguard Workerentry:
764*9880d681SAndroid Build Coastguard Worker  %a = alloca [3 x i8]
765*9880d681SAndroid Build Coastguard Worker  %ptr = getelementptr [3 x i8], [3 x i8]* %a, i32 0, i32 0
766*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %ptr, i8* %src, i32 4, i32 1, i1 true)
767*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %ptr, i32 4, i32 1, i1 true)
768*9880d681SAndroid Build Coastguard Worker  ret void
769*9880d681SAndroid Build Coastguard Worker}
770*9880d681SAndroid Build Coastguard Worker
771*9880d681SAndroid Build Coastguard Workerdefine void @test18(i8* %src, i8* %dst, i32 %size) {
772*9880d681SAndroid Build Coastguard Worker; Preserve transfer instrinsics with a variable size, even if they overlap with
773*9880d681SAndroid Build Coastguard Worker; fixed size operations. Further, continue to split and promote allocas preceding
774*9880d681SAndroid Build Coastguard Worker; the variable sized intrinsic.
775*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test18(
776*9880d681SAndroid Build Coastguard Worker; CHECK:      %[[a:.*]] = alloca [34 x i8]
777*9880d681SAndroid Build Coastguard Worker; CHECK:      %[[srcgep1:.*]] = getelementptr inbounds i8, i8* %src, i64 4
778*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[srccast1:.*]] = bitcast i8* %[[srcgep1]] to i32*
779*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[srcload:.*]] = load i32, i32* %[[srccast1]]
780*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[agep1:.*]] = getelementptr inbounds [34 x i8], [34 x i8]* %[[a]], i64 0, i64 0
781*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[agep1]], i8* %src, i32 %size,
782*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[agep2:.*]] = getelementptr inbounds [34 x i8], [34 x i8]* %[[a]], i64 0, i64 0
783*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memset.p0i8.i32(i8* %[[agep2]], i8 42, i32 %size,
784*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[dstcast1:.*]] = bitcast i8* %dst to i32*
785*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i32 42, i32* %[[dstcast1]]
786*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[dstgep1:.*]] = getelementptr inbounds i8, i8* %dst, i64 4
787*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[dstcast2:.*]] = bitcast i8* %[[dstgep1]] to i32*
788*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i32 %[[srcload]], i32* %[[dstcast2]]
789*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[agep3:.*]] = getelementptr inbounds [34 x i8], [34 x i8]* %[[a]], i64 0, i64 0
790*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %[[agep3]], i32 %size,
791*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ret void
792*9880d681SAndroid Build Coastguard Worker
793*9880d681SAndroid Build Coastguard Workerentry:
794*9880d681SAndroid Build Coastguard Worker  %a = alloca [42 x i8]
795*9880d681SAndroid Build Coastguard Worker  %ptr = getelementptr [42 x i8], [42 x i8]* %a, i32 0, i32 0
796*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %ptr, i8* %src, i32 8, i32 1, i1 false)
797*9880d681SAndroid Build Coastguard Worker  %ptr2 = getelementptr [42 x i8], [42 x i8]* %a, i32 0, i32 8
798*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %ptr2, i8* %src, i32 %size, i32 1, i1 false)
799*9880d681SAndroid Build Coastguard Worker  call void @llvm.memset.p0i8.i32(i8* %ptr2, i8 42, i32 %size, i32 1, i1 false)
800*9880d681SAndroid Build Coastguard Worker  %cast = bitcast i8* %ptr to i32*
801*9880d681SAndroid Build Coastguard Worker  store i32 42, i32* %cast
802*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %ptr, i32 8, i32 1, i1 false)
803*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %ptr2, i32 %size, i32 1, i1 false)
804*9880d681SAndroid Build Coastguard Worker  ret void
805*9880d681SAndroid Build Coastguard Worker}
806*9880d681SAndroid Build Coastguard Worker
807*9880d681SAndroid Build Coastguard Worker%opaque = type opaque
808*9880d681SAndroid Build Coastguard Worker
809*9880d681SAndroid Build Coastguard Workerdefine i32 @test19(%opaque* %x) {
810*9880d681SAndroid Build Coastguard Worker; This input will cause us to try to compute a natural GEP when rewriting
811*9880d681SAndroid Build Coastguard Worker; pointers in such a way that we try to GEP through the opaque type. Previously,
812*9880d681SAndroid Build Coastguard Worker; a check for an unsized type was missing and this crashed. Ensure it behaves
813*9880d681SAndroid Build Coastguard Worker; reasonably now.
814*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test19(
815*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
816*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32 undef
817*9880d681SAndroid Build Coastguard Worker
818*9880d681SAndroid Build Coastguard Workerentry:
819*9880d681SAndroid Build Coastguard Worker  %a = alloca { i64, i8* }
820*9880d681SAndroid Build Coastguard Worker  %cast1 = bitcast %opaque* %x to i8*
821*9880d681SAndroid Build Coastguard Worker  %cast2 = bitcast { i64, i8* }* %a to i8*
822*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %cast2, i8* %cast1, i32 16, i32 1, i1 false)
823*9880d681SAndroid Build Coastguard Worker  %gep = getelementptr inbounds { i64, i8* }, { i64, i8* }* %a, i32 0, i32 0
824*9880d681SAndroid Build Coastguard Worker  %val = load i64, i64* %gep
825*9880d681SAndroid Build Coastguard Worker  ret i32 undef
826*9880d681SAndroid Build Coastguard Worker}
827*9880d681SAndroid Build Coastguard Worker
828*9880d681SAndroid Build Coastguard Workerdefine i32 @test20() {
829*9880d681SAndroid Build Coastguard Worker; Ensure we can track negative offsets (before the beginning of the alloca) and
830*9880d681SAndroid Build Coastguard Worker; negative relative offsets from offsets starting past the end of the alloca.
831*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test20(
832*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
833*9880d681SAndroid Build Coastguard Worker; CHECK: %[[sum1:.*]] = add i32 1, 2
834*9880d681SAndroid Build Coastguard Worker; CHECK: %[[sum2:.*]] = add i32 %[[sum1]], 3
835*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32 %[[sum2]]
836*9880d681SAndroid Build Coastguard Worker
837*9880d681SAndroid Build Coastguard Workerentry:
838*9880d681SAndroid Build Coastguard Worker  %a = alloca [3 x i32]
839*9880d681SAndroid Build Coastguard Worker  %gep1 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0
840*9880d681SAndroid Build Coastguard Worker  store i32 1, i32* %gep1
841*9880d681SAndroid Build Coastguard Worker  %gep2.1 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 -2
842*9880d681SAndroid Build Coastguard Worker  %gep2.2 = getelementptr i32, i32* %gep2.1, i32 3
843*9880d681SAndroid Build Coastguard Worker  store i32 2, i32* %gep2.2
844*9880d681SAndroid Build Coastguard Worker  %gep3.1 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 14
845*9880d681SAndroid Build Coastguard Worker  %gep3.2 = getelementptr i32, i32* %gep3.1, i32 -12
846*9880d681SAndroid Build Coastguard Worker  store i32 3, i32* %gep3.2
847*9880d681SAndroid Build Coastguard Worker
848*9880d681SAndroid Build Coastguard Worker  %load1 = load i32, i32* %gep1
849*9880d681SAndroid Build Coastguard Worker  %load2 = load i32, i32* %gep2.2
850*9880d681SAndroid Build Coastguard Worker  %load3 = load i32, i32* %gep3.2
851*9880d681SAndroid Build Coastguard Worker  %sum1 = add i32 %load1, %load2
852*9880d681SAndroid Build Coastguard Worker  %sum2 = add i32 %sum1, %load3
853*9880d681SAndroid Build Coastguard Worker  ret i32 %sum2
854*9880d681SAndroid Build Coastguard Worker}
855*9880d681SAndroid Build Coastguard Worker
856*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
857*9880d681SAndroid Build Coastguard Worker
858*9880d681SAndroid Build Coastguard Workerdefine i8 @test21() {
859*9880d681SAndroid Build Coastguard Worker; Test allocations and offsets which border on overflow of the int64_t used
860*9880d681SAndroid Build Coastguard Worker; internally. This is really awkward to really test as LLVM doesn't really
861*9880d681SAndroid Build Coastguard Worker; support such extreme constructs cleanly.
862*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test21(
863*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
864*9880d681SAndroid Build Coastguard Worker; CHECK: or i8 -1, -1
865*9880d681SAndroid Build Coastguard Worker
866*9880d681SAndroid Build Coastguard Workerentry:
867*9880d681SAndroid Build Coastguard Worker  %a = alloca [2305843009213693951 x i8]
868*9880d681SAndroid Build Coastguard Worker  %gep0 = getelementptr [2305843009213693951 x i8], [2305843009213693951 x i8]* %a, i64 0, i64 2305843009213693949
869*9880d681SAndroid Build Coastguard Worker  store i8 255, i8* %gep0
870*9880d681SAndroid Build Coastguard Worker  %gep1 = getelementptr [2305843009213693951 x i8], [2305843009213693951 x i8]* %a, i64 0, i64 -9223372036854775807
871*9880d681SAndroid Build Coastguard Worker  %gep2 = getelementptr i8, i8* %gep1, i64 -1
872*9880d681SAndroid Build Coastguard Worker  call void @llvm.memset.p0i8.i64(i8* %gep2, i8 0, i64 18446744073709551615, i32 1, i1 false)
873*9880d681SAndroid Build Coastguard Worker  %gep3 = getelementptr i8, i8* %gep1, i64 9223372036854775807
874*9880d681SAndroid Build Coastguard Worker  %gep4 = getelementptr i8, i8* %gep3, i64 9223372036854775807
875*9880d681SAndroid Build Coastguard Worker  %gep5 = getelementptr i8, i8* %gep4, i64 -6917529027641081857
876*9880d681SAndroid Build Coastguard Worker  store i8 255, i8* %gep5
877*9880d681SAndroid Build Coastguard Worker  %cast1 = bitcast i8* %gep4 to i32*
878*9880d681SAndroid Build Coastguard Worker  store i32 0, i32* %cast1
879*9880d681SAndroid Build Coastguard Worker  %load = load i8, i8* %gep0
880*9880d681SAndroid Build Coastguard Worker  %gep6 = getelementptr i8, i8* %gep0, i32 1
881*9880d681SAndroid Build Coastguard Worker  %load2 = load i8, i8* %gep6
882*9880d681SAndroid Build Coastguard Worker  %result = or i8 %load, %load2
883*9880d681SAndroid Build Coastguard Worker  ret i8 %result
884*9880d681SAndroid Build Coastguard Worker}
885*9880d681SAndroid Build Coastguard Worker
886*9880d681SAndroid Build Coastguard Worker%PR13916.struct = type { i8 }
887*9880d681SAndroid Build Coastguard Worker
888*9880d681SAndroid Build Coastguard Workerdefine void @PR13916.1() {
889*9880d681SAndroid Build Coastguard Worker; Ensure that we handle overlapping memcpy intrinsics correctly, especially in
890*9880d681SAndroid Build Coastguard Worker; the case where there is a directly identical value for both source and dest.
891*9880d681SAndroid Build Coastguard Worker; CHECK: @PR13916.1
892*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
893*9880d681SAndroid Build Coastguard Worker; CHECK: ret void
894*9880d681SAndroid Build Coastguard Worker
895*9880d681SAndroid Build Coastguard Workerentry:
896*9880d681SAndroid Build Coastguard Worker  %a = alloca i8
897*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %a, i8* %a, i32 1, i32 1, i1 false)
898*9880d681SAndroid Build Coastguard Worker  %tmp2 = load i8, i8* %a
899*9880d681SAndroid Build Coastguard Worker  ret void
900*9880d681SAndroid Build Coastguard Worker}
901*9880d681SAndroid Build Coastguard Worker
902*9880d681SAndroid Build Coastguard Workerdefine void @PR13916.2() {
903*9880d681SAndroid Build Coastguard Worker; Check whether we continue to handle them correctly when they start off with
904*9880d681SAndroid Build Coastguard Worker; different pointer value chains, but during rewriting we coalesce them into the
905*9880d681SAndroid Build Coastguard Worker; same value.
906*9880d681SAndroid Build Coastguard Worker; CHECK: @PR13916.2
907*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
908*9880d681SAndroid Build Coastguard Worker; CHECK: ret void
909*9880d681SAndroid Build Coastguard Worker
910*9880d681SAndroid Build Coastguard Workerentry:
911*9880d681SAndroid Build Coastguard Worker  %a = alloca %PR13916.struct, align 1
912*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %if.then, label %if.end
913*9880d681SAndroid Build Coastguard Worker
914*9880d681SAndroid Build Coastguard Workerif.then:
915*9880d681SAndroid Build Coastguard Worker  %tmp0 = bitcast %PR13916.struct* %a to i8*
916*9880d681SAndroid Build Coastguard Worker  %tmp1 = bitcast %PR13916.struct* %a to i8*
917*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %tmp0, i8* %tmp1, i32 1, i32 1, i1 false)
918*9880d681SAndroid Build Coastguard Worker  br label %if.end
919*9880d681SAndroid Build Coastguard Worker
920*9880d681SAndroid Build Coastguard Workerif.end:
921*9880d681SAndroid Build Coastguard Worker  %gep = getelementptr %PR13916.struct, %PR13916.struct* %a, i32 0, i32 0
922*9880d681SAndroid Build Coastguard Worker  %tmp2 = load i8, i8* %gep
923*9880d681SAndroid Build Coastguard Worker  ret void
924*9880d681SAndroid Build Coastguard Worker}
925*9880d681SAndroid Build Coastguard Worker
926*9880d681SAndroid Build Coastguard Workerdefine void @PR13990() {
927*9880d681SAndroid Build Coastguard Worker; Ensure we can handle cases where processing one alloca causes the other
928*9880d681SAndroid Build Coastguard Worker; alloca to become dead and get deleted. This might crash or fail under
929*9880d681SAndroid Build Coastguard Worker; Valgrind if we regress.
930*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @PR13990(
931*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
932*9880d681SAndroid Build Coastguard Worker; CHECK: unreachable
933*9880d681SAndroid Build Coastguard Worker; CHECK: unreachable
934*9880d681SAndroid Build Coastguard Worker
935*9880d681SAndroid Build Coastguard Workerentry:
936*9880d681SAndroid Build Coastguard Worker  %tmp1 = alloca i8*
937*9880d681SAndroid Build Coastguard Worker  %tmp2 = alloca i8*
938*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %bb1, label %bb2
939*9880d681SAndroid Build Coastguard Worker
940*9880d681SAndroid Build Coastguard Workerbb1:
941*9880d681SAndroid Build Coastguard Worker  store i8* undef, i8** %tmp2
942*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %bb2, label %bb3
943*9880d681SAndroid Build Coastguard Worker
944*9880d681SAndroid Build Coastguard Workerbb2:
945*9880d681SAndroid Build Coastguard Worker  %tmp50 = select i1 undef, i8** %tmp2, i8** %tmp1
946*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %bb3, label %bb4
947*9880d681SAndroid Build Coastguard Worker
948*9880d681SAndroid Build Coastguard Workerbb3:
949*9880d681SAndroid Build Coastguard Worker  unreachable
950*9880d681SAndroid Build Coastguard Worker
951*9880d681SAndroid Build Coastguard Workerbb4:
952*9880d681SAndroid Build Coastguard Worker  unreachable
953*9880d681SAndroid Build Coastguard Worker}
954*9880d681SAndroid Build Coastguard Worker
955*9880d681SAndroid Build Coastguard Workerdefine double @PR13969(double %x) {
956*9880d681SAndroid Build Coastguard Worker; Check that we detect when promotion will un-escape an alloca and iterate to
957*9880d681SAndroid Build Coastguard Worker; re-try running SROA over that alloca. Without that, the two allocas that are
958*9880d681SAndroid Build Coastguard Worker; stored into a dead alloca don't get rewritten and promoted.
959*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @PR13969(
960*9880d681SAndroid Build Coastguard Worker
961*9880d681SAndroid Build Coastguard Workerentry:
962*9880d681SAndroid Build Coastguard Worker  %a = alloca double
963*9880d681SAndroid Build Coastguard Worker  %b = alloca double*
964*9880d681SAndroid Build Coastguard Worker  %c = alloca double
965*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
966*9880d681SAndroid Build Coastguard Worker
967*9880d681SAndroid Build Coastguard Worker  store double %x, double* %a
968*9880d681SAndroid Build Coastguard Worker  store double* %c, double** %b
969*9880d681SAndroid Build Coastguard Worker  store double* %a, double** %b
970*9880d681SAndroid Build Coastguard Worker  store double %x, double* %c
971*9880d681SAndroid Build Coastguard Worker  %ret = load double, double* %a
972*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: store
973*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: load
974*9880d681SAndroid Build Coastguard Worker
975*9880d681SAndroid Build Coastguard Worker  ret double %ret
976*9880d681SAndroid Build Coastguard Worker; CHECK: ret double %x
977*9880d681SAndroid Build Coastguard Worker}
978*9880d681SAndroid Build Coastguard Worker
979*9880d681SAndroid Build Coastguard Worker%PR14034.struct = type { { {} }, i32, %PR14034.list }
980*9880d681SAndroid Build Coastguard Worker%PR14034.list = type { %PR14034.list*, %PR14034.list* }
981*9880d681SAndroid Build Coastguard Worker
982*9880d681SAndroid Build Coastguard Workerdefine void @PR14034() {
983*9880d681SAndroid Build Coastguard Worker; This test case tries to form GEPs into the empty leading struct members, and
984*9880d681SAndroid Build Coastguard Worker; subsequently crashed (under valgrind) before we fixed the PR. The important
985*9880d681SAndroid Build Coastguard Worker; thing is to handle empty structs gracefully.
986*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @PR14034(
987*9880d681SAndroid Build Coastguard Worker
988*9880d681SAndroid Build Coastguard Workerentry:
989*9880d681SAndroid Build Coastguard Worker  %a = alloca %PR14034.struct
990*9880d681SAndroid Build Coastguard Worker  %list = getelementptr %PR14034.struct, %PR14034.struct* %a, i32 0, i32 2
991*9880d681SAndroid Build Coastguard Worker  %prev = getelementptr %PR14034.list, %PR14034.list* %list, i32 0, i32 1
992*9880d681SAndroid Build Coastguard Worker  store %PR14034.list* undef, %PR14034.list** %prev
993*9880d681SAndroid Build Coastguard Worker  %cast0 = bitcast %PR14034.struct* undef to i8*
994*9880d681SAndroid Build Coastguard Worker  %cast1 = bitcast %PR14034.struct* %a to i8*
995*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %cast0, i8* %cast1, i32 12, i32 0, i1 false)
996*9880d681SAndroid Build Coastguard Worker  ret void
997*9880d681SAndroid Build Coastguard Worker}
998*9880d681SAndroid Build Coastguard Worker
999*9880d681SAndroid Build Coastguard Workerdefine i32 @test22(i32 %x) {
1000*9880d681SAndroid Build Coastguard Worker; Test that SROA and promotion is not confused by a grab bax mixture of pointer
1001*9880d681SAndroid Build Coastguard Worker; types involving wrapper aggregates and zero-length aggregate members.
1002*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test22(
1003*9880d681SAndroid Build Coastguard Worker
1004*9880d681SAndroid Build Coastguard Workerentry:
1005*9880d681SAndroid Build Coastguard Worker  %a1 = alloca { { [1 x { i32 }] } }
1006*9880d681SAndroid Build Coastguard Worker  %a2 = alloca { {}, { float }, [0 x i8] }
1007*9880d681SAndroid Build Coastguard Worker  %a3 = alloca { [0 x i8], { [0 x double], [1 x [1 x <4 x i8>]], {} }, { { {} } } }
1008*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
1009*9880d681SAndroid Build Coastguard Worker
1010*9880d681SAndroid Build Coastguard Worker  %wrap1 = insertvalue [1 x { i32 }] undef, i32 %x, 0, 0
1011*9880d681SAndroid Build Coastguard Worker  %gep1 = getelementptr { { [1 x { i32 }] } }, { { [1 x { i32 }] } }* %a1, i32 0, i32 0, i32 0
1012*9880d681SAndroid Build Coastguard Worker  store [1 x { i32 }] %wrap1, [1 x { i32 }]* %gep1
1013*9880d681SAndroid Build Coastguard Worker
1014*9880d681SAndroid Build Coastguard Worker  %gep2 = getelementptr { { [1 x { i32 }] } }, { { [1 x { i32 }] } }* %a1, i32 0, i32 0
1015*9880d681SAndroid Build Coastguard Worker  %ptrcast1 = bitcast { [1 x { i32 }] }* %gep2 to { [1 x { float }] }*
1016*9880d681SAndroid Build Coastguard Worker  %load1 = load { [1 x { float }] }, { [1 x { float }] }* %ptrcast1
1017*9880d681SAndroid Build Coastguard Worker  %unwrap1 = extractvalue { [1 x { float }] } %load1, 0, 0
1018*9880d681SAndroid Build Coastguard Worker
1019*9880d681SAndroid Build Coastguard Worker  %wrap2 = insertvalue { {}, { float }, [0 x i8] } undef, { float } %unwrap1, 1
1020*9880d681SAndroid Build Coastguard Worker  store { {}, { float }, [0 x i8] } %wrap2, { {}, { float }, [0 x i8] }* %a2
1021*9880d681SAndroid Build Coastguard Worker
1022*9880d681SAndroid Build Coastguard Worker  %gep3 = getelementptr { {}, { float }, [0 x i8] }, { {}, { float }, [0 x i8] }* %a2, i32 0, i32 1, i32 0
1023*9880d681SAndroid Build Coastguard Worker  %ptrcast2 = bitcast float* %gep3 to <4 x i8>*
1024*9880d681SAndroid Build Coastguard Worker  %load3 = load <4 x i8>, <4 x i8>* %ptrcast2
1025*9880d681SAndroid Build Coastguard Worker  %valcast1 = bitcast <4 x i8> %load3 to i32
1026*9880d681SAndroid Build Coastguard Worker
1027*9880d681SAndroid Build Coastguard Worker  %wrap3 = insertvalue [1 x [1 x i32]] undef, i32 %valcast1, 0, 0
1028*9880d681SAndroid Build Coastguard Worker  %wrap4 = insertvalue { [1 x [1 x i32]], {} } undef, [1 x [1 x i32]] %wrap3, 0
1029*9880d681SAndroid Build Coastguard Worker  %gep4 = getelementptr { [0 x i8], { [0 x double], [1 x [1 x <4 x i8>]], {} }, { { {} } } }, { [0 x i8], { [0 x double], [1 x [1 x <4 x i8>]], {} }, { { {} } } }* %a3, i32 0, i32 1
1030*9880d681SAndroid Build Coastguard Worker  %ptrcast3 = bitcast { [0 x double], [1 x [1 x <4 x i8>]], {} }* %gep4 to { [1 x [1 x i32]], {} }*
1031*9880d681SAndroid Build Coastguard Worker  store { [1 x [1 x i32]], {} } %wrap4, { [1 x [1 x i32]], {} }* %ptrcast3
1032*9880d681SAndroid Build Coastguard Worker
1033*9880d681SAndroid Build Coastguard Worker  %gep5 = getelementptr { [0 x i8], { [0 x double], [1 x [1 x <4 x i8>]], {} }, { { {} } } }, { [0 x i8], { [0 x double], [1 x [1 x <4 x i8>]], {} }, { { {} } } }* %a3, i32 0, i32 1, i32 1, i32 0
1034*9880d681SAndroid Build Coastguard Worker  %ptrcast4 = bitcast [1 x <4 x i8>]* %gep5 to { {}, float, {} }*
1035*9880d681SAndroid Build Coastguard Worker  %load4 = load { {}, float, {} }, { {}, float, {} }* %ptrcast4
1036*9880d681SAndroid Build Coastguard Worker  %unwrap2 = extractvalue { {}, float, {} } %load4, 1
1037*9880d681SAndroid Build Coastguard Worker  %valcast2 = bitcast float %unwrap2 to i32
1038*9880d681SAndroid Build Coastguard Worker
1039*9880d681SAndroid Build Coastguard Worker  ret i32 %valcast2
1040*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32
1041*9880d681SAndroid Build Coastguard Worker}
1042*9880d681SAndroid Build Coastguard Worker
1043*9880d681SAndroid Build Coastguard Workerdefine void @PR14059.1(double* %d) {
1044*9880d681SAndroid Build Coastguard Worker; In PR14059 a peculiar construct was identified as something that is used
1045*9880d681SAndroid Build Coastguard Worker; pervasively in ARM's ABI-calling-convention lowering: the passing of a struct
1046*9880d681SAndroid Build Coastguard Worker; of doubles via an array of i32 in order to place the data into integer
1047*9880d681SAndroid Build Coastguard Worker; registers. This in turn was missed as an optimization by SROA due to the
1048*9880d681SAndroid Build Coastguard Worker; partial loads and stores of integers to the double alloca we were trying to
1049*9880d681SAndroid Build Coastguard Worker; form and promote. The solution is to widen the integer operations to be
1050*9880d681SAndroid Build Coastguard Worker; whole-alloca operations, and perform the appropriate bitcasting on the
1051*9880d681SAndroid Build Coastguard Worker; *values* rather than the pointers. When this works, partial reads and writes
1052*9880d681SAndroid Build Coastguard Worker; via integers can be promoted away.
1053*9880d681SAndroid Build Coastguard Worker; CHECK: @PR14059.1
1054*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
1055*9880d681SAndroid Build Coastguard Worker; CHECK: ret void
1056*9880d681SAndroid Build Coastguard Worker
1057*9880d681SAndroid Build Coastguard Workerentry:
1058*9880d681SAndroid Build Coastguard Worker  %X.sroa.0.i = alloca double, align 8
1059*9880d681SAndroid Build Coastguard Worker  %0 = bitcast double* %X.sroa.0.i to i8*
1060*9880d681SAndroid Build Coastguard Worker  call void @llvm.lifetime.start(i64 -1, i8* %0)
1061*9880d681SAndroid Build Coastguard Worker
1062*9880d681SAndroid Build Coastguard Worker  ; Store to the low 32-bits...
1063*9880d681SAndroid Build Coastguard Worker  %X.sroa.0.0.cast2.i = bitcast double* %X.sroa.0.i to i32*
1064*9880d681SAndroid Build Coastguard Worker  store i32 0, i32* %X.sroa.0.0.cast2.i, align 8
1065*9880d681SAndroid Build Coastguard Worker
1066*9880d681SAndroid Build Coastguard Worker  ; Also use a memset to the middle 32-bits for fun.
1067*9880d681SAndroid Build Coastguard Worker  %X.sroa.0.2.raw_idx2.i = getelementptr inbounds i8, i8* %0, i32 2
1068*9880d681SAndroid Build Coastguard Worker  call void @llvm.memset.p0i8.i64(i8* %X.sroa.0.2.raw_idx2.i, i8 0, i64 4, i32 1, i1 false)
1069*9880d681SAndroid Build Coastguard Worker
1070*9880d681SAndroid Build Coastguard Worker  ; Or a memset of the whole thing.
1071*9880d681SAndroid Build Coastguard Worker  call void @llvm.memset.p0i8.i64(i8* %0, i8 0, i64 8, i32 1, i1 false)
1072*9880d681SAndroid Build Coastguard Worker
1073*9880d681SAndroid Build Coastguard Worker  ; Write to the high 32-bits with a memcpy.
1074*9880d681SAndroid Build Coastguard Worker  %X.sroa.0.4.raw_idx4.i = getelementptr inbounds i8, i8* %0, i32 4
1075*9880d681SAndroid Build Coastguard Worker  %d.raw = bitcast double* %d to i8*
1076*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %X.sroa.0.4.raw_idx4.i, i8* %d.raw, i32 4, i32 1, i1 false)
1077*9880d681SAndroid Build Coastguard Worker
1078*9880d681SAndroid Build Coastguard Worker  ; Store to the high 32-bits...
1079*9880d681SAndroid Build Coastguard Worker  %X.sroa.0.4.cast5.i = bitcast i8* %X.sroa.0.4.raw_idx4.i to i32*
1080*9880d681SAndroid Build Coastguard Worker  store i32 1072693248, i32* %X.sroa.0.4.cast5.i, align 4
1081*9880d681SAndroid Build Coastguard Worker
1082*9880d681SAndroid Build Coastguard Worker  ; Do the actual math...
1083*9880d681SAndroid Build Coastguard Worker  %X.sroa.0.0.load1.i = load double, double* %X.sroa.0.i, align 8
1084*9880d681SAndroid Build Coastguard Worker  %accum.real.i = load double, double* %d, align 8
1085*9880d681SAndroid Build Coastguard Worker  %add.r.i = fadd double %accum.real.i, %X.sroa.0.0.load1.i
1086*9880d681SAndroid Build Coastguard Worker  store double %add.r.i, double* %d, align 8
1087*9880d681SAndroid Build Coastguard Worker  call void @llvm.lifetime.end(i64 -1, i8* %0)
1088*9880d681SAndroid Build Coastguard Worker  ret void
1089*9880d681SAndroid Build Coastguard Worker}
1090*9880d681SAndroid Build Coastguard Worker
1091*9880d681SAndroid Build Coastguard Workerdefine i64 @PR14059.2({ float, float }* %phi) {
1092*9880d681SAndroid Build Coastguard Worker; Check that SROA can split up alloca-wide integer loads and stores where the
1093*9880d681SAndroid Build Coastguard Worker; underlying alloca has smaller components that are accessed independently. This
1094*9880d681SAndroid Build Coastguard Worker; shows up particularly with ABI lowering patterns coming out of Clang that rely
1095*9880d681SAndroid Build Coastguard Worker; on the particular register placement of a single large integer return value.
1096*9880d681SAndroid Build Coastguard Worker; CHECK: @PR14059.2
1097*9880d681SAndroid Build Coastguard Worker
1098*9880d681SAndroid Build Coastguard Workerentry:
1099*9880d681SAndroid Build Coastguard Worker  %retval = alloca { float, float }, align 4
1100*9880d681SAndroid Build Coastguard Worker  ; CHECK-NOT: alloca
1101*9880d681SAndroid Build Coastguard Worker
1102*9880d681SAndroid Build Coastguard Worker  %0 = bitcast { float, float }* %retval to i64*
1103*9880d681SAndroid Build Coastguard Worker  store i64 0, i64* %0
1104*9880d681SAndroid Build Coastguard Worker  ; CHECK-NOT: store
1105*9880d681SAndroid Build Coastguard Worker
1106*9880d681SAndroid Build Coastguard Worker  %phi.realp = getelementptr inbounds { float, float }, { float, float }* %phi, i32 0, i32 0
1107*9880d681SAndroid Build Coastguard Worker  %phi.real = load float, float* %phi.realp
1108*9880d681SAndroid Build Coastguard Worker  %phi.imagp = getelementptr inbounds { float, float }, { float, float }* %phi, i32 0, i32 1
1109*9880d681SAndroid Build Coastguard Worker  %phi.imag = load float, float* %phi.imagp
1110*9880d681SAndroid Build Coastguard Worker  ; CHECK:      %[[realp:.*]] = getelementptr inbounds { float, float }, { float, float }* %phi, i32 0, i32 0
1111*9880d681SAndroid Build Coastguard Worker  ; CHECK-NEXT: %[[real:.*]] = load float, float* %[[realp]]
1112*9880d681SAndroid Build Coastguard Worker  ; CHECK-NEXT: %[[imagp:.*]] = getelementptr inbounds { float, float }, { float, float }* %phi, i32 0, i32 1
1113*9880d681SAndroid Build Coastguard Worker  ; CHECK-NEXT: %[[imag:.*]] = load float, float* %[[imagp]]
1114*9880d681SAndroid Build Coastguard Worker
1115*9880d681SAndroid Build Coastguard Worker  %real = getelementptr inbounds { float, float }, { float, float }* %retval, i32 0, i32 0
1116*9880d681SAndroid Build Coastguard Worker  %imag = getelementptr inbounds { float, float }, { float, float }* %retval, i32 0, i32 1
1117*9880d681SAndroid Build Coastguard Worker  store float %phi.real, float* %real
1118*9880d681SAndroid Build Coastguard Worker  store float %phi.imag, float* %imag
1119*9880d681SAndroid Build Coastguard Worker  ; CHECK-NEXT: %[[real_convert:.*]] = bitcast float %[[real]] to i32
1120*9880d681SAndroid Build Coastguard Worker  ; CHECK-NEXT: %[[imag_convert:.*]] = bitcast float %[[imag]] to i32
1121*9880d681SAndroid Build Coastguard Worker  ; CHECK-NEXT: %[[imag_ext:.*]] = zext i32 %[[imag_convert]] to i64
1122*9880d681SAndroid Build Coastguard Worker  ; CHECK-NEXT: %[[imag_shift:.*]] = shl i64 %[[imag_ext]], 32
1123*9880d681SAndroid Build Coastguard Worker  ; CHECK-NEXT: %[[imag_mask:.*]] = and i64 undef, 4294967295
1124*9880d681SAndroid Build Coastguard Worker  ; CHECK-NEXT: %[[imag_insert:.*]] = or i64 %[[imag_mask]], %[[imag_shift]]
1125*9880d681SAndroid Build Coastguard Worker  ; CHECK-NEXT: %[[real_ext:.*]] = zext i32 %[[real_convert]] to i64
1126*9880d681SAndroid Build Coastguard Worker  ; CHECK-NEXT: %[[real_mask:.*]] = and i64 %[[imag_insert]], -4294967296
1127*9880d681SAndroid Build Coastguard Worker  ; CHECK-NEXT: %[[real_insert:.*]] = or i64 %[[real_mask]], %[[real_ext]]
1128*9880d681SAndroid Build Coastguard Worker
1129*9880d681SAndroid Build Coastguard Worker  %1 = load i64, i64* %0, align 1
1130*9880d681SAndroid Build Coastguard Worker  ret i64 %1
1131*9880d681SAndroid Build Coastguard Worker  ; CHECK-NEXT: ret i64 %[[real_insert]]
1132*9880d681SAndroid Build Coastguard Worker}
1133*9880d681SAndroid Build Coastguard Worker
1134*9880d681SAndroid Build Coastguard Workerdefine void @PR14105({ [16 x i8] }* %ptr) {
1135*9880d681SAndroid Build Coastguard Worker; Ensure that when rewriting the GEP index '-1' for this alloca we preserve is
1136*9880d681SAndroid Build Coastguard Worker; sign as negative. We use a volatile memcpy to ensure promotion never actually
1137*9880d681SAndroid Build Coastguard Worker; occurs.
1138*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @PR14105(
1139*9880d681SAndroid Build Coastguard Worker
1140*9880d681SAndroid Build Coastguard Workerentry:
1141*9880d681SAndroid Build Coastguard Worker  %a = alloca { [16 x i8] }, align 8
1142*9880d681SAndroid Build Coastguard Worker; CHECK: alloca [16 x i8], align 8
1143*9880d681SAndroid Build Coastguard Worker
1144*9880d681SAndroid Build Coastguard Worker  %gep = getelementptr inbounds { [16 x i8] }, { [16 x i8] }* %ptr, i64 -1
1145*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: getelementptr inbounds { [16 x i8] }, { [16 x i8] }* %ptr, i64 -1, i32 0, i64 0
1146*9880d681SAndroid Build Coastguard Worker
1147*9880d681SAndroid Build Coastguard Worker  %cast1 = bitcast { [16 x i8 ] }* %gep to i8*
1148*9880d681SAndroid Build Coastguard Worker  %cast2 = bitcast { [16 x i8 ] }* %a to i8*
1149*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %cast1, i8* %cast2, i32 16, i32 8, i1 true)
1150*9880d681SAndroid Build Coastguard Worker  ret void
1151*9880d681SAndroid Build Coastguard Worker; CHECK: ret
1152*9880d681SAndroid Build Coastguard Worker}
1153*9880d681SAndroid Build Coastguard Worker
1154*9880d681SAndroid Build Coastguard Workerdefine void @PR14105_as1({ [16 x i8] } addrspace(1)* %ptr) {
1155*9880d681SAndroid Build Coastguard Worker; Make sure this the right address space pointer is used for type check.
1156*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @PR14105_as1(
1157*9880d681SAndroid Build Coastguard Worker
1158*9880d681SAndroid Build Coastguard Workerentry:
1159*9880d681SAndroid Build Coastguard Worker  %a = alloca { [16 x i8] }, align 8
1160*9880d681SAndroid Build Coastguard Worker; CHECK: alloca [16 x i8], align 8
1161*9880d681SAndroid Build Coastguard Worker
1162*9880d681SAndroid Build Coastguard Worker  %gep = getelementptr inbounds { [16 x i8] }, { [16 x i8] } addrspace(1)* %ptr, i64 -1
1163*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: getelementptr inbounds { [16 x i8] }, { [16 x i8] } addrspace(1)* %ptr, i16 -1, i32 0, i16 0
1164*9880d681SAndroid Build Coastguard Worker
1165*9880d681SAndroid Build Coastguard Worker  %cast1 = bitcast { [16 x i8 ] } addrspace(1)* %gep to i8 addrspace(1)*
1166*9880d681SAndroid Build Coastguard Worker  %cast2 = bitcast { [16 x i8 ] }* %a to i8*
1167*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p1i8.p0i8.i32(i8 addrspace(1)* %cast1, i8* %cast2, i32 16, i32 8, i1 true)
1168*9880d681SAndroid Build Coastguard Worker  ret void
1169*9880d681SAndroid Build Coastguard Worker; CHECK: ret
1170*9880d681SAndroid Build Coastguard Worker}
1171*9880d681SAndroid Build Coastguard Worker
1172*9880d681SAndroid Build Coastguard Workerdefine void @PR14465() {
1173*9880d681SAndroid Build Coastguard Worker; Ensure that we don't crash when analyzing a alloca larger than the maximum
1174*9880d681SAndroid Build Coastguard Worker; integer type width (MAX_INT_BITS) supported by llvm (1048576*32 > (1<<23)-1).
1175*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @PR14465(
1176*9880d681SAndroid Build Coastguard Worker
1177*9880d681SAndroid Build Coastguard Worker  %stack = alloca [1048576 x i32], align 16
1178*9880d681SAndroid Build Coastguard Worker; CHECK: alloca [1048576 x i32]
1179*9880d681SAndroid Build Coastguard Worker  %cast = bitcast [1048576 x i32]* %stack to i8*
1180*9880d681SAndroid Build Coastguard Worker  call void @llvm.memset.p0i8.i64(i8* %cast, i8 -2, i64 4194304, i32 16, i1 false)
1181*9880d681SAndroid Build Coastguard Worker  ret void
1182*9880d681SAndroid Build Coastguard Worker; CHECK: ret
1183*9880d681SAndroid Build Coastguard Worker}
1184*9880d681SAndroid Build Coastguard Worker
1185*9880d681SAndroid Build Coastguard Workerdefine void @PR14548(i1 %x) {
1186*9880d681SAndroid Build Coastguard Worker; Handle a mixture of i1 and i8 loads and stores to allocas. This particular
1187*9880d681SAndroid Build Coastguard Worker; pattern caused crashes and invalid output in the PR, and its nature will
1188*9880d681SAndroid Build Coastguard Worker; trigger a mixture in several permutations as we resolve each alloca
1189*9880d681SAndroid Build Coastguard Worker; iteratively.
1190*9880d681SAndroid Build Coastguard Worker; Note that we don't do a particularly good *job* of handling these mixtures,
1191*9880d681SAndroid Build Coastguard Worker; but the hope is that this is very rare.
1192*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @PR14548(
1193*9880d681SAndroid Build Coastguard Worker
1194*9880d681SAndroid Build Coastguard Workerentry:
1195*9880d681SAndroid Build Coastguard Worker  %a = alloca <{ i1 }>, align 8
1196*9880d681SAndroid Build Coastguard Worker  %b = alloca <{ i1 }>, align 8
1197*9880d681SAndroid Build Coastguard Worker; CHECK:      %[[a:.*]] = alloca i8, align 8
1198*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[b:.*]] = alloca i8, align 8
1199*9880d681SAndroid Build Coastguard Worker
1200*9880d681SAndroid Build Coastguard Worker  %b.i1 = bitcast <{ i1 }>* %b to i1*
1201*9880d681SAndroid Build Coastguard Worker  store i1 %x, i1* %b.i1, align 8
1202*9880d681SAndroid Build Coastguard Worker  %b.i8 = bitcast <{ i1 }>* %b to i8*
1203*9880d681SAndroid Build Coastguard Worker  %foo = load i8, i8* %b.i8, align 1
1204*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[b_cast:.*]] = bitcast i8* %[[b]] to i1*
1205*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i1 %x, i1* %[[b_cast]], align 8
1206*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: {{.*}} = load i8, i8* %[[b]], align 8
1207*9880d681SAndroid Build Coastguard Worker
1208*9880d681SAndroid Build Coastguard Worker  %a.i8 = bitcast <{ i1 }>* %a to i8*
1209*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %a.i8, i8* %b.i8, i32 1, i32 1, i1 false) nounwind
1210*9880d681SAndroid Build Coastguard Worker  %bar = load i8, i8* %a.i8, align 1
1211*9880d681SAndroid Build Coastguard Worker  %a.i1 = getelementptr inbounds <{ i1 }>, <{ i1 }>* %a, i32 0, i32 0
1212*9880d681SAndroid Build Coastguard Worker  %baz = load i1, i1* %a.i1, align 1
1213*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[copy:.*]] = load i8, i8* %[[b]], align 8
1214*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i8 %[[copy]], i8* %[[a]], align 8
1215*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: {{.*}} = load i8, i8* %[[a]], align 8
1216*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[a_cast:.*]] = bitcast i8* %[[a]] to i1*
1217*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: {{.*}} = load i1, i1* %[[a_cast]], align 8
1218*9880d681SAndroid Build Coastguard Worker
1219*9880d681SAndroid Build Coastguard Worker  ret void
1220*9880d681SAndroid Build Coastguard Worker}
1221*9880d681SAndroid Build Coastguard Worker
1222*9880d681SAndroid Build Coastguard Workerdefine <3 x i8> @PR14572.1(i32 %x) {
1223*9880d681SAndroid Build Coastguard Worker; Ensure that a split integer store which is wider than the type size of the
1224*9880d681SAndroid Build Coastguard Worker; alloca (relying on the alloc size padding) doesn't trigger an assert.
1225*9880d681SAndroid Build Coastguard Worker; CHECK: @PR14572.1
1226*9880d681SAndroid Build Coastguard Worker
1227*9880d681SAndroid Build Coastguard Workerentry:
1228*9880d681SAndroid Build Coastguard Worker  %a = alloca <3 x i8>, align 4
1229*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
1230*9880d681SAndroid Build Coastguard Worker
1231*9880d681SAndroid Build Coastguard Worker  %cast = bitcast <3 x i8>* %a to i32*
1232*9880d681SAndroid Build Coastguard Worker  store i32 %x, i32* %cast, align 1
1233*9880d681SAndroid Build Coastguard Worker  %y = load <3 x i8>, <3 x i8>* %a, align 4
1234*9880d681SAndroid Build Coastguard Worker  ret <3 x i8> %y
1235*9880d681SAndroid Build Coastguard Worker; CHECK: ret <3 x i8>
1236*9880d681SAndroid Build Coastguard Worker}
1237*9880d681SAndroid Build Coastguard Worker
1238*9880d681SAndroid Build Coastguard Workerdefine i32 @PR14572.2(<3 x i8> %x) {
1239*9880d681SAndroid Build Coastguard Worker; Ensure that a split integer load which is wider than the type size of the
1240*9880d681SAndroid Build Coastguard Worker; alloca (relying on the alloc size padding) doesn't trigger an assert.
1241*9880d681SAndroid Build Coastguard Worker; CHECK: @PR14572.2
1242*9880d681SAndroid Build Coastguard Worker
1243*9880d681SAndroid Build Coastguard Workerentry:
1244*9880d681SAndroid Build Coastguard Worker  %a = alloca <3 x i8>, align 4
1245*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
1246*9880d681SAndroid Build Coastguard Worker
1247*9880d681SAndroid Build Coastguard Worker  store <3 x i8> %x, <3 x i8>* %a, align 1
1248*9880d681SAndroid Build Coastguard Worker  %cast = bitcast <3 x i8>* %a to i32*
1249*9880d681SAndroid Build Coastguard Worker  %y = load i32, i32* %cast, align 4
1250*9880d681SAndroid Build Coastguard Worker  ret i32 %y
1251*9880d681SAndroid Build Coastguard Worker; CHECK: ret i32
1252*9880d681SAndroid Build Coastguard Worker}
1253*9880d681SAndroid Build Coastguard Worker
1254*9880d681SAndroid Build Coastguard Workerdefine i32 @PR14601(i32 %x) {
1255*9880d681SAndroid Build Coastguard Worker; Don't try to form a promotable integer alloca when there is a variable length
1256*9880d681SAndroid Build Coastguard Worker; memory intrinsic.
1257*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @PR14601(
1258*9880d681SAndroid Build Coastguard Worker
1259*9880d681SAndroid Build Coastguard Workerentry:
1260*9880d681SAndroid Build Coastguard Worker  %a = alloca i32
1261*9880d681SAndroid Build Coastguard Worker; CHECK: alloca
1262*9880d681SAndroid Build Coastguard Worker
1263*9880d681SAndroid Build Coastguard Worker  %a.i8 = bitcast i32* %a to i8*
1264*9880d681SAndroid Build Coastguard Worker  call void @llvm.memset.p0i8.i32(i8* %a.i8, i8 0, i32 %x, i32 1, i1 false)
1265*9880d681SAndroid Build Coastguard Worker  %v = load i32, i32* %a
1266*9880d681SAndroid Build Coastguard Worker  ret i32 %v
1267*9880d681SAndroid Build Coastguard Worker}
1268*9880d681SAndroid Build Coastguard Worker
1269*9880d681SAndroid Build Coastguard Workerdefine void @PR15674(i8* %data, i8* %src, i32 %size) {
1270*9880d681SAndroid Build Coastguard Worker; Arrange (via control flow) to have unmerged stores of a particular width to
1271*9880d681SAndroid Build Coastguard Worker; an alloca where we incrementally store from the end of the array toward the
1272*9880d681SAndroid Build Coastguard Worker; beginning of the array. Ensure that the final integer store, despite being
1273*9880d681SAndroid Build Coastguard Worker; convertable to the integer type that we end up promoting this alloca toward,
1274*9880d681SAndroid Build Coastguard Worker; doesn't get widened to a full alloca store.
1275*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @PR15674(
1276*9880d681SAndroid Build Coastguard Worker
1277*9880d681SAndroid Build Coastguard Workerentry:
1278*9880d681SAndroid Build Coastguard Worker  %tmp = alloca [4 x i8], align 1
1279*9880d681SAndroid Build Coastguard Worker; CHECK: alloca i32
1280*9880d681SAndroid Build Coastguard Worker
1281*9880d681SAndroid Build Coastguard Worker  switch i32 %size, label %end [
1282*9880d681SAndroid Build Coastguard Worker    i32 4, label %bb4
1283*9880d681SAndroid Build Coastguard Worker    i32 3, label %bb3
1284*9880d681SAndroid Build Coastguard Worker    i32 2, label %bb2
1285*9880d681SAndroid Build Coastguard Worker    i32 1, label %bb1
1286*9880d681SAndroid Build Coastguard Worker  ]
1287*9880d681SAndroid Build Coastguard Worker
1288*9880d681SAndroid Build Coastguard Workerbb4:
1289*9880d681SAndroid Build Coastguard Worker  %src.gep3 = getelementptr inbounds i8, i8* %src, i32 3
1290*9880d681SAndroid Build Coastguard Worker  %src.3 = load i8, i8* %src.gep3
1291*9880d681SAndroid Build Coastguard Worker  %tmp.gep3 = getelementptr inbounds [4 x i8], [4 x i8]* %tmp, i32 0, i32 3
1292*9880d681SAndroid Build Coastguard Worker  store i8 %src.3, i8* %tmp.gep3
1293*9880d681SAndroid Build Coastguard Worker; CHECK: store i8
1294*9880d681SAndroid Build Coastguard Worker
1295*9880d681SAndroid Build Coastguard Worker  br label %bb3
1296*9880d681SAndroid Build Coastguard Worker
1297*9880d681SAndroid Build Coastguard Workerbb3:
1298*9880d681SAndroid Build Coastguard Worker  %src.gep2 = getelementptr inbounds i8, i8* %src, i32 2
1299*9880d681SAndroid Build Coastguard Worker  %src.2 = load i8, i8* %src.gep2
1300*9880d681SAndroid Build Coastguard Worker  %tmp.gep2 = getelementptr inbounds [4 x i8], [4 x i8]* %tmp, i32 0, i32 2
1301*9880d681SAndroid Build Coastguard Worker  store i8 %src.2, i8* %tmp.gep2
1302*9880d681SAndroid Build Coastguard Worker; CHECK: store i8
1303*9880d681SAndroid Build Coastguard Worker
1304*9880d681SAndroid Build Coastguard Worker  br label %bb2
1305*9880d681SAndroid Build Coastguard Worker
1306*9880d681SAndroid Build Coastguard Workerbb2:
1307*9880d681SAndroid Build Coastguard Worker  %src.gep1 = getelementptr inbounds i8, i8* %src, i32 1
1308*9880d681SAndroid Build Coastguard Worker  %src.1 = load i8, i8* %src.gep1
1309*9880d681SAndroid Build Coastguard Worker  %tmp.gep1 = getelementptr inbounds [4 x i8], [4 x i8]* %tmp, i32 0, i32 1
1310*9880d681SAndroid Build Coastguard Worker  store i8 %src.1, i8* %tmp.gep1
1311*9880d681SAndroid Build Coastguard Worker; CHECK: store i8
1312*9880d681SAndroid Build Coastguard Worker
1313*9880d681SAndroid Build Coastguard Worker  br label %bb1
1314*9880d681SAndroid Build Coastguard Worker
1315*9880d681SAndroid Build Coastguard Workerbb1:
1316*9880d681SAndroid Build Coastguard Worker  %src.gep0 = getelementptr inbounds i8, i8* %src, i32 0
1317*9880d681SAndroid Build Coastguard Worker  %src.0 = load i8, i8* %src.gep0
1318*9880d681SAndroid Build Coastguard Worker  %tmp.gep0 = getelementptr inbounds [4 x i8], [4 x i8]* %tmp, i32 0, i32 0
1319*9880d681SAndroid Build Coastguard Worker  store i8 %src.0, i8* %tmp.gep0
1320*9880d681SAndroid Build Coastguard Worker; CHECK: store i8
1321*9880d681SAndroid Build Coastguard Worker
1322*9880d681SAndroid Build Coastguard Worker  br label %end
1323*9880d681SAndroid Build Coastguard Worker
1324*9880d681SAndroid Build Coastguard Workerend:
1325*9880d681SAndroid Build Coastguard Worker  %tmp.raw = bitcast [4 x i8]* %tmp to i8*
1326*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %data, i8* %tmp.raw, i32 %size, i32 1, i1 false)
1327*9880d681SAndroid Build Coastguard Worker  ret void
1328*9880d681SAndroid Build Coastguard Worker; CHECK: ret void
1329*9880d681SAndroid Build Coastguard Worker}
1330*9880d681SAndroid Build Coastguard Worker
1331*9880d681SAndroid Build Coastguard Workerdefine void @PR15805(i1 %a, i1 %b) {
1332*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @PR15805(
1333*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
1334*9880d681SAndroid Build Coastguard Worker; CHECK: ret void
1335*9880d681SAndroid Build Coastguard Worker
1336*9880d681SAndroid Build Coastguard Worker  %c = alloca i64, align 8
1337*9880d681SAndroid Build Coastguard Worker  %p.0.c = select i1 undef, i64* %c, i64* %c
1338*9880d681SAndroid Build Coastguard Worker  %cond.in = select i1 undef, i64* %p.0.c, i64* %c
1339*9880d681SAndroid Build Coastguard Worker  %cond = load i64, i64* %cond.in, align 8
1340*9880d681SAndroid Build Coastguard Worker  ret void
1341*9880d681SAndroid Build Coastguard Worker}
1342*9880d681SAndroid Build Coastguard Worker
1343*9880d681SAndroid Build Coastguard Workerdefine void @PR15805.1(i1 %a, i1 %b) {
1344*9880d681SAndroid Build Coastguard Worker; Same as the normal PR15805, but rigged to place the use before the def inside
1345*9880d681SAndroid Build Coastguard Worker; of looping unreachable code. This helps ensure that we aren't sensitive to the
1346*9880d681SAndroid Build Coastguard Worker; order in which the uses of the alloca are visited.
1347*9880d681SAndroid Build Coastguard Worker;
1348*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @PR15805.1(
1349*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
1350*9880d681SAndroid Build Coastguard Worker; CHECK: ret void
1351*9880d681SAndroid Build Coastguard Worker
1352*9880d681SAndroid Build Coastguard Worker  %c = alloca i64, align 8
1353*9880d681SAndroid Build Coastguard Worker  br label %exit
1354*9880d681SAndroid Build Coastguard Worker
1355*9880d681SAndroid Build Coastguard Workerloop:
1356*9880d681SAndroid Build Coastguard Worker  %cond.in = select i1 undef, i64* %c, i64* %p.0.c
1357*9880d681SAndroid Build Coastguard Worker  %p.0.c = select i1 undef, i64* %c, i64* %c
1358*9880d681SAndroid Build Coastguard Worker  %cond = load i64, i64* %cond.in, align 8
1359*9880d681SAndroid Build Coastguard Worker  br i1 undef, label %loop, label %exit
1360*9880d681SAndroid Build Coastguard Worker
1361*9880d681SAndroid Build Coastguard Workerexit:
1362*9880d681SAndroid Build Coastguard Worker  ret void
1363*9880d681SAndroid Build Coastguard Worker}
1364*9880d681SAndroid Build Coastguard Worker
1365*9880d681SAndroid Build Coastguard Workerdefine void @PR16651.1(i8* %a) {
1366*9880d681SAndroid Build Coastguard Worker; This test case caused a crash due to the volatile memcpy in combination with
1367*9880d681SAndroid Build Coastguard Worker; lowering to integer loads and stores of a width other than that of the original
1368*9880d681SAndroid Build Coastguard Worker; memcpy.
1369*9880d681SAndroid Build Coastguard Worker;
1370*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @PR16651.1(
1371*9880d681SAndroid Build Coastguard Worker; CHECK: alloca i16
1372*9880d681SAndroid Build Coastguard Worker; CHECK: alloca i8
1373*9880d681SAndroid Build Coastguard Worker; CHECK: alloca i8
1374*9880d681SAndroid Build Coastguard Worker; CHECK: unreachable
1375*9880d681SAndroid Build Coastguard Worker
1376*9880d681SAndroid Build Coastguard Workerentry:
1377*9880d681SAndroid Build Coastguard Worker  %b = alloca i32, align 4
1378*9880d681SAndroid Build Coastguard Worker  %b.cast = bitcast i32* %b to i8*
1379*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %b.cast, i8* %a, i32 4, i32 4, i1 true)
1380*9880d681SAndroid Build Coastguard Worker  %b.gep = getelementptr inbounds i8, i8* %b.cast, i32 2
1381*9880d681SAndroid Build Coastguard Worker  load i8, i8* %b.gep, align 2
1382*9880d681SAndroid Build Coastguard Worker  unreachable
1383*9880d681SAndroid Build Coastguard Worker}
1384*9880d681SAndroid Build Coastguard Worker
1385*9880d681SAndroid Build Coastguard Workerdefine void @PR16651.2() {
1386*9880d681SAndroid Build Coastguard Worker; This test case caused a crash due to failing to promote given a select that
1387*9880d681SAndroid Build Coastguard Worker; can't be speculated. It shouldn't be promoted, but we missed that fact when
1388*9880d681SAndroid Build Coastguard Worker; analyzing whether we could form a vector promotion because that code didn't
1389*9880d681SAndroid Build Coastguard Worker; bail on select instructions.
1390*9880d681SAndroid Build Coastguard Worker;
1391*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @PR16651.2(
1392*9880d681SAndroid Build Coastguard Worker; CHECK: alloca <2 x float>
1393*9880d681SAndroid Build Coastguard Worker; CHECK: ret void
1394*9880d681SAndroid Build Coastguard Worker
1395*9880d681SAndroid Build Coastguard Workerentry:
1396*9880d681SAndroid Build Coastguard Worker  %tv1 = alloca { <2 x float>, <2 x float> }, align 8
1397*9880d681SAndroid Build Coastguard Worker  %0 = getelementptr { <2 x float>, <2 x float> }, { <2 x float>, <2 x float> }* %tv1, i64 0, i32 1
1398*9880d681SAndroid Build Coastguard Worker  store <2 x float> undef, <2 x float>* %0, align 8
1399*9880d681SAndroid Build Coastguard Worker  %1 = getelementptr inbounds { <2 x float>, <2 x float> }, { <2 x float>, <2 x float> }* %tv1, i64 0, i32 1, i64 0
1400*9880d681SAndroid Build Coastguard Worker  %cond105.in.i.i = select i1 undef, float* null, float* %1
1401*9880d681SAndroid Build Coastguard Worker  %cond105.i.i = load float, float* %cond105.in.i.i, align 8
1402*9880d681SAndroid Build Coastguard Worker  ret void
1403*9880d681SAndroid Build Coastguard Worker}
1404*9880d681SAndroid Build Coastguard Worker
1405*9880d681SAndroid Build Coastguard Workerdefine void @test23(i32 %x) {
1406*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test23(
1407*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
1408*9880d681SAndroid Build Coastguard Worker; CHECK: ret void
1409*9880d681SAndroid Build Coastguard Workerentry:
1410*9880d681SAndroid Build Coastguard Worker  %a = alloca i32, align 4
1411*9880d681SAndroid Build Coastguard Worker  store i32 %x, i32* %a, align 4
1412*9880d681SAndroid Build Coastguard Worker  %gep1 = getelementptr inbounds i32, i32* %a, i32 1
1413*9880d681SAndroid Build Coastguard Worker  %gep0 = getelementptr inbounds i32, i32* %a, i32 0
1414*9880d681SAndroid Build Coastguard Worker  %cast1 = bitcast i32* %gep1 to i8*
1415*9880d681SAndroid Build Coastguard Worker  %cast0 = bitcast i32* %gep0 to i8*
1416*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %cast1, i8* %cast0, i32 4, i32 1, i1 false)
1417*9880d681SAndroid Build Coastguard Worker  ret void
1418*9880d681SAndroid Build Coastguard Worker}
1419*9880d681SAndroid Build Coastguard Worker
1420*9880d681SAndroid Build Coastguard Workerdefine void @PR18615() {
1421*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @PR18615(
1422*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
1423*9880d681SAndroid Build Coastguard Worker; CHECK: ret void
1424*9880d681SAndroid Build Coastguard Workerentry:
1425*9880d681SAndroid Build Coastguard Worker  %f = alloca i8
1426*9880d681SAndroid Build Coastguard Worker  %gep = getelementptr i8, i8* %f, i64 -1
1427*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* undef, i8* %gep, i32 1, i32 1, i1 false)
1428*9880d681SAndroid Build Coastguard Worker  ret void
1429*9880d681SAndroid Build Coastguard Worker}
1430*9880d681SAndroid Build Coastguard Worker
1431*9880d681SAndroid Build Coastguard Workerdefine void @test24(i8* %src, i8* %dst) {
1432*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test24(
1433*9880d681SAndroid Build Coastguard Worker; CHECK: alloca i64, align 16
1434*9880d681SAndroid Build Coastguard Worker; CHECK: load volatile i64, i64* %{{[^,]*}}, align 1
1435*9880d681SAndroid Build Coastguard Worker; CHECK: store volatile i64 %{{[^,]*}}, i64* %{{[^,]*}}, align 16
1436*9880d681SAndroid Build Coastguard Worker; CHECK: load volatile i64, i64* %{{[^,]*}}, align 16
1437*9880d681SAndroid Build Coastguard Worker; CHECK: store volatile i64 %{{[^,]*}}, i64* %{{[^,]*}}, align 1
1438*9880d681SAndroid Build Coastguard Worker
1439*9880d681SAndroid Build Coastguard Workerentry:
1440*9880d681SAndroid Build Coastguard Worker  %a = alloca i64, align 16
1441*9880d681SAndroid Build Coastguard Worker  %ptr = bitcast i64* %a to i8*
1442*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %ptr, i8* %src, i32 8, i32 1, i1 true)
1443*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %ptr, i32 8, i32 1, i1 true)
1444*9880d681SAndroid Build Coastguard Worker  ret void
1445*9880d681SAndroid Build Coastguard Worker}
1446*9880d681SAndroid Build Coastguard Worker
1447*9880d681SAndroid Build Coastguard Workerdefine float @test25() {
1448*9880d681SAndroid Build Coastguard Worker; Check that we split up stores in order to promote the smaller SSA values.. These types
1449*9880d681SAndroid Build Coastguard Worker; of patterns can arise because LLVM maps small memcpy's to integer load and
1450*9880d681SAndroid Build Coastguard Worker; stores. If we get a memcpy of an aggregate (such as C and C++ frontends would
1451*9880d681SAndroid Build Coastguard Worker; produce, but so might any language frontend), this will in many cases turn into
1452*9880d681SAndroid Build Coastguard Worker; an integer load and store. SROA needs to be extremely powerful to correctly
1453*9880d681SAndroid Build Coastguard Worker; handle these cases and form splitable and promotable SSA values.
1454*9880d681SAndroid Build Coastguard Worker;
1455*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test25(
1456*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
1457*9880d681SAndroid Build Coastguard Worker; CHECK: %[[F1:.*]] = bitcast i32 0 to float
1458*9880d681SAndroid Build Coastguard Worker; CHECK: %[[F2:.*]] = bitcast i32 1065353216 to float
1459*9880d681SAndroid Build Coastguard Worker; CHECK: %[[SUM:.*]] = fadd float %[[F1]], %[[F2]]
1460*9880d681SAndroid Build Coastguard Worker; CHECK: ret float %[[SUM]]
1461*9880d681SAndroid Build Coastguard Worker
1462*9880d681SAndroid Build Coastguard Workerentry:
1463*9880d681SAndroid Build Coastguard Worker  %a = alloca i64
1464*9880d681SAndroid Build Coastguard Worker  %b = alloca i64
1465*9880d681SAndroid Build Coastguard Worker  %a.cast = bitcast i64* %a to [2 x float]*
1466*9880d681SAndroid Build Coastguard Worker  %a.gep1 = getelementptr [2 x float], [2 x float]* %a.cast, i32 0, i32 0
1467*9880d681SAndroid Build Coastguard Worker  %a.gep2 = getelementptr [2 x float], [2 x float]* %a.cast, i32 0, i32 1
1468*9880d681SAndroid Build Coastguard Worker  %b.cast = bitcast i64* %b to [2 x float]*
1469*9880d681SAndroid Build Coastguard Worker  %b.gep1 = getelementptr [2 x float], [2 x float]* %b.cast, i32 0, i32 0
1470*9880d681SAndroid Build Coastguard Worker  %b.gep2 = getelementptr [2 x float], [2 x float]* %b.cast, i32 0, i32 1
1471*9880d681SAndroid Build Coastguard Worker  store float 0.0, float* %a.gep1
1472*9880d681SAndroid Build Coastguard Worker  store float 1.0, float* %a.gep2
1473*9880d681SAndroid Build Coastguard Worker  %v = load i64, i64* %a
1474*9880d681SAndroid Build Coastguard Worker  store i64 %v, i64* %b
1475*9880d681SAndroid Build Coastguard Worker  %f1 = load float, float* %b.gep1
1476*9880d681SAndroid Build Coastguard Worker  %f2 = load float, float* %b.gep2
1477*9880d681SAndroid Build Coastguard Worker  %ret = fadd float %f1, %f2
1478*9880d681SAndroid Build Coastguard Worker  ret float %ret
1479*9880d681SAndroid Build Coastguard Worker}
1480*9880d681SAndroid Build Coastguard Worker
1481*9880d681SAndroid Build Coastguard Worker@complex1 = external global [2 x float]
1482*9880d681SAndroid Build Coastguard Worker@complex2 = external global [2 x float]
1483*9880d681SAndroid Build Coastguard Worker
1484*9880d681SAndroid Build Coastguard Workerdefine void @test26() {
1485*9880d681SAndroid Build Coastguard Worker; Test a case of splitting up loads and stores against a globals.
1486*9880d681SAndroid Build Coastguard Worker;
1487*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test26(
1488*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
1489*9880d681SAndroid Build Coastguard Worker; CHECK: %[[L1:.*]] = load i32, i32* bitcast
1490*9880d681SAndroid Build Coastguard Worker; CHECK: %[[L2:.*]] = load i32, i32* bitcast
1491*9880d681SAndroid Build Coastguard Worker; CHECK: %[[F1:.*]] = bitcast i32 %[[L1]] to float
1492*9880d681SAndroid Build Coastguard Worker; CHECK: %[[F2:.*]] = bitcast i32 %[[L2]] to float
1493*9880d681SAndroid Build Coastguard Worker; CHECK: %[[SUM:.*]] = fadd float %[[F1]], %[[F2]]
1494*9880d681SAndroid Build Coastguard Worker; CHECK: %[[C1:.*]] = bitcast float %[[SUM]] to i32
1495*9880d681SAndroid Build Coastguard Worker; CHECK: %[[C2:.*]] = bitcast float %[[SUM]] to i32
1496*9880d681SAndroid Build Coastguard Worker; CHECK: store i32 %[[C1]], i32* bitcast
1497*9880d681SAndroid Build Coastguard Worker; CHECK: store i32 %[[C2]], i32* bitcast
1498*9880d681SAndroid Build Coastguard Worker; CHECK: ret void
1499*9880d681SAndroid Build Coastguard Worker
1500*9880d681SAndroid Build Coastguard Workerentry:
1501*9880d681SAndroid Build Coastguard Worker  %a = alloca i64
1502*9880d681SAndroid Build Coastguard Worker  %a.cast = bitcast i64* %a to [2 x float]*
1503*9880d681SAndroid Build Coastguard Worker  %a.gep1 = getelementptr [2 x float], [2 x float]* %a.cast, i32 0, i32 0
1504*9880d681SAndroid Build Coastguard Worker  %a.gep2 = getelementptr [2 x float], [2 x float]* %a.cast, i32 0, i32 1
1505*9880d681SAndroid Build Coastguard Worker  %v1 = load i64, i64* bitcast ([2 x float]* @complex1 to i64*)
1506*9880d681SAndroid Build Coastguard Worker  store i64 %v1, i64* %a
1507*9880d681SAndroid Build Coastguard Worker  %f1 = load float, float* %a.gep1
1508*9880d681SAndroid Build Coastguard Worker  %f2 = load float, float* %a.gep2
1509*9880d681SAndroid Build Coastguard Worker  %sum = fadd float %f1, %f2
1510*9880d681SAndroid Build Coastguard Worker  store float %sum, float* %a.gep1
1511*9880d681SAndroid Build Coastguard Worker  store float %sum, float* %a.gep2
1512*9880d681SAndroid Build Coastguard Worker  %v2 = load i64, i64* %a
1513*9880d681SAndroid Build Coastguard Worker  store i64 %v2, i64* bitcast ([2 x float]* @complex2 to i64*)
1514*9880d681SAndroid Build Coastguard Worker  ret void
1515*9880d681SAndroid Build Coastguard Worker}
1516*9880d681SAndroid Build Coastguard Worker
1517*9880d681SAndroid Build Coastguard Workerdefine float @test27() {
1518*9880d681SAndroid Build Coastguard Worker; Another, more complex case of splittable i64 loads and stores. This example
1519*9880d681SAndroid Build Coastguard Worker; is a particularly challenging one because the load and store both point into
1520*9880d681SAndroid Build Coastguard Worker; the alloca SROA is processing, and they overlap but at an offset.
1521*9880d681SAndroid Build Coastguard Worker;
1522*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @test27(
1523*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
1524*9880d681SAndroid Build Coastguard Worker; CHECK: %[[F1:.*]] = bitcast i32 0 to float
1525*9880d681SAndroid Build Coastguard Worker; CHECK: %[[F2:.*]] = bitcast i32 1065353216 to float
1526*9880d681SAndroid Build Coastguard Worker; CHECK: %[[SUM:.*]] = fadd float %[[F1]], %[[F2]]
1527*9880d681SAndroid Build Coastguard Worker; CHECK: ret float %[[SUM]]
1528*9880d681SAndroid Build Coastguard Worker
1529*9880d681SAndroid Build Coastguard Workerentry:
1530*9880d681SAndroid Build Coastguard Worker  %a = alloca [12 x i8]
1531*9880d681SAndroid Build Coastguard Worker  %gep1 = getelementptr [12 x i8], [12 x i8]* %a, i32 0, i32 0
1532*9880d681SAndroid Build Coastguard Worker  %gep2 = getelementptr [12 x i8], [12 x i8]* %a, i32 0, i32 4
1533*9880d681SAndroid Build Coastguard Worker  %gep3 = getelementptr [12 x i8], [12 x i8]* %a, i32 0, i32 8
1534*9880d681SAndroid Build Coastguard Worker  %iptr1 = bitcast i8* %gep1 to i64*
1535*9880d681SAndroid Build Coastguard Worker  %iptr2 = bitcast i8* %gep2 to i64*
1536*9880d681SAndroid Build Coastguard Worker  %fptr1 = bitcast i8* %gep1 to float*
1537*9880d681SAndroid Build Coastguard Worker  %fptr2 = bitcast i8* %gep2 to float*
1538*9880d681SAndroid Build Coastguard Worker  %fptr3 = bitcast i8* %gep3 to float*
1539*9880d681SAndroid Build Coastguard Worker  store float 0.0, float* %fptr1
1540*9880d681SAndroid Build Coastguard Worker  store float 1.0, float* %fptr2
1541*9880d681SAndroid Build Coastguard Worker  %v = load i64, i64* %iptr1
1542*9880d681SAndroid Build Coastguard Worker  store i64 %v, i64* %iptr2
1543*9880d681SAndroid Build Coastguard Worker  %f1 = load float, float* %fptr2
1544*9880d681SAndroid Build Coastguard Worker  %f2 = load float, float* %fptr3
1545*9880d681SAndroid Build Coastguard Worker  %ret = fadd float %f1, %f2
1546*9880d681SAndroid Build Coastguard Worker  ret float %ret
1547*9880d681SAndroid Build Coastguard Worker}
1548*9880d681SAndroid Build Coastguard Worker
1549*9880d681SAndroid Build Coastguard Workerdefine i32 @PR22093() {
1550*9880d681SAndroid Build Coastguard Worker; Test that we don't try to pre-split a splittable store of a splittable but
1551*9880d681SAndroid Build Coastguard Worker; not pre-splittable load over the same alloca. We "handle" this case when the
1552*9880d681SAndroid Build Coastguard Worker; load is unsplittable but unrelated to this alloca by just generating extra
1553*9880d681SAndroid Build Coastguard Worker; loads without touching the original, but when the original load was out of
1554*9880d681SAndroid Build Coastguard Worker; this alloca we need to handle it specially to ensure the splits line up
1555*9880d681SAndroid Build Coastguard Worker; properly for rewriting.
1556*9880d681SAndroid Build Coastguard Worker;
1557*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @PR22093(
1558*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
1559*9880d681SAndroid Build Coastguard Worker; CHECK: alloca i16
1560*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
1561*9880d681SAndroid Build Coastguard Worker; CHECK: store volatile i16
1562*9880d681SAndroid Build Coastguard Worker
1563*9880d681SAndroid Build Coastguard Workerentry:
1564*9880d681SAndroid Build Coastguard Worker  %a = alloca i32
1565*9880d681SAndroid Build Coastguard Worker  %a.cast = bitcast i32* %a to i16*
1566*9880d681SAndroid Build Coastguard Worker  store volatile i16 42, i16* %a.cast
1567*9880d681SAndroid Build Coastguard Worker  %load = load i32, i32* %a
1568*9880d681SAndroid Build Coastguard Worker  store i32 %load, i32* %a
1569*9880d681SAndroid Build Coastguard Worker  ret i32 %load
1570*9880d681SAndroid Build Coastguard Worker}
1571*9880d681SAndroid Build Coastguard Worker
1572*9880d681SAndroid Build Coastguard Workerdefine void @PR22093.2() {
1573*9880d681SAndroid Build Coastguard Worker; Another way that we end up being unable to split a particular set of loads
1574*9880d681SAndroid Build Coastguard Worker; and stores can even have ordering importance. Here we have a load which is
1575*9880d681SAndroid Build Coastguard Worker; pre-splittable by itself, and the first store is also compatible. But the
1576*9880d681SAndroid Build Coastguard Worker; second store of the load makes the load unsplittable because of a mismatch of
1577*9880d681SAndroid Build Coastguard Worker; splits. Because this makes the load unsplittable, we also have to go back and
1578*9880d681SAndroid Build Coastguard Worker; remove the first store from the presplit candidates as its load won't be
1579*9880d681SAndroid Build Coastguard Worker; presplit.
1580*9880d681SAndroid Build Coastguard Worker;
1581*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @PR22093.2(
1582*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
1583*9880d681SAndroid Build Coastguard Worker; CHECK: alloca i16
1584*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: alloca i8
1585*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
1586*9880d681SAndroid Build Coastguard Worker; CHECK: store volatile i16
1587*9880d681SAndroid Build Coastguard Worker; CHECK: store volatile i8
1588*9880d681SAndroid Build Coastguard Worker
1589*9880d681SAndroid Build Coastguard Workerentry:
1590*9880d681SAndroid Build Coastguard Worker  %a = alloca i64
1591*9880d681SAndroid Build Coastguard Worker  %a.cast1 = bitcast i64* %a to i32*
1592*9880d681SAndroid Build Coastguard Worker  %a.cast2 = bitcast i64* %a to i16*
1593*9880d681SAndroid Build Coastguard Worker  store volatile i16 42, i16* %a.cast2
1594*9880d681SAndroid Build Coastguard Worker  %load = load i32, i32* %a.cast1
1595*9880d681SAndroid Build Coastguard Worker  store i32 %load, i32* %a.cast1
1596*9880d681SAndroid Build Coastguard Worker  %a.gep1 = getelementptr i32, i32* %a.cast1, i32 1
1597*9880d681SAndroid Build Coastguard Worker  %a.cast3 = bitcast i32* %a.gep1 to i8*
1598*9880d681SAndroid Build Coastguard Worker  store volatile i8 13, i8* %a.cast3
1599*9880d681SAndroid Build Coastguard Worker  store i32 %load, i32* %a.gep1
1600*9880d681SAndroid Build Coastguard Worker  ret void
1601*9880d681SAndroid Build Coastguard Worker}
1602*9880d681SAndroid Build Coastguard Worker
1603*9880d681SAndroid Build Coastguard Workerdefine void @PR23737() {
1604*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @PR23737(
1605*9880d681SAndroid Build Coastguard Worker; CHECK: store atomic volatile {{.*}} seq_cst
1606*9880d681SAndroid Build Coastguard Worker; CHECK: load atomic volatile {{.*}} seq_cst
1607*9880d681SAndroid Build Coastguard Workerentry:
1608*9880d681SAndroid Build Coastguard Worker  %ptr = alloca i64, align 8
1609*9880d681SAndroid Build Coastguard Worker  store atomic volatile i64 0, i64* %ptr seq_cst, align 8
1610*9880d681SAndroid Build Coastguard Worker  %load = load atomic volatile i64, i64* %ptr seq_cst, align 8
1611*9880d681SAndroid Build Coastguard Worker  ret void
1612*9880d681SAndroid Build Coastguard Worker}
1613*9880d681SAndroid Build Coastguard Worker
1614*9880d681SAndroid Build Coastguard Workerdefine i16 @PR24463() {
1615*9880d681SAndroid Build Coastguard Worker; Ensure we can handle a very interesting case where there is an integer-based
1616*9880d681SAndroid Build Coastguard Worker; rewrite of the uses of the alloca, but where one of the integers in that is
1617*9880d681SAndroid Build Coastguard Worker; a sub-integer that requires extraction *and* extends past the end of the
1618*9880d681SAndroid Build Coastguard Worker; alloca. In this case, we should extract the i8 and then zext it to i16.
1619*9880d681SAndroid Build Coastguard Worker;
1620*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @PR24463(
1621*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: alloca
1622*9880d681SAndroid Build Coastguard Worker; CHECK: %[[SHIFT:.*]] = lshr i16 0, 8
1623*9880d681SAndroid Build Coastguard Worker; CHECK: %[[TRUNC:.*]] = trunc i16 %[[SHIFT]] to i8
1624*9880d681SAndroid Build Coastguard Worker; CHECK: %[[ZEXT:.*]] = zext i8 %[[TRUNC]] to i16
1625*9880d681SAndroid Build Coastguard Worker; CHECK: ret i16 %[[ZEXT]]
1626*9880d681SAndroid Build Coastguard Workerentry:
1627*9880d681SAndroid Build Coastguard Worker  %alloca = alloca [3 x i8]
1628*9880d681SAndroid Build Coastguard Worker  %gep1 = getelementptr inbounds [3 x i8], [3 x i8]* %alloca, i64 0, i64 1
1629*9880d681SAndroid Build Coastguard Worker  %bc1 = bitcast i8* %gep1 to i16*
1630*9880d681SAndroid Build Coastguard Worker  store i16 0, i16* %bc1
1631*9880d681SAndroid Build Coastguard Worker  %gep2 = getelementptr inbounds [3 x i8], [3 x i8]* %alloca, i64 0, i64 2
1632*9880d681SAndroid Build Coastguard Worker  %bc2 = bitcast i8* %gep2 to i16*
1633*9880d681SAndroid Build Coastguard Worker  %load = load i16, i16* %bc2
1634*9880d681SAndroid Build Coastguard Worker  ret i16 %load
1635*9880d681SAndroid Build Coastguard Worker}
1636*9880d681SAndroid Build Coastguard Worker
1637*9880d681SAndroid Build Coastguard Worker%struct.STest = type { %struct.SPos, %struct.SPos }
1638*9880d681SAndroid Build Coastguard Worker%struct.SPos = type { float, float }
1639*9880d681SAndroid Build Coastguard Worker
1640*9880d681SAndroid Build Coastguard Workerdefine void @PR25873(%struct.STest* %outData) {
1641*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @PR25873(
1642*9880d681SAndroid Build Coastguard Worker; CHECK: store i32 1123418112
1643*9880d681SAndroid Build Coastguard Worker; CHECK: store i32 1139015680
1644*9880d681SAndroid Build Coastguard Worker; CHECK: %[[HIZEXT:.*]] = zext i32 1139015680 to i64
1645*9880d681SAndroid Build Coastguard Worker; CHECK: %[[HISHL:.*]] = shl i64 %[[HIZEXT]], 32
1646*9880d681SAndroid Build Coastguard Worker; CHECK: %[[HIMASK:.*]] = and i64 undef, 4294967295
1647*9880d681SAndroid Build Coastguard Worker; CHECK: %[[HIINSERT:.*]] = or i64 %[[HIMASK]], %[[HISHL]]
1648*9880d681SAndroid Build Coastguard Worker; CHECK: %[[LOZEXT:.*]] = zext i32 1123418112 to i64
1649*9880d681SAndroid Build Coastguard Worker; CHECK: %[[LOMASK:.*]] = and i64 %[[HIINSERT]], -4294967296
1650*9880d681SAndroid Build Coastguard Worker; CHECK: %[[LOINSERT:.*]] = or i64 %[[LOMASK]], %[[LOZEXT]]
1651*9880d681SAndroid Build Coastguard Worker; CHECK: store i64 %[[LOINSERT]]
1652*9880d681SAndroid Build Coastguard Workerentry:
1653*9880d681SAndroid Build Coastguard Worker  %tmpData = alloca %struct.STest, align 8
1654*9880d681SAndroid Build Coastguard Worker  %0 = bitcast %struct.STest* %tmpData to i8*
1655*9880d681SAndroid Build Coastguard Worker  call void @llvm.lifetime.start(i64 16, i8* %0)
1656*9880d681SAndroid Build Coastguard Worker  %x = getelementptr inbounds %struct.STest, %struct.STest* %tmpData, i64 0, i32 0, i32 0
1657*9880d681SAndroid Build Coastguard Worker  store float 1.230000e+02, float* %x, align 8
1658*9880d681SAndroid Build Coastguard Worker  %y = getelementptr inbounds %struct.STest, %struct.STest* %tmpData, i64 0, i32 0, i32 1
1659*9880d681SAndroid Build Coastguard Worker  store float 4.560000e+02, float* %y, align 4
1660*9880d681SAndroid Build Coastguard Worker  %m_posB = getelementptr inbounds %struct.STest, %struct.STest* %tmpData, i64 0, i32 1
1661*9880d681SAndroid Build Coastguard Worker  %1 = bitcast %struct.STest* %tmpData to i64*
1662*9880d681SAndroid Build Coastguard Worker  %2 = bitcast %struct.SPos* %m_posB to i64*
1663*9880d681SAndroid Build Coastguard Worker  %3 = load i64, i64* %1, align 8
1664*9880d681SAndroid Build Coastguard Worker  store i64 %3, i64* %2, align 8
1665*9880d681SAndroid Build Coastguard Worker  %4 = bitcast %struct.STest* %outData to i8*
1666*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %4, i8* %0, i64 16, i32 4, i1 false)
1667*9880d681SAndroid Build Coastguard Worker  call void @llvm.lifetime.end(i64 16, i8* %0)
1668*9880d681SAndroid Build Coastguard Worker  ret void
1669*9880d681SAndroid Build Coastguard Worker}
1670*9880d681SAndroid Build Coastguard Worker
1671*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
1672