| 1 |
// Test with fast math |
| 2 |
// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -DFAST \ |
| 3 |
// RUN: -mreassociate \ |
| 4 |
// RUN: -o - %s | FileCheck --check-prefixes CHECK,CHECKFAST,CHECKNP %s |
| 5 |
// |
| 6 |
// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -emit-llvm -DFAST \ |
| 7 |
// RUN: -mreassociate \ |
| 8 |
// RUN: -o - %s | FileCheck --check-prefixes CHECK,CHECKFAST,CHECKNP %s |
| 9 |
// |
| 10 |
// Test with fast math and fprotect-parens |
| 11 |
// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -DFAST \ |
| 12 |
// RUN: -mreassociate -fprotect-parens -ffp-contract=on\ |
| 13 |
// RUN: -o - %s | FileCheck --check-prefixes CHECK,CHECKFAST,CHECKPP %s |
| 14 |
// |
| 15 |
// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -emit-llvm -DFAST \ |
| 16 |
// RUN: -mreassociate -fprotect-parens -ffp-contract=on\ |
| 17 |
// RUN: -o - %s | FileCheck --check-prefixes CHECK,CHECKFAST,CHECKPP %s |
| 18 |
// |
| 19 |
// Test without fast math: llvm intrinsic not created |
| 20 |
// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -fprotect-parens\ |
| 21 |
// RUN: -o - %s | FileCheck --implicit-check-not="llvm.arithmetic.fence" %s |
| 22 |
// |
| 23 |
// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -emit-llvm -fprotect-parens\ |
| 24 |
// RUN: -o - %s | FileCheck --implicit-check-not="llvm.arithmetic.fence" %s |
| 25 |
// |
| 26 |
// Test with fast math on spir target |
| 27 |
// RUN: %clang_cc1 -triple spir64 -emit-llvm -DFAST \ |
| 28 |
// RUN: -mreassociate -o - %s \ |
| 29 |
// RUN: | FileCheck --check-prefixes CHECK,CHECKFAST,CHECKNP %s |
| 30 |
// |
| 31 |
|
| 32 |
int v; |
| 33 |
int addit(float a, float b) { |
| 34 |
// CHECK: define {{.*}}@addit(float noundef %a, float noundef %b) #0 { |
| 35 |
_Complex double cd, cd1; |
| 36 |
cd = __arithmetic_fence(cd1); |
| 37 |
// CHECKFAST: call{{.*}} double @llvm.arithmetic.fence.f64({{.*}}real) |
| 38 |
// CHECKFAST: call{{.*}} double @llvm.arithmetic.fence.f64({{.*}}imag) |
| 39 |
// Vector should be supported. |
| 40 |
typedef float __v2f32 __attribute__((__vector_size__(8))); |
| 41 |
__v2f32 vec1, vec2; |
| 42 |
vec1 = __arithmetic_fence(vec2); |
| 43 |
// CHECKFAST: call{{.*}} <2 x float> @llvm.arithmetic.fence.v2f32 |
| 44 |
vec2 = (vec2 + vec1); |
| 45 |
// CHECKPP: call{{.*}} <2 x float> @llvm.arithmetic.fence.v2f32 |
| 46 |
|
| 47 |
v = __arithmetic_fence(a + b); |
| 48 |
// CHECKFAST: call{{.*}} float @llvm.arithmetic.fence.f32(float %add{{.*}}) |
| 49 |
|
| 50 |
v = (a + b); |
| 51 |
// CHECKPP: call{{.*}} float @llvm.arithmetic.fence.f32(float %add{{.*}}) |
| 52 |
v = a + (b*b); |
| 53 |
// CHECKPP: fmul reassoc |
| 54 |
// CHECKPP-NEXT: call{{.*}} float @llvm.arithmetic.fence.f32(float %mul) |
| 55 |
// CHECKNP: fmul |
| 56 |
// CHECKNP: fadd |
| 57 |
v = b + a*a; |
| 58 |
// CHECKPP: call{{.*}} float @llvm.fmuladd.f32 |
| 59 |
// CHECKNP: fmul |
| 60 |
// CHECKNP: fadd |
| 61 |
v = b + __arithmetic_fence(a*a); // Fence blocks recognition of FMA |
| 62 |
// CHECKPP: fmul |
| 63 |
// CHECKNP: fmul |
| 64 |
|
| 65 |
b = (a); |
| 66 |
(a) = b; |
| 67 |
// CHECK-NEXT fptosi |
| 68 |
// CHECK-NEXT store i32 |
| 69 |
// CHECK-NEXT load float |
| 70 |
// CHECK-NEXT store float |
| 71 |
// CHECK-NEXT load float |
| 72 |
// CHECK-NEXT store float |
| 73 |
return 0; |
| 74 |
// CHECK-NEXT ret i32 0 |
| 75 |
} |
| 76 |
int addit1(int a, int b) { |
| 77 |
// CHECK: define {{.*}}@addit1(i32 noundef %a, i32 noundef %b{{.*}} |
| 78 |
v = (a + b); |
| 79 |
// CHECK-NOT: call{{.*}} float @llvm.arithmetic.fence.int(float noundef %add) |
| 80 |
return 0; |
| 81 |
} |
| 82 |
#ifdef FAST |
| 83 |
#pragma float_control(precise, on) |
| 84 |
int subit(float a, float b, float *fp) { |
| 85 |
// CHECKFAST: define {{.*}}@subit(float noundef %a, float noundef %b{{.*}} |
| 86 |
*fp = __arithmetic_fence(a - b); |
| 87 |
*fp = (a + b); |
| 88 |
// CHECK-NOT: call{{.*}} float @llvm.arithmetic.fence.f32(float noundef %add) |
| 89 |
return 0; |
| 90 |
} |
| 91 |
#endif |