blob: 0dcdc15c77a65cceb97ba410664e159f7c16dbfd [file] [log] [blame]
Tim Northover51dbecf2013-02-07 15:39:16 +00001// RUN: %clang_cc1 -emit-llvm < %s | FileCheck %s
Eli Friedman1e692ac2008-06-13 23:01:12 +00002
Eli Friedman1e692ac2008-06-13 23:01:12 +00003int S;
4volatile int vS;
5
6int* pS;
7volatile int* pvS;
8
9int A[10];
10volatile int vA[10];
11
12struct { int x; } F;
13struct { volatile int x; } vF;
14
15struct { int x; } F2;
16volatile struct { int x; } vF2;
17volatile struct { int x; } *vpF2;
18
19struct { struct { int y; } x; } F3;
20volatile struct { struct { int y; } x; } vF3;
21
22struct { int x:3; } BF;
23struct { volatile int x:3; } vBF;
24
25typedef int v4si __attribute__ ((vector_size (16)));
26v4si V;
27volatile v4si vV;
28
29typedef __attribute__(( ext_vector_type(4) )) int extv4;
30extv4 VE;
31volatile extv4 vVE;
32
33volatile struct {int x;} aggFct(void);
34
Mike Stumpcb9b0102009-11-03 23:32:42 +000035typedef volatile int volatile_int;
36volatile_int vtS;
37
John McCall13591ed2009-07-25 04:36:53 +000038int main() {
Eli Friedman1e692ac2008-06-13 23:01:12 +000039 int i;
Tim Northover026ce822013-02-08 08:00:13 +000040// CHECK: [[I:%[a-zA-Z0-9_.]+]] = alloca i32
Eli Friedman1e692ac2008-06-13 23:01:12 +000041 // load
42 i=S;
Tim Northover026ce822013-02-08 08:00:13 +000043// CHECK: load i32* @S
44// CHECK: store i32 {{.*}}, i32* [[I]]
Eli Friedman1e692ac2008-06-13 23:01:12 +000045 i=vS;
Tim Northover026ce822013-02-08 08:00:13 +000046// CHECK: load volatile i32* @vS
47// CHECK: store i32 {{.*}}, i32* [[I]]
Eli Friedman1e692ac2008-06-13 23:01:12 +000048 i=*pS;
Tim Northover026ce822013-02-08 08:00:13 +000049// CHECK: [[PS_VAL:%[a-zA-Z0-9_.]+]] = load i32** @pS
50// CHECK: load i32* [[PS_VAL]]
51// CHECK: store i32 {{.*}}, i32* [[I]]
Eli Friedman1e692ac2008-06-13 23:01:12 +000052 i=*pvS;
Tim Northover026ce822013-02-08 08:00:13 +000053// CHECK: [[PVS_VAL:%[a-zA-Z0-9_.]+]] = load i32** @pvS
54// CHECK: load volatile i32* [[PVS_VAL]]
55// CHECK: store i32 {{.*}}, i32* [[I]]
Eli Friedman1e692ac2008-06-13 23:01:12 +000056 i=A[2];
Tim Northover026ce822013-02-08 08:00:13 +000057// CHECK: load i32* getelementptr {{.*}} @A
58// CHECK: store i32 {{.*}}, i32* [[I]]
Eli Friedman1e692ac2008-06-13 23:01:12 +000059 i=vA[2];
Tim Northover026ce822013-02-08 08:00:13 +000060// CHECK: load volatile i32* getelementptr {{.*}} @vA
61// CHECK: store i32 {{.*}}, i32* [[I]]
Eli Friedman1e692ac2008-06-13 23:01:12 +000062 i=F.x;
Tim Northover026ce822013-02-08 08:00:13 +000063// CHECK: load i32* getelementptr {{.*}} @F
64// CHECK: store i32 {{.*}}, i32* [[I]]
Eli Friedman1e692ac2008-06-13 23:01:12 +000065 i=vF.x;
Tim Northover026ce822013-02-08 08:00:13 +000066// CHECK: load volatile i32* getelementptr {{.*}} @vF
67// CHECK: store i32 {{.*}}, i32* [[I]]
Eli Friedman1e692ac2008-06-13 23:01:12 +000068 i=F2.x;
Tim Northover026ce822013-02-08 08:00:13 +000069// CHECK: load i32* getelementptr {{.*}} @F2
70// CHECK: store i32 {{.*}}, i32* [[I]]
Eli Friedman1e692ac2008-06-13 23:01:12 +000071 i=vF2.x;
Tim Northover026ce822013-02-08 08:00:13 +000072// CHECK: load volatile i32* getelementptr {{.*}} @vF2
73// CHECK: store i32 {{.*}}, i32* [[I]]
Eli Friedman1e692ac2008-06-13 23:01:12 +000074 i=vpF2->x;
Tim Northover026ce822013-02-08 08:00:13 +000075// CHECK: [[VPF2_VAL:%[a-zA-Z0-9_.]+]] = load {{%[a-zA-Z0-9_.]+}}** @vpF2
76// CHECK: [[ELT:%[a-zA-Z0-9_.]+]] = getelementptr {{.*}} [[VPF2_VAL]]
77// CHECK: load volatile i32* [[ELT]]
78// CHECK: store i32 {{.*}}, i32* [[I]]
Eli Friedman1e692ac2008-06-13 23:01:12 +000079 i=F3.x.y;
Tim Northover026ce822013-02-08 08:00:13 +000080// CHECK: load i32* getelementptr {{.*}} @F3
81// CHECK: store i32 {{.*}}, i32* [[I]]
Eli Friedman1e692ac2008-06-13 23:01:12 +000082 i=vF3.x.y;
Tim Northover026ce822013-02-08 08:00:13 +000083// CHECK: load volatile i32* getelementptr {{.*}} @vF3
84// CHECK: store i32 {{.*}}, i32* [[I]]
Eli Friedman1e692ac2008-06-13 23:01:12 +000085 i=BF.x;
Tim Northover026ce822013-02-08 08:00:13 +000086// CHECK: load i8* getelementptr {{.*}} @BF
87// CHECK: store i32 {{.*}}, i32* [[I]]
Eli Friedman1e692ac2008-06-13 23:01:12 +000088 i=vBF.x;
Tim Northover026ce822013-02-08 08:00:13 +000089// CHECK: load volatile i8* getelementptr {{.*}} @vBF
90// CHECK: store i32 {{.*}}, i32* [[I]]
Eli Friedman1e692ac2008-06-13 23:01:12 +000091 i=V[3];
Tim Northover026ce822013-02-08 08:00:13 +000092// CHECK: load <4 x i32>* @V
93// CHECK: store i32 {{.*}}, i32* [[I]]
Eli Friedman1e692ac2008-06-13 23:01:12 +000094 i=vV[3];
Tim Northover026ce822013-02-08 08:00:13 +000095// CHECK: load volatile <4 x i32>* @vV
96// CHECK: store i32 {{.*}}, i32* [[I]]
Eli Friedman1e692ac2008-06-13 23:01:12 +000097 i=VE.yx[1];
Tim Northover026ce822013-02-08 08:00:13 +000098// CHECK: load <4 x i32>* @VE
99// CHECK: store i32 {{.*}}, i32* [[I]]
Eli Friedman1e692ac2008-06-13 23:01:12 +0000100 i=vVE.zy[1];
Tim Northover026ce822013-02-08 08:00:13 +0000101// CHECK: load volatile <4 x i32>* @vVE
102// CHECK: store i32 {{.*}}, i32* [[I]]
Douglas Gregor5291c3c2010-07-13 08:18:22 +0000103 i = aggFct().x; // Note: not volatile
Tim Northover026ce822013-02-08 08:00:13 +0000104 // N.b. Aggregate return is extremely target specific, all we can
105 // really say here is that there probably shouldn't be a volatile
106 // load.
107// CHECK-NOT: load volatile
108// CHECK: store i32 {{.*}}, i32* [[I]]
Mike Stumpcb9b0102009-11-03 23:32:42 +0000109 i=vtS;
Tim Northover026ce822013-02-08 08:00:13 +0000110// CHECK: load volatile i32* @vtS
111// CHECK: store i32 {{.*}}, i32* [[I]]
Eli Friedman1e692ac2008-06-13 23:01:12 +0000112
113
114 // store
115 S=i;
Tim Northover026ce822013-02-08 08:00:13 +0000116// CHECK: load i32* [[I]]
117// CHECK: store i32 {{.*}}, i32* @S
Eli Friedman1e692ac2008-06-13 23:01:12 +0000118 vS=i;
Tim Northover026ce822013-02-08 08:00:13 +0000119// CHECK: load i32* [[I]]
120// CHECK: store volatile i32 {{.*}}, i32* @vS
Eli Friedman1e692ac2008-06-13 23:01:12 +0000121 *pS=i;
Tim Northover026ce822013-02-08 08:00:13 +0000122// CHECK: load i32* [[I]]
123// CHECK: [[PS_VAL:%[a-zA-Z0-9_.]+]] = load i32** @pS
124// CHECK: store i32 {{.*}}, i32* [[PS_VAL]]
Eli Friedman1e692ac2008-06-13 23:01:12 +0000125 *pvS=i;
Tim Northover026ce822013-02-08 08:00:13 +0000126// CHECK: load i32* [[I]]
127// CHECK: [[PVS_VAL:%[a-zA-Z0-9_.]+]] = load i32** @pvS
128// CHECK: store volatile i32 {{.*}}, i32* [[PVS_VAL]]
Eli Friedman1e692ac2008-06-13 23:01:12 +0000129 A[2]=i;
Tim Northover026ce822013-02-08 08:00:13 +0000130// CHECK: load i32* [[I]]
131// CHECK: store i32 {{.*}}, i32* getelementptr {{.*}} @A
Eli Friedman1e692ac2008-06-13 23:01:12 +0000132 vA[2]=i;
Tim Northover026ce822013-02-08 08:00:13 +0000133// CHECK: load i32* [[I]]
134// CHECK: store volatile i32 {{.*}}, i32* getelementptr {{.*}} @vA
Eli Friedman1e692ac2008-06-13 23:01:12 +0000135 F.x=i;
Tim Northover026ce822013-02-08 08:00:13 +0000136// CHECK: load i32* [[I]]
137// CHECK: store i32 {{.*}}, i32* getelementptr {{.*}} @F
Eli Friedman1e692ac2008-06-13 23:01:12 +0000138 vF.x=i;
Tim Northover026ce822013-02-08 08:00:13 +0000139// CHECK: load i32* [[I]]
140// CHECK: store volatile i32 {{.*}}, i32* getelementptr {{.*}} @vF
Eli Friedman1e692ac2008-06-13 23:01:12 +0000141 F2.x=i;
Tim Northover026ce822013-02-08 08:00:13 +0000142// CHECK: load i32* [[I]]
143// CHECK: store i32 {{.*}}, i32* getelementptr {{.*}} @F2
Eli Friedman1e692ac2008-06-13 23:01:12 +0000144 vF2.x=i;
Tim Northover026ce822013-02-08 08:00:13 +0000145// CHECK: load i32* [[I]]
146// CHECK: store volatile i32 {{.*}}, i32* getelementptr {{.*}} @vF2
Eli Friedman1e692ac2008-06-13 23:01:12 +0000147 vpF2->x=i;
Tim Northover026ce822013-02-08 08:00:13 +0000148// CHECK: load i32* [[I]]
149// CHECK: [[VPF2_VAL:%[a-zA-Z0-9_.]+]] = load {{%[a-zA-Z0-9._]+}}** @vpF2
150// CHECK: [[ELT:%[a-zA-Z0-9_.]+]] = getelementptr {{.*}} [[VPF2_VAL]]
151// CHECK: store volatile i32 {{.*}}, i32* [[ELT]]
Eli Friedman1e692ac2008-06-13 23:01:12 +0000152 vF3.x.y=i;
Tim Northover026ce822013-02-08 08:00:13 +0000153// CHECK: load i32* [[I]]
154// CHECK: store volatile i32 {{.*}}, i32* getelementptr {{.*}} @vF3
Eli Friedman1e692ac2008-06-13 23:01:12 +0000155 BF.x=i;
Tim Northover026ce822013-02-08 08:00:13 +0000156// CHECK: load i32* [[I]]
157// CHECK: load i8* getelementptr {{.*}} @BF
158// CHECK: store i8 {{.*}}, i8* getelementptr {{.*}} @BF
Daniel Dunbared3849b2008-11-19 09:36:46 +0000159 vBF.x=i;
Tim Northover026ce822013-02-08 08:00:13 +0000160// CHECK: load i32* [[I]]
161// CHECK: load volatile i8* getelementptr {{.*}} @vBF
162// CHECK: store volatile i8 {{.*}}, i8* getelementptr {{.*}} @vBF
Eli Friedman1e692ac2008-06-13 23:01:12 +0000163 V[3]=i;
Tim Northover026ce822013-02-08 08:00:13 +0000164// CHECK: load i32* [[I]]
165// CHECK: load <4 x i32>* @V
166// CHECK: store <4 x i32> {{.*}}, <4 x i32>* @V
Eli Friedman1e692ac2008-06-13 23:01:12 +0000167 vV[3]=i;
Tim Northover026ce822013-02-08 08:00:13 +0000168// CHECK: load i32* [[I]]
169// CHECK: load volatile <4 x i32>* @vV
170// CHECK: store volatile <4 x i32> {{.*}}, <4 x i32>* @vV
Mike Stumpcb9b0102009-11-03 23:32:42 +0000171 vtS=i;
Tim Northover026ce822013-02-08 08:00:13 +0000172// CHECK: load i32* [[I]]
173// CHECK: store volatile i32 {{.*}}, i32* @vtS
Eli Friedman1e692ac2008-06-13 23:01:12 +0000174
175 // other ops:
176 ++S;
Tim Northover026ce822013-02-08 08:00:13 +0000177// CHECK: load i32* @S
178// CHECK: store i32 {{.*}}, i32* @S
Eli Friedman1e692ac2008-06-13 23:01:12 +0000179 ++vS;
Tim Northover026ce822013-02-08 08:00:13 +0000180// CHECK: load volatile i32* @vS
181// CHECK: store volatile i32 {{.*}}, i32* @vS
Eli Friedman1e692ac2008-06-13 23:01:12 +0000182 i+=S;
Tim Northover026ce822013-02-08 08:00:13 +0000183// CHECK: load i32* @S
184// CHECK: load i32* [[I]]
185// CHECK: store i32 {{.*}}, i32* [[I]]
Eli Friedman1e692ac2008-06-13 23:01:12 +0000186 i+=vS;
Tim Northover026ce822013-02-08 08:00:13 +0000187// CHECK: load volatile i32* @vS
188// CHECK: load i32* [[I]]
189// CHECK: store i32 {{.*}}, i32* [[I]]
Mike Stumpcb9b0102009-11-03 23:32:42 +0000190 ++vtS;
Tim Northover026ce822013-02-08 08:00:13 +0000191// CHECK: load volatile i32* @vtS
192// CHECK: store volatile i32 {{.*}}, i32* @vtS
Mike Stump49d1cd52009-05-26 22:03:21 +0000193 (void)vF2;
Tim Northover51dbecf2013-02-07 15:39:16 +0000194 // From vF2 to a temporary
Tim Northover026ce822013-02-08 08:00:13 +0000195// CHECK: call void @llvm.memcpy.{{.*}}(i8* %{{.*}}, i8* {{.*}} @vF2 {{.*}}, i1 true)
Mike Stump49d1cd52009-05-26 22:03:21 +0000196 vF2 = vF2;
Tim Northover51dbecf2013-02-07 15:39:16 +0000197 // vF2 to itself
Tim Northover026ce822013-02-08 08:00:13 +0000198// CHECK: call void @llvm.memcpy.{{.*}}(i8* {{.*@vF2.*}}, i8* {{.*@vF2.*}}, i1 true)
Mike Stump49d1cd52009-05-26 22:03:21 +0000199 vF2 = vF2 = vF2;
Tim Northover51dbecf2013-02-07 15:39:16 +0000200 // vF2 to itself twice
Tim Northover026ce822013-02-08 08:00:13 +0000201// CHECK: call void @llvm.memcpy.{{.*}}(i8* {{.*@vF2.*}}, i8* {{.*@vF2.*}}, i1 true)
202// CHECK: call void @llvm.memcpy.{{.*}}(i8* {{.*@vF2.*}}, i8* {{.*@vF2.*}}, i1 true)
Argyrios Kyrtzidis8028bfa2010-08-25 23:42:51 +0000203 vF2 = (vF2, vF2);
Tim Northover51dbecf2013-02-07 15:39:16 +0000204 // vF2 to a temporary, then vF2 to itself
Tim Northover026ce822013-02-08 08:00:13 +0000205// CHECK: call void @llvm.memcpy.{{.*}}(i8* %{{.*}}, i8* {{.*@vF2.*}}, i1 true)
206// CHECK: call void @llvm.memcpy.{{.*}}(i8* {{.*@vF2.*}}, i8* {{.*@vF2.*}}, i1 true)
Eli Friedman1e692ac2008-06-13 23:01:12 +0000207}