Tim Northover | 51dbecf | 2013-02-07 15:39:16 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm < %s | FileCheck %s |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 2 | |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 3 | int S; |
| 4 | volatile int vS; |
| 5 | |
| 6 | int* pS; |
| 7 | volatile int* pvS; |
| 8 | |
| 9 | int A[10]; |
| 10 | volatile int vA[10]; |
| 11 | |
| 12 | struct { int x; } F; |
| 13 | struct { volatile int x; } vF; |
| 14 | |
| 15 | struct { int x; } F2; |
| 16 | volatile struct { int x; } vF2; |
| 17 | volatile struct { int x; } *vpF2; |
| 18 | |
| 19 | struct { struct { int y; } x; } F3; |
| 20 | volatile struct { struct { int y; } x; } vF3; |
| 21 | |
| 22 | struct { int x:3; } BF; |
| 23 | struct { volatile int x:3; } vBF; |
| 24 | |
| 25 | typedef int v4si __attribute__ ((vector_size (16))); |
| 26 | v4si V; |
| 27 | volatile v4si vV; |
| 28 | |
| 29 | typedef __attribute__(( ext_vector_type(4) )) int extv4; |
| 30 | extv4 VE; |
| 31 | volatile extv4 vVE; |
| 32 | |
| 33 | volatile struct {int x;} aggFct(void); |
| 34 | |
Mike Stump | cb9b010 | 2009-11-03 23:32:42 +0000 | [diff] [blame] | 35 | typedef volatile int volatile_int; |
| 36 | volatile_int vtS; |
| 37 | |
John McCall | 13591ed | 2009-07-25 04:36:53 +0000 | [diff] [blame] | 38 | int main() { |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 39 | int i; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 40 | // CHECK: [[I:%[a-zA-Z0-9_.]+]] = alloca i32 |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 41 | // load |
| 42 | i=S; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 43 | // CHECK: load i32* @S |
| 44 | // CHECK: store i32 {{.*}}, i32* [[I]] |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 45 | i=vS; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 46 | // CHECK: load volatile i32* @vS |
| 47 | // CHECK: store i32 {{.*}}, i32* [[I]] |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 48 | i=*pS; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 49 | // CHECK: [[PS_VAL:%[a-zA-Z0-9_.]+]] = load i32** @pS |
| 50 | // CHECK: load i32* [[PS_VAL]] |
| 51 | // CHECK: store i32 {{.*}}, i32* [[I]] |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 52 | i=*pvS; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 53 | // CHECK: [[PVS_VAL:%[a-zA-Z0-9_.]+]] = load i32** @pvS |
| 54 | // CHECK: load volatile i32* [[PVS_VAL]] |
| 55 | // CHECK: store i32 {{.*}}, i32* [[I]] |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 56 | i=A[2]; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 57 | // CHECK: load i32* getelementptr {{.*}} @A |
| 58 | // CHECK: store i32 {{.*}}, i32* [[I]] |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 59 | i=vA[2]; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 60 | // CHECK: load volatile i32* getelementptr {{.*}} @vA |
| 61 | // CHECK: store i32 {{.*}}, i32* [[I]] |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 62 | i=F.x; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 63 | // CHECK: load i32* getelementptr {{.*}} @F |
| 64 | // CHECK: store i32 {{.*}}, i32* [[I]] |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 65 | i=vF.x; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 66 | // CHECK: load volatile i32* getelementptr {{.*}} @vF |
| 67 | // CHECK: store i32 {{.*}}, i32* [[I]] |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 68 | i=F2.x; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 69 | // CHECK: load i32* getelementptr {{.*}} @F2 |
| 70 | // CHECK: store i32 {{.*}}, i32* [[I]] |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 71 | i=vF2.x; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 72 | // CHECK: load volatile i32* getelementptr {{.*}} @vF2 |
| 73 | // CHECK: store i32 {{.*}}, i32* [[I]] |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 74 | i=vpF2->x; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 75 | // 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 Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 79 | i=F3.x.y; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 80 | // CHECK: load i32* getelementptr {{.*}} @F3 |
| 81 | // CHECK: store i32 {{.*}}, i32* [[I]] |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 82 | i=vF3.x.y; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 83 | // CHECK: load volatile i32* getelementptr {{.*}} @vF3 |
| 84 | // CHECK: store i32 {{.*}}, i32* [[I]] |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 85 | i=BF.x; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 86 | // CHECK: load i8* getelementptr {{.*}} @BF |
| 87 | // CHECK: store i32 {{.*}}, i32* [[I]] |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 88 | i=vBF.x; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 89 | // CHECK: load volatile i8* getelementptr {{.*}} @vBF |
| 90 | // CHECK: store i32 {{.*}}, i32* [[I]] |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 91 | i=V[3]; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 92 | // CHECK: load <4 x i32>* @V |
| 93 | // CHECK: store i32 {{.*}}, i32* [[I]] |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 94 | i=vV[3]; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 95 | // CHECK: load volatile <4 x i32>* @vV |
| 96 | // CHECK: store i32 {{.*}}, i32* [[I]] |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 97 | i=VE.yx[1]; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 98 | // CHECK: load <4 x i32>* @VE |
| 99 | // CHECK: store i32 {{.*}}, i32* [[I]] |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 100 | i=vVE.zy[1]; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 101 | // CHECK: load volatile <4 x i32>* @vVE |
| 102 | // CHECK: store i32 {{.*}}, i32* [[I]] |
Douglas Gregor | 5291c3c | 2010-07-13 08:18:22 +0000 | [diff] [blame] | 103 | i = aggFct().x; // Note: not volatile |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 104 | // 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 Stump | cb9b010 | 2009-11-03 23:32:42 +0000 | [diff] [blame] | 109 | i=vtS; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 110 | // CHECK: load volatile i32* @vtS |
| 111 | // CHECK: store i32 {{.*}}, i32* [[I]] |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 112 | |
| 113 | |
| 114 | // store |
| 115 | S=i; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 116 | // CHECK: load i32* [[I]] |
| 117 | // CHECK: store i32 {{.*}}, i32* @S |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 118 | vS=i; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 119 | // CHECK: load i32* [[I]] |
| 120 | // CHECK: store volatile i32 {{.*}}, i32* @vS |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 121 | *pS=i; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 122 | // CHECK: load i32* [[I]] |
| 123 | // CHECK: [[PS_VAL:%[a-zA-Z0-9_.]+]] = load i32** @pS |
| 124 | // CHECK: store i32 {{.*}}, i32* [[PS_VAL]] |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 125 | *pvS=i; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 126 | // CHECK: load i32* [[I]] |
| 127 | // CHECK: [[PVS_VAL:%[a-zA-Z0-9_.]+]] = load i32** @pvS |
| 128 | // CHECK: store volatile i32 {{.*}}, i32* [[PVS_VAL]] |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 129 | A[2]=i; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 130 | // CHECK: load i32* [[I]] |
| 131 | // CHECK: store i32 {{.*}}, i32* getelementptr {{.*}} @A |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 132 | vA[2]=i; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 133 | // CHECK: load i32* [[I]] |
| 134 | // CHECK: store volatile i32 {{.*}}, i32* getelementptr {{.*}} @vA |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 135 | F.x=i; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 136 | // CHECK: load i32* [[I]] |
| 137 | // CHECK: store i32 {{.*}}, i32* getelementptr {{.*}} @F |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 138 | vF.x=i; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 139 | // CHECK: load i32* [[I]] |
| 140 | // CHECK: store volatile i32 {{.*}}, i32* getelementptr {{.*}} @vF |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 141 | F2.x=i; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 142 | // CHECK: load i32* [[I]] |
| 143 | // CHECK: store i32 {{.*}}, i32* getelementptr {{.*}} @F2 |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 144 | vF2.x=i; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 145 | // CHECK: load i32* [[I]] |
| 146 | // CHECK: store volatile i32 {{.*}}, i32* getelementptr {{.*}} @vF2 |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 147 | vpF2->x=i; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 148 | // 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 Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 152 | vF3.x.y=i; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 153 | // CHECK: load i32* [[I]] |
| 154 | // CHECK: store volatile i32 {{.*}}, i32* getelementptr {{.*}} @vF3 |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 155 | BF.x=i; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 156 | // CHECK: load i32* [[I]] |
| 157 | // CHECK: load i8* getelementptr {{.*}} @BF |
| 158 | // CHECK: store i8 {{.*}}, i8* getelementptr {{.*}} @BF |
Daniel Dunbar | ed3849b | 2008-11-19 09:36:46 +0000 | [diff] [blame] | 159 | vBF.x=i; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 160 | // CHECK: load i32* [[I]] |
| 161 | // CHECK: load volatile i8* getelementptr {{.*}} @vBF |
| 162 | // CHECK: store volatile i8 {{.*}}, i8* getelementptr {{.*}} @vBF |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 163 | V[3]=i; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 164 | // CHECK: load i32* [[I]] |
| 165 | // CHECK: load <4 x i32>* @V |
| 166 | // CHECK: store <4 x i32> {{.*}}, <4 x i32>* @V |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 167 | vV[3]=i; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 168 | // CHECK: load i32* [[I]] |
| 169 | // CHECK: load volatile <4 x i32>* @vV |
| 170 | // CHECK: store volatile <4 x i32> {{.*}}, <4 x i32>* @vV |
Mike Stump | cb9b010 | 2009-11-03 23:32:42 +0000 | [diff] [blame] | 171 | vtS=i; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 172 | // CHECK: load i32* [[I]] |
| 173 | // CHECK: store volatile i32 {{.*}}, i32* @vtS |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 174 | |
| 175 | // other ops: |
| 176 | ++S; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 177 | // CHECK: load i32* @S |
| 178 | // CHECK: store i32 {{.*}}, i32* @S |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 179 | ++vS; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 180 | // CHECK: load volatile i32* @vS |
| 181 | // CHECK: store volatile i32 {{.*}}, i32* @vS |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 182 | i+=S; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 183 | // CHECK: load i32* @S |
| 184 | // CHECK: load i32* [[I]] |
| 185 | // CHECK: store i32 {{.*}}, i32* [[I]] |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 186 | i+=vS; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 187 | // CHECK: load volatile i32* @vS |
| 188 | // CHECK: load i32* [[I]] |
| 189 | // CHECK: store i32 {{.*}}, i32* [[I]] |
Mike Stump | cb9b010 | 2009-11-03 23:32:42 +0000 | [diff] [blame] | 190 | ++vtS; |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 191 | // CHECK: load volatile i32* @vtS |
| 192 | // CHECK: store volatile i32 {{.*}}, i32* @vtS |
Mike Stump | 49d1cd5 | 2009-05-26 22:03:21 +0000 | [diff] [blame] | 193 | (void)vF2; |
Tim Northover | 51dbecf | 2013-02-07 15:39:16 +0000 | [diff] [blame] | 194 | // From vF2 to a temporary |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 195 | // CHECK: call void @llvm.memcpy.{{.*}}(i8* %{{.*}}, i8* {{.*}} @vF2 {{.*}}, i1 true) |
Mike Stump | 49d1cd5 | 2009-05-26 22:03:21 +0000 | [diff] [blame] | 196 | vF2 = vF2; |
Tim Northover | 51dbecf | 2013-02-07 15:39:16 +0000 | [diff] [blame] | 197 | // vF2 to itself |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 198 | // CHECK: call void @llvm.memcpy.{{.*}}(i8* {{.*@vF2.*}}, i8* {{.*@vF2.*}}, i1 true) |
Mike Stump | 49d1cd5 | 2009-05-26 22:03:21 +0000 | [diff] [blame] | 199 | vF2 = vF2 = vF2; |
Tim Northover | 51dbecf | 2013-02-07 15:39:16 +0000 | [diff] [blame] | 200 | // vF2 to itself twice |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 201 | // CHECK: call void @llvm.memcpy.{{.*}}(i8* {{.*@vF2.*}}, i8* {{.*@vF2.*}}, i1 true) |
| 202 | // CHECK: call void @llvm.memcpy.{{.*}}(i8* {{.*@vF2.*}}, i8* {{.*@vF2.*}}, i1 true) |
Argyrios Kyrtzidis | 8028bfa | 2010-08-25 23:42:51 +0000 | [diff] [blame] | 203 | vF2 = (vF2, vF2); |
Tim Northover | 51dbecf | 2013-02-07 15:39:16 +0000 | [diff] [blame] | 204 | // vF2 to a temporary, then vF2 to itself |
Tim Northover | 026ce82 | 2013-02-08 08:00:13 +0000 | [diff] [blame] | 205 | // CHECK: call void @llvm.memcpy.{{.*}}(i8* %{{.*}}, i8* {{.*@vF2.*}}, i1 true) |
| 206 | // CHECK: call void @llvm.memcpy.{{.*}}(i8* {{.*@vF2.*}}, i8* {{.*@vF2.*}}, i1 true) |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame] | 207 | } |