volatile-1.cpp revision 83ce9d4a552987d34cbd500e983db8d770232379
183ce9d4a552987d34cbd500e983db8d770232379John McCall// RUN: %clang_cc1 -Wno-unused-value -emit-llvm %s -o - | FileCheck %s 283ce9d4a552987d34cbd500e983db8d770232379John McCall 383ce9d4a552987d34cbd500e983db8d770232379John McCall// CHECK: @i = global [[INT:i[0-9]+]] 0 483ce9d4a552987d34cbd500e983db8d770232379John McCallvolatile int i, j, k; 583ce9d4a552987d34cbd500e983db8d770232379John McCallvolatile int ar[5]; 683ce9d4a552987d34cbd500e983db8d770232379John McCallvolatile char c; 783ce9d4a552987d34cbd500e983db8d770232379John McCall// CHECK: @ci = global [[CINT:%.*]] zeroinitializer 883ce9d4a552987d34cbd500e983db8d770232379John McCallvolatile _Complex int ci; 983ce9d4a552987d34cbd500e983db8d770232379John McCallvolatile struct S { 1083ce9d4a552987d34cbd500e983db8d770232379John McCall#ifdef __cplusplus 1183ce9d4a552987d34cbd500e983db8d770232379John McCall void operator =(volatile struct S&o) volatile; 1283ce9d4a552987d34cbd500e983db8d770232379John McCall#endif 1383ce9d4a552987d34cbd500e983db8d770232379John McCall int i; 1483ce9d4a552987d34cbd500e983db8d770232379John McCall} a, b; 1583ce9d4a552987d34cbd500e983db8d770232379John McCall 1683ce9d4a552987d34cbd500e983db8d770232379John McCall//void operator =(volatile struct S&o1, volatile struct S&o2) volatile; 1783ce9d4a552987d34cbd500e983db8d770232379John McCallint printf(const char *, ...); 1883ce9d4a552987d34cbd500e983db8d770232379John McCall 1983ce9d4a552987d34cbd500e983db8d770232379John McCall 2083ce9d4a552987d34cbd500e983db8d770232379John McCall// CHECK: define void @{{.*}}test 2183ce9d4a552987d34cbd500e983db8d770232379John McCallvoid test() { 2283ce9d4a552987d34cbd500e983db8d770232379John McCall 2383ce9d4a552987d34cbd500e983db8d770232379John McCall asm("nop"); // CHECK: call void asm 2483ce9d4a552987d34cbd500e983db8d770232379John McCall 2583ce9d4a552987d34cbd500e983db8d770232379John McCall // FIXME: should not load 2683ce9d4a552987d34cbd500e983db8d770232379John McCall i; 2783ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load [[INT]]* @i 2883ce9d4a552987d34cbd500e983db8d770232379John McCall 2983ce9d4a552987d34cbd500e983db8d770232379John McCall (float)(ci); 3083ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) 3183ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) 3283ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: sitofp [[INT]] 3383ce9d4a552987d34cbd500e983db8d770232379John McCall 3483ce9d4a552987d34cbd500e983db8d770232379John McCall // These are not uses in C++: 3583ce9d4a552987d34cbd500e983db8d770232379John McCall // [expr.static.cast]p6: 3683ce9d4a552987d34cbd500e983db8d770232379John McCall // The lvalue-to-rvalue . . . conversions are not applied to the expression. 3783ce9d4a552987d34cbd500e983db8d770232379John McCall (void)ci; 3883ce9d4a552987d34cbd500e983db8d770232379John McCall (void)a; 3983ce9d4a552987d34cbd500e983db8d770232379John McCall 4083ce9d4a552987d34cbd500e983db8d770232379John McCall (void)(ci=ci); 4183ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: [[R:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) 4283ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: [[I:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) 4383ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store [[INT]] [[R]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) 4483ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store [[INT]] [[I]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) 4583ce9d4a552987d34cbd500e983db8d770232379John McCall 4683ce9d4a552987d34cbd500e983db8d770232379John McCall (void)(i=j); 4783ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: [[T:%.*]] = volatile load [[INT]]* @j 4883ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store [[INT]] [[T]], [[INT]]* @i 4983ce9d4a552987d34cbd500e983db8d770232379John McCall 5083ce9d4a552987d34cbd500e983db8d770232379John McCall // FIXME: extra load at end! 5183ce9d4a552987d34cbd500e983db8d770232379John McCall ci+=ci; 5283ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: [[R1:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) 5383ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: [[I1:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) 5483ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: [[R2:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) 5583ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: [[I2:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) 5683ce9d4a552987d34cbd500e983db8d770232379John McCall // Not sure why they're ordered this way. 5783ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: [[R:%.*]] = add [[INT]] [[R2]], [[R1]] 5883ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: [[I:%.*]] = add [[INT]] [[I2]], [[I1]] 5983ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store [[INT]] [[R]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) 6083ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store [[INT]] [[I]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) 6183ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: [[R1:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) 6283ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: [[I1:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) 6383ce9d4a552987d34cbd500e983db8d770232379John McCall 6483ce9d4a552987d34cbd500e983db8d770232379John McCall // Note that C++ requires an extra volatile load over C from the LHS of the '+'. 6583ce9d4a552987d34cbd500e983db8d770232379John McCall (ci += ci) + ci; 6683ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: [[R1:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) 6783ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: [[I1:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) 6883ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: [[R2:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) 6983ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: [[I2:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) 7083ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: [[R:%.*]] = add [[INT]] [[R2]], [[R1]] 7183ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: [[I:%.*]] = add [[INT]] [[I2]], [[I1]] 7283ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store [[INT]] [[R]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) 7383ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store [[INT]] [[I]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) 7483ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: [[R1:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) 7583ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: [[I1:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) 7683ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: [[R2:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 0) 7783ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: [[I2:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) 7883ce9d4a552987d34cbd500e983db8d770232379John McCall // These additions can be elided. 7983ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: add [[INT]] [[R1]], [[R2]] 8083ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: add [[INT]] [[I1]], [[I2]] 8183ce9d4a552987d34cbd500e983db8d770232379John McCall 8283ce9d4a552987d34cbd500e983db8d770232379John McCall asm("nop"); // CHECK-NEXT: call void asm 8383ce9d4a552987d34cbd500e983db8d770232379John McCall 8483ce9d4a552987d34cbd500e983db8d770232379John McCall // Extra volatile load in C++. 8583ce9d4a552987d34cbd500e983db8d770232379John McCall (i += j) + k; 8683ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 8783ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 8883ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: add nsw [[INT]] 8983ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 9083ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 9183ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 9283ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: add nsw [[INT]] 9383ce9d4a552987d34cbd500e983db8d770232379John McCall 9483ce9d4a552987d34cbd500e983db8d770232379John McCall asm("nop"); // CHECK-NEXT: call void asm 9583ce9d4a552987d34cbd500e983db8d770232379John McCall 9683ce9d4a552987d34cbd500e983db8d770232379John McCall // Extra volatile load in C++. 9783ce9d4a552987d34cbd500e983db8d770232379John McCall (i += j) + 1; 9883ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 9983ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 10083ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: add nsw [[INT]] 10183ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 10283ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 10383ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: add nsw [[INT]] 10483ce9d4a552987d34cbd500e983db8d770232379John McCall 10583ce9d4a552987d34cbd500e983db8d770232379John McCall asm("nop"); // CHECK-NEXT: call void asm 10683ce9d4a552987d34cbd500e983db8d770232379John McCall 10783ce9d4a552987d34cbd500e983db8d770232379John McCall ci+ci; 10883ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 10983ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 11083ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 11183ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 11283ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: add [[INT]] 11383ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: add [[INT]] 11483ce9d4a552987d34cbd500e983db8d770232379John McCall 11583ce9d4a552987d34cbd500e983db8d770232379John McCall // FIXME: should not load 11683ce9d4a552987d34cbd500e983db8d770232379John McCall __real i; 11783ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 11883ce9d4a552987d34cbd500e983db8d770232379John McCall 11983ce9d4a552987d34cbd500e983db8d770232379John McCall +ci; 12083ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 12183ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 12283ce9d4a552987d34cbd500e983db8d770232379John McCall 12383ce9d4a552987d34cbd500e983db8d770232379John McCall asm("nop"); // CHECK-NEXT: call void asm 12483ce9d4a552987d34cbd500e983db8d770232379John McCall 12583ce9d4a552987d34cbd500e983db8d770232379John McCall (void)(i=i); 12683ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 12783ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 12883ce9d4a552987d34cbd500e983db8d770232379John McCall 12983ce9d4a552987d34cbd500e983db8d770232379John McCall (float)(i=i); 13083ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 13183ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 13283ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 13383ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: sitofp 13483ce9d4a552987d34cbd500e983db8d770232379John McCall 13583ce9d4a552987d34cbd500e983db8d770232379John McCall (void)i; 13683ce9d4a552987d34cbd500e983db8d770232379John McCall 13783ce9d4a552987d34cbd500e983db8d770232379John McCall i=i; 13883ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 13983ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 14083ce9d4a552987d34cbd500e983db8d770232379John McCall 14183ce9d4a552987d34cbd500e983db8d770232379John McCall // Extra volatile load in C++. 14283ce9d4a552987d34cbd500e983db8d770232379John McCall i=i=i; 14383ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 14483ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 14583ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 14683ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 14783ce9d4a552987d34cbd500e983db8d770232379John McCall 14883ce9d4a552987d34cbd500e983db8d770232379John McCall (void)__builtin_choose_expr(0, i=i, j=j); 14983ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 15083ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 15183ce9d4a552987d34cbd500e983db8d770232379John McCall 15283ce9d4a552987d34cbd500e983db8d770232379John McCall // FIXME: shouldn't get these extra loads here, or the phi 15383ce9d4a552987d34cbd500e983db8d770232379John McCall k ? (i=i) : (j=j); 15483ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 15583ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: icmp 15683ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: br i1 15783ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK: volatile load 15883ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 15983ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 16083ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: br label 16183ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK: volatile load 16283ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 16383ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 16483ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: br label 16583ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK: phi 16683ce9d4a552987d34cbd500e983db8d770232379John McCall 16783ce9d4a552987d34cbd500e983db8d770232379John McCall (void)(i,(i=i)); 16883ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 16983ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 17083ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 17183ce9d4a552987d34cbd500e983db8d770232379John McCall 17283ce9d4a552987d34cbd500e983db8d770232379John McCall // FIXME: should not load k 17383ce9d4a552987d34cbd500e983db8d770232379John McCall i=i,k; 17483ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load [[INT]]* @i 17583ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store {{.*}}, [[INT]]* @i 17683ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load [[INT]]* @k 17783ce9d4a552987d34cbd500e983db8d770232379John McCall 17883ce9d4a552987d34cbd500e983db8d770232379John McCall (i=j,k=j); 17983ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load [[INT]]* @j 18083ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store {{.*}}, [[INT]]* @i 18183ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load [[INT]]* @j 18283ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store {{.*}}, [[INT]]* @k 18383ce9d4a552987d34cbd500e983db8d770232379John McCall 18483ce9d4a552987d34cbd500e983db8d770232379John McCall // FIXME: should not load 'k' 18583ce9d4a552987d34cbd500e983db8d770232379John McCall (i=j,k); 18683ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load [[INT]]* @j 18783ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store {{.*}}, [[INT]]* @i 18883ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load [[INT]]* @k 18983ce9d4a552987d34cbd500e983db8d770232379John McCall 19083ce9d4a552987d34cbd500e983db8d770232379John McCall // FIXME: should not load either 19183ce9d4a552987d34cbd500e983db8d770232379John McCall (i,j); 19283ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load [[INT]]* @i 19383ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load [[INT]]* @j 19483ce9d4a552987d34cbd500e983db8d770232379John McCall 19583ce9d4a552987d34cbd500e983db8d770232379John McCall // Extra load in C++. 19683ce9d4a552987d34cbd500e983db8d770232379John McCall i=c=k; 19783ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 19883ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: trunc 19983ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 20083ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 20183ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: sext 20283ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 20383ce9d4a552987d34cbd500e983db8d770232379John McCall 20483ce9d4a552987d34cbd500e983db8d770232379John McCall i+=k; 20583ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 20683ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 20783ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: add nsw [[INT]] 20883ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 20983ce9d4a552987d34cbd500e983db8d770232379John McCall 21083ce9d4a552987d34cbd500e983db8d770232379John McCall // FIXME: should not load! 21183ce9d4a552987d34cbd500e983db8d770232379John McCall ci; 21283ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load {{.*}} @ci, i32 0, i32 0 21383ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load {{.*}} @ci, i32 0, i32 1 21483ce9d4a552987d34cbd500e983db8d770232379John McCall 21583ce9d4a552987d34cbd500e983db8d770232379John McCall asm("nop"); // CHECK-NEXT: call void asm 21683ce9d4a552987d34cbd500e983db8d770232379John McCall 21783ce9d4a552987d34cbd500e983db8d770232379John McCall (int)ci; 21883ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load {{.*}} @ci, i32 0, i32 0 21983ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load {{.*}} @ci, i32 0, i32 1 22083ce9d4a552987d34cbd500e983db8d770232379John McCall 22183ce9d4a552987d34cbd500e983db8d770232379John McCall (bool)ci; 22283ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load {{.*}} @ci, i32 0, i32 0 22383ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load {{.*}} @ci, i32 0, i32 1 22483ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: icmp ne 22583ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: icmp ne 22683ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: or i1 22783ce9d4a552987d34cbd500e983db8d770232379John McCall 22883ce9d4a552987d34cbd500e983db8d770232379John McCall // FIXME: should not load! 22983ce9d4a552987d34cbd500e983db8d770232379John McCall ci=ci; 23083ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 23183ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 23283ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 23383ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 23483ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 23583ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 23683ce9d4a552987d34cbd500e983db8d770232379John McCall 23783ce9d4a552987d34cbd500e983db8d770232379John McCall asm("nop"); // CHECK-NEXT: call void asm 23883ce9d4a552987d34cbd500e983db8d770232379John McCall 23983ce9d4a552987d34cbd500e983db8d770232379John McCall // FIXME: should not load at end 24083ce9d4a552987d34cbd500e983db8d770232379John McCall // Extra load in C++. 24183ce9d4a552987d34cbd500e983db8d770232379John McCall ci=ci=ci; 24283ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 24383ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 24483ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 24583ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 24683ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 24783ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 24883ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 24983ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 25083ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 25183ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 25283ce9d4a552987d34cbd500e983db8d770232379John McCall 25383ce9d4a552987d34cbd500e983db8d770232379John McCall __imag ci = __imag ci = __imag ci; 25483ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: [[T:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) 25583ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store [[INT]] [[T]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) 25683ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: [[T:%.*]] = volatile load [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) 25783ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store [[INT]] [[T]], [[INT]]* getelementptr inbounds ([[CINT]]* @ci, i32 0, i32 1) 25883ce9d4a552987d34cbd500e983db8d770232379John McCall 25983ce9d4a552987d34cbd500e983db8d770232379John McCall __real (i = j); 26083ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 26183ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 26283ce9d4a552987d34cbd500e983db8d770232379John McCall 26383ce9d4a552987d34cbd500e983db8d770232379John McCall __imag i; 26483ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 26583ce9d4a552987d34cbd500e983db8d770232379John McCall 26683ce9d4a552987d34cbd500e983db8d770232379John McCall // ============================================================ 26783ce9d4a552987d34cbd500e983db8d770232379John McCall // FIXME: Test cases we get wrong. 26883ce9d4a552987d34cbd500e983db8d770232379John McCall 26983ce9d4a552987d34cbd500e983db8d770232379John McCall // A use. We load all of a into a copy of a, then load i. gcc forgets to do 27083ce9d4a552987d34cbd500e983db8d770232379John McCall // the assignment. 27183ce9d4a552987d34cbd500e983db8d770232379John McCall // (a = a).i; 27283ce9d4a552987d34cbd500e983db8d770232379John McCall 27383ce9d4a552987d34cbd500e983db8d770232379John McCall // ============================================================ 27483ce9d4a552987d34cbd500e983db8d770232379John McCall // Test cases where we intentionally differ from gcc, due to suspected bugs in 27583ce9d4a552987d34cbd500e983db8d770232379John McCall // gcc. 27683ce9d4a552987d34cbd500e983db8d770232379John McCall 27783ce9d4a552987d34cbd500e983db8d770232379John McCall // Not a use. gcc forgets to do the assignment. 27883ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: call 27983ce9d4a552987d34cbd500e983db8d770232379John McCall ((a=a),a); 28083ce9d4a552987d34cbd500e983db8d770232379John McCall 28183ce9d4a552987d34cbd500e983db8d770232379John McCall // Not a use. gcc gets this wrong, it doesn't emit the copy! 28283ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: call 28383ce9d4a552987d34cbd500e983db8d770232379John McCall (void)(a=a); 28483ce9d4a552987d34cbd500e983db8d770232379John McCall 28583ce9d4a552987d34cbd500e983db8d770232379John McCall // Not a use. gcc got this wrong in 4.2 and omitted the side effects 28683ce9d4a552987d34cbd500e983db8d770232379John McCall // entirely, but it is fixed in 4.4.0. 28783ce9d4a552987d34cbd500e983db8d770232379John McCall __imag (i = j); 28883ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 28983ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 29083ce9d4a552987d34cbd500e983db8d770232379John McCall 29183ce9d4a552987d34cbd500e983db8d770232379John McCall // C++ does an extra load here. Note that we have to do full loads. 29283ce9d4a552987d34cbd500e983db8d770232379John McCall (float)(ci=ci); 29383ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 29483ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 29583ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 29683ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 29783ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 29883ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 29983ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: sitofp 30083ce9d4a552987d34cbd500e983db8d770232379John McCall 30183ce9d4a552987d34cbd500e983db8d770232379John McCall // Not a use, bug? gcc treats this as not a use, that's probably a 30283ce9d4a552987d34cbd500e983db8d770232379John McCall // bug due to tree folding ignoring volatile. 30383ce9d4a552987d34cbd500e983db8d770232379John McCall (int)(ci=ci); 30483ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 30583ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 30683ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 30783ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 30883ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 30983ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 31083ce9d4a552987d34cbd500e983db8d770232379John McCall 31183ce9d4a552987d34cbd500e983db8d770232379John McCall // A use. 31283ce9d4a552987d34cbd500e983db8d770232379John McCall (float)(i=i); 31383ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 31483ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 31583ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 31683ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: sitofp 31783ce9d4a552987d34cbd500e983db8d770232379John McCall 31883ce9d4a552987d34cbd500e983db8d770232379John McCall // A use. gcc treats this as not a use, that's probably a bug due to tree 31983ce9d4a552987d34cbd500e983db8d770232379John McCall // folding ignoring volatile. 32083ce9d4a552987d34cbd500e983db8d770232379John McCall (int)(i=i); 32183ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 32283ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 32383ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 32483ce9d4a552987d34cbd500e983db8d770232379John McCall 32583ce9d4a552987d34cbd500e983db8d770232379John McCall // A use. 32683ce9d4a552987d34cbd500e983db8d770232379John McCall -(i=j); 32783ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 32883ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 32983ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 33083ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: sub 33183ce9d4a552987d34cbd500e983db8d770232379John McCall 33283ce9d4a552987d34cbd500e983db8d770232379John McCall // A use. gcc treats this a not a use, that's probably a bug due to tree 33383ce9d4a552987d34cbd500e983db8d770232379John McCall // folding ignoring volatile. 33483ce9d4a552987d34cbd500e983db8d770232379John McCall +(i=k); 33583ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 33683ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 33783ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 33883ce9d4a552987d34cbd500e983db8d770232379John McCall 33983ce9d4a552987d34cbd500e983db8d770232379John McCall // A use. gcc treats this a not a use, that's probably a bug due to tree 34083ce9d4a552987d34cbd500e983db8d770232379John McCall // folding ignoring volatile. 34183ce9d4a552987d34cbd500e983db8d770232379John McCall // FIXME: extra load at end 34283ce9d4a552987d34cbd500e983db8d770232379John McCall __real (ci=ci); 34383ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 34483ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 34583ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 34683ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 34783ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 34883ce9d4a552987d34cbd500e983db8d770232379John McCall 34983ce9d4a552987d34cbd500e983db8d770232379John McCall // A use. 35083ce9d4a552987d34cbd500e983db8d770232379John McCall i + 0; 35183ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 35283ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: add 35383ce9d4a552987d34cbd500e983db8d770232379John McCall 35483ce9d4a552987d34cbd500e983db8d770232379John McCall // A use. 35583ce9d4a552987d34cbd500e983db8d770232379John McCall (i=j) + i; 35683ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 35783ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 35883ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 35983ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 36083ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: add 36183ce9d4a552987d34cbd500e983db8d770232379John McCall 36283ce9d4a552987d34cbd500e983db8d770232379John McCall // A use. gcc treats this as not a use, that's probably a bug due to tree 36383ce9d4a552987d34cbd500e983db8d770232379John McCall // folding ignoring volatile. 36483ce9d4a552987d34cbd500e983db8d770232379John McCall (i=j) + 0; 36583ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 36683ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store 36783ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load 36883ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: add 36983ce9d4a552987d34cbd500e983db8d770232379John McCall 37083ce9d4a552987d34cbd500e983db8d770232379John McCall // FIXME: extra load of 'i' 37183ce9d4a552987d34cbd500e983db8d770232379John McCall (i,j)=k; 37283ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load [[INT]]* @k 37383ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load [[INT]]* @i 37483ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store {{.*}}, [[INT]]* @j 37583ce9d4a552987d34cbd500e983db8d770232379John McCall 37683ce9d4a552987d34cbd500e983db8d770232379John McCall // FIXME: extra load of 'j' 37783ce9d4a552987d34cbd500e983db8d770232379John McCall (j=k,i)=i; 37883ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load [[INT]]* @i 37983ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load [[INT]]* @k 38083ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store {{.*}}, [[INT]]* @j 38183ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile load [[INT]]* @j 38283ce9d4a552987d34cbd500e983db8d770232379John McCall // CHECK-NEXT: volatile store {{.*}}, [[INT]]* @i 38383ce9d4a552987d34cbd500e983db8d770232379John McCall} 384