[clang] 827be69 - [clang] FastMathFlags.allowContract should be initialized only from FPFeatures.allowFPContractAcrossStatement
Melanie Blower via cfe-commits
cfe-commits at lists.llvm.org
Wed May 20 06:19:28 PDT 2020
Author: Melanie Blower
Date: 2020-05-20T06:19:10-07:00
New Revision: 827be690dce158924924a70fda79b35a9d7ad1cc
URL: https://github.com/llvm/llvm-project/commit/827be690dce158924924a70fda79b35a9d7ad1cc
DIFF: https://github.com/llvm/llvm-project/commit/827be690dce158924924a70fda79b35a9d7ad1cc.diff
LOG: [clang] FastMathFlags.allowContract should be initialized only from FPFeatures.allowFPContractAcrossStatement
Summary: Fix bug introduced in D72841 adding support for pragma float_control
Reviewers: rjmccall, Anastasia
Differential Revision: https://reviews.llvm.org/D79903
Added:
Modified:
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/constrained-math-builtins.c
clang/test/CodeGen/fp-contract-on-pragma.cpp
clang/test/CodeGen/fp-contract-pragma.cpp
clang/test/CodeGen/fp-floatcontrol-class.cpp
clang/test/CodeGen/fp-floatcontrol-pragma.cpp
clang/test/CodeGen/fp-floatcontrol-stack.cpp
clang/test/CodeGenOpenCL/relaxed-fpmath.cl
clang/test/CodeGenOpenCL/single-precision-constant.cl
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index 76f58b284eeb..346c429f663e 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -223,8 +223,7 @@ static void updateFastMathFlags(llvm::FastMathFlags &FMF,
FMF.setNoSignedZeros(FPFeatures.noSignedZeros());
FMF.setAllowReciprocal(FPFeatures.allowReciprocalMath());
FMF.setApproxFunc(FPFeatures.allowApproximateFunctions());
- FMF.setAllowContract(FPFeatures.allowFPContractAcrossStatement() ||
- FPFeatures.allowFPContractWithinStatement());
+ FMF.setAllowContract(FPFeatures.allowFPContractAcrossStatement());
}
/// Propagate fast-math flags from \p Op to the instruction in \p V.
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 94ba0dd8e598..b4bc027e832b 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2944,6 +2944,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
Opts.NoBitFieldTypeAlign = Args.hasArg(OPT_fno_bitfield_type_align);
Opts.SinglePrecisionConstants = Args.hasArg(OPT_cl_single_precision_constant);
Opts.FastRelaxedMath = Args.hasArg(OPT_cl_fast_relaxed_math);
+ if (Opts.FastRelaxedMath)
+ Opts.setDefaultFPContractMode(LangOptions::FPM_Fast);
Opts.HexagonQdsp6Compat = Args.hasArg(OPT_mqdsp6_compat);
Opts.FakeAddressSpaceMap = Args.hasArg(OPT_ffake_address_space_map);
Opts.ParseUnknownAnytype = Args.hasArg(OPT_funknown_anytype);
diff --git a/clang/test/CodeGen/constrained-math-builtins.c b/clang/test/CodeGen/constrained-math-builtins.c
index fe303eb0d5c2..a2feae903d30 100644
--- a/clang/test/CodeGen/constrained-math-builtins.c
+++ b/clang/test/CodeGen/constrained-math-builtins.c
@@ -154,9 +154,9 @@ void bar(float f) {
(double)f * f - f;
(long double)-f * f + f;
- // CHECK: call contract float @llvm.experimental.constrained.fmuladd.f32
+ // CHECK: call float @llvm.experimental.constrained.fmuladd.f32
// CHECK: fneg
- // CHECK: call contract double @llvm.experimental.constrained.fmuladd.f64
+ // CHECK: call double @llvm.experimental.constrained.fmuladd.f64
// CHECK: fneg
- // CHECK: call contract x86_fp80 @llvm.experimental.constrained.fmuladd.f80
+ // CHECK: call x86_fp80 @llvm.experimental.constrained.fmuladd.f80
};
diff --git a/clang/test/CodeGen/fp-contract-on-pragma.cpp b/clang/test/CodeGen/fp-contract-on-pragma.cpp
index 5f7463608660..812a7176b515 100644
--- a/clang/test/CodeGen/fp-contract-on-pragma.cpp
+++ b/clang/test/CodeGen/fp-contract-on-pragma.cpp
@@ -3,7 +3,7 @@
// Is FP_CONTRACT honored in a simple case?
float fp_contract_1(float a, float b, float c) {
// CHECK: _Z13fp_contract_1fff
-// CHECK: tail call contract float @llvm.fmuladd
+// CHECK: tail call float @llvm.fmuladd
#pragma clang fp contract(on)
return a * b + c;
}
@@ -31,7 +31,7 @@ T template_muladd(T a, T b, T c) {
float fp_contract_3(float a, float b, float c) {
// CHECK: _Z13fp_contract_3fff
- // CHECK: tail call contract float @llvm.fmuladd
+ // CHECK: tail call float @llvm.fmuladd
return template_muladd<float>(a, b, c);
}
@@ -45,13 +45,13 @@ class fp_contract_4 {
template class fp_contract_4<int>;
// CHECK: _ZN13fp_contract_4IiE6methodEfff
-// CHECK: tail call contract float @llvm.fmuladd
+// CHECK: tail call float @llvm.fmuladd
// Check file-scoped FP_CONTRACT
#pragma clang fp contract(on)
float fp_contract_5(float a, float b, float c) {
// CHECK: _Z13fp_contract_5fff
- // CHECK: tail call contract float @llvm.fmuladd
+ // CHECK: tail call float @llvm.fmuladd
return a * b + c;
}
@@ -69,8 +69,8 @@ float fp_contract_6(float a, float b, float c) {
float fp_contract_7(float a, float b, float c) {
// CHECK: _Z13fp_contract_7fff
-// CHECK: %[[M:.+]] = fmul contract float %b, 2.000000e+00
-// CHECK-NEXT: fsub contract float %[[M]], %c
+// CHECK: %[[M:.+]] = fmul float %b, 2.000000e+00
+// CHECK-NEXT: fsub float %[[M]], %c
#pragma clang fp contract(on)
return (a = 2 * b) - c;
}
diff --git a/clang/test/CodeGen/fp-contract-pragma.cpp b/clang/test/CodeGen/fp-contract-pragma.cpp
index 3a861ab613cd..805cc5d9c299 100644
--- a/clang/test/CodeGen/fp-contract-pragma.cpp
+++ b/clang/test/CodeGen/fp-contract-pragma.cpp
@@ -2,9 +2,9 @@
// Is FP_CONTRACT honored in a simple case?
float fp_contract_1(float a, float b, float c) {
- // CHECK: _Z13fp_contract_1fff
- // CHECK: tail call contract float @llvm.fmuladd
-#pragma STDC FP_CONTRACT ON
+// CHECK: _Z13fp_contract_1fff
+// CHECK: tail call float @llvm.fmuladd
+ #pragma STDC FP_CONTRACT ON
return a * b + c;
}
@@ -30,8 +30,8 @@ T template_muladd(T a, T b, T c) {
}
float fp_contract_3(float a, float b, float c) {
- // CHECK: _Z13fp_contract_3fff
- // CHECK: tail call contract float @llvm.fmuladd
+// CHECK: _Z13fp_contract_3fff
+// CHECK: tail call float @llvm.fmuladd
return template_muladd<float>(a, b, c);
}
@@ -44,13 +44,13 @@ template<typename T> class fp_contract_4 {
template class fp_contract_4<int>;
// CHECK: _ZN13fp_contract_4IiE6methodEfff
-// CHECK: tail call contract float @llvm.fmuladd
+// CHECK: tail call float @llvm.fmuladd
// Check file-scoped FP_CONTRACT
#pragma STDC FP_CONTRACT ON
float fp_contract_5(float a, float b, float c) {
- // CHECK: _Z13fp_contract_5fff
- // CHECK: tail call contract float @llvm.fmuladd
+// CHECK: _Z13fp_contract_5fff
+// CHECK: tail call float @llvm.fmuladd
return a * b + c;
}
@@ -67,25 +67,25 @@ float fp_contract_6(float a, float b, float c) {
// https://llvm.org/bugs/show_bug.cgi?id=25719
float fp_contract_7(float a, float b, float c) {
- // CHECK: _Z13fp_contract_7fff
- // CHECK: %[[M:.+]] = fmul contract float %b, 2.000000e+00
- // CHECK-NEXT: fsub contract float %[[M]], %c
-#pragma STDC FP_CONTRACT ON
+// CHECK: _Z13fp_contract_7fff
+// CHECK: %[[M:.+]] = fmul float %b, 2.000000e+00
+// CHECK-NEXT: fsub float %[[M]], %c
+ #pragma STDC FP_CONTRACT ON
return (a = 2 * b) - c;
}
float fp_contract_8(float a, float b, float c) {
- // CHECK: _Z13fp_contract_8fff
- // CHECK: fneg contract float %c
- // CHECK: tail call contract float @llvm.fmuladd
-#pragma STDC FP_CONTRACT ON
+// CHECK: _Z13fp_contract_8fff
+// CHECK: fneg float %c
+// CHECK: tail call float @llvm.fmuladd
+ #pragma STDC FP_CONTRACT ON
return a * b - c;
}
float fp_contract_9(float a, float b, float c) {
- // CHECK: _Z13fp_contract_9fff
- // CHECK: fneg contract float %a
- // CHECK: tail call contract float @llvm.fmuladd
-#pragma STDC FP_CONTRACT ON
+// CHECK: _Z13fp_contract_9fff
+// CHECK: fneg float %a
+// CHECK: tail call float @llvm.fmuladd
+ #pragma STDC FP_CONTRACT ON
return c - a * b;
}
diff --git a/clang/test/CodeGen/fp-floatcontrol-class.cpp b/clang/test/CodeGen/fp-floatcontrol-class.cpp
index 324c3cc14f6f..db600eee6a08 100644
--- a/clang/test/CodeGen/fp-floatcontrol-class.cpp
+++ b/clang/test/CodeGen/fp-floatcontrol-class.cpp
@@ -8,13 +8,13 @@ float z();
class ON {
float w = 2 + y() * z();
// CHECK-LABEL: define {{.*}} @_ZN2ONC2Ev{{.*}}
- //CHECK: call contract float {{.*}}llvm.fmuladd
+ //CHECK: call float {{.*}}llvm.fmuladd
};
ON on;
#pragma float_control(except, off)
class OFF {
float w = 2 + y() * z();
// CHECK-LABEL: define {{.*}} @_ZN3OFFC2Ev{{.*}}
- //CHECK: call contract float {{.*}}llvm.fmuladd
+ //CHECK: call float {{.*}}llvm.fmuladd
};
OFF off;
diff --git a/clang/test/CodeGen/fp-floatcontrol-pragma.cpp b/clang/test/CodeGen/fp-floatcontrol-pragma.cpp
index ca3a3a46aab2..7d8843220f44 100644
--- a/clang/test/CodeGen/fp-floatcontrol-pragma.cpp
+++ b/clang/test/CodeGen/fp-floatcontrol-pragma.cpp
@@ -160,7 +160,7 @@ float exc_off(double x, float zero) {
// CHECK-NS: define {{.*}}exc_off{{.*}}
{} try {
x = 1.0 / zero; /* division by zero, the result unused */
-//CHECK-NS: fdiv contract double
+//CHECK-NS: fdiv double
} catch (...) {}
return zero;
}
diff --git a/clang/test/CodeGen/fp-floatcontrol-stack.cpp b/clang/test/CodeGen/fp-floatcontrol-stack.cpp
index 18ec0d4db653..f49b5088641c 100644
--- a/clang/test/CodeGen/fp-floatcontrol-stack.cpp
+++ b/clang/test/CodeGen/fp-floatcontrol-stack.cpp
@@ -9,7 +9,7 @@
float fun_default FUN(1)
//CHECK-LABEL: define {{.*}} @_Z11fun_defaultf{{.*}}
#if DEFAULT
-//CHECK-DDEFAULT: call contract float @llvm.fmuladd{{.*}}
+//CHECK-DDEFAULT: call float @llvm.fmuladd{{.*}}
#endif
#if EBSTRICT
// Note that backend wants constrained intrinsics used
@@ -37,7 +37,7 @@ float fun_default FUN(1)
//CHECK-DEBSTRICT: llvm.experimental.constrained.fmuladd{{.*}}tonearest{{.*}}strict
#endif
#if NOHONOR
-//CHECK-NOHONOR: nnan ninf contract float {{.*}}llvm.experimental.constrained.fmuladd{{.*}}tonearest{{.*}}strict
+//CHECK-NOHONOR: nnan ninf float {{.*}}llvm.experimental.constrained.fmuladd{{.*}}tonearest{{.*}}strict
#endif
#if FAST
//Not possible to enable float_control(except) in FAST mode.
@@ -49,13 +49,13 @@ float fun_default FUN(1)
float exc_pop FUN(5)
//CHECK-LABEL: define {{.*}} @_Z7exc_popf{{.*}}
#if DEFAULT
-//CHECK-DDEFAULT: call contract float @llvm.fmuladd{{.*}}
+//CHECK-DDEFAULT: call float @llvm.fmuladd{{.*}}
#endif
#if EBSTRICT
//CHECK-DEBSTRICT: llvm.experimental.constrained.fmuladd{{.*}}tonearest{{.*}}strict
#endif
#if NOHONOR
-//CHECK-NOHONOR: call nnan ninf contract float @llvm.fmuladd{{.*}}
+//CHECK-NOHONOR: call nnan ninf float @llvm.fmuladd{{.*}}
#endif
#if FAST
//CHECK-FAST: fmul fast float
@@ -66,13 +66,13 @@ float fun_default FUN(1)
float exc_off FUN(5)
//CHECK-LABEL: define {{.*}} @_Z7exc_offf{{.*}}
#if DEFAULT
-//CHECK-DDEFAULT: call contract float @llvm.fmuladd{{.*}}
+//CHECK-DDEFAULT: call float @llvm.fmuladd{{.*}}
#endif
#if EBSTRICT
-//CHECK-DEBSTRICT: call contract float @llvm.fmuladd{{.*}}
+//CHECK-DEBSTRICT: call float @llvm.fmuladd{{.*}}
#endif
#if NOHONOR
-//CHECK-NOHONOR: call nnan ninf contract float @llvm.fmuladd{{.*}}
+//CHECK-NOHONOR: call nnan ninf float @llvm.fmuladd{{.*}}
#endif
#if FAST
//CHECK-FAST: fmul fast float
@@ -83,30 +83,30 @@ float fun_default FUN(1)
float precise_on FUN(3)
//CHECK-LABEL: define {{.*}} @_Z10precise_onf{{.*}}
#if DEFAULT
-//CHECK-DDEFAULT: contract float {{.*}}llvm.fmuladd{{.*}}
+//CHECK-DDEFAULT: float {{.*}}llvm.fmuladd{{.*}}
#endif
#if EBSTRICT
-//CHECK-DEBSTRICT: contract float {{.*}}llvm.fmuladd{{.*}}
+//CHECK-DEBSTRICT: float {{.*}}llvm.fmuladd{{.*}}
#endif
#if NOHONOR
// If precise is pushed then all fast-math should be off!
-//CHECK-NOHONOR: call contract float {{.*}}llvm.fmuladd{{.*}}
+//CHECK-NOHONOR: call float {{.*}}llvm.fmuladd{{.*}}
#endif
#if FAST
-//CHECK-FAST: contract float {{.*}}llvm.fmuladd{{.*}}
+//CHECK-FAST: float {{.*}}llvm.fmuladd{{.*}}
#endif
#pragma float_control(pop)
float precise_pop FUN(3)
//CHECK-LABEL: define {{.*}} @_Z11precise_popf{{.*}}
#if DEFAULT
-//CHECK-DDEFAULT: contract float {{.*}}llvm.fmuladd{{.*}}
+//CHECK-DDEFAULT: float {{.*}}llvm.fmuladd{{.*}}
#endif
#if EBSTRICT
-//CHECK-DEBSTRICT: contract float {{.*}}llvm.fmuladd{{.*}}
+//CHECK-DEBSTRICT: float {{.*}}llvm.fmuladd{{.*}}
#endif
#if NOHONOR
-//CHECK-NOHONOR: call nnan ninf contract float @llvm.fmuladd{{.*}}
+//CHECK-NOHONOR: call nnan ninf float @llvm.fmuladd{{.*}}
#endif
#if FAST
//CHECK-FAST: fmul fast float
@@ -143,14 +143,14 @@ float fun_default FUN(1)
//CHECK-DDEFAULT: llvm.fmuladd{{.*}}
#endif
#if EBSTRICT
-//CHECK-DEBSTRICT: contract float {{.*}}llvm.fmuladd{{.*}}
+//CHECK-DEBSTRICT: float {{.*}}llvm.fmuladd{{.*}}
#endif
#if NOHONOR
// fast math should be off, and contract should be on
-//CHECK-NOHONOR: contract float {{.*}}llvm.fmuladd{{.*}}
+//CHECK-NOHONOR: float {{.*}}llvm.fmuladd{{.*}}
#endif
#if FAST
-//CHECK-FAST: contract float {{.*}}llvm.fmuladd{{.*}}
+//CHECK-FAST: float {{.*}}llvm.fmuladd{{.*}}
#endif
#pragma float_control(push)
@@ -160,13 +160,13 @@ float fun_default FUN(1)
//CHECK-DDEFAULT: llvm.fmuladd{{.*}}
#endif
#if EBSTRICT
-//CHECK-DEBSTRICT: contract float {{.*}}llvm.fmuladd{{.*}}
+//CHECK-DEBSTRICT: float {{.*}}llvm.fmuladd{{.*}}
#endif
#if NOHONOR
-//CHECK-NOHONOR: contract float {{.*}}llvm.fmuladd{{.*}}
+//CHECK-NOHONOR: float {{.*}}llvm.fmuladd{{.*}}
#endif
#if FAST
-//CHECK-FAST: contract float {{.*}}llvm.fmuladd{{.*}}
+//CHECK-FAST: float {{.*}}llvm.fmuladd{{.*}}
#endif
#pragma float_control(precise, off)
@@ -197,13 +197,13 @@ float fun_default FUN(1)
//CHECK-DDEFAULT: llvm.fmuladd{{.*}}
#endif
#if EBSTRICT
-//CHECK-DEBSTRICT: contract float {{.*}}llvm.fmuladd{{.*}}
+//CHECK-DEBSTRICT: float {{.*}}llvm.fmuladd{{.*}}
#endif
#if NOHONOR
-//CHECK-NOHONOR: contract float {{.*}}llvm.fmuladd{{.*}}
+//CHECK-NOHONOR: float {{.*}}llvm.fmuladd{{.*}}
#endif
#if FAST
-//CHECK-FAST: contract float {{.*}}llvm.fmuladd{{.*}}
+//CHECK-FAST: float {{.*}}llvm.fmuladd{{.*}}
#endif
#ifndef FAST
@@ -217,14 +217,14 @@ class ON {
float z = 2 + y() * 7;
//CHECK-LABEL: define {{.*}} void @_ZN2ONC2Ev{{.*}}
#if DEFAULT
-//CHECK-DDEFAULT: call contract float {{.*}}llvm.fmuladd
+//CHECK-DDEFAULT: call float {{.*}}llvm.fmuladd
#endif
#if EBSTRICT
//Currently, same as default [command line options not considered]
-//CHECK-DEBSTRICT: call contract float {{.*}}llvm.fmuladd
+//CHECK-DEBSTRICT: call float {{.*}}llvm.fmuladd
#endif
#if NOHONOR
-//CHECK-NOHONOR: call nnan ninf contract float @llvm.fmuladd{{.*}}
+//CHECK-NOHONOR: call nnan ninf float @llvm.fmuladd{{.*}}
#endif
#if FAST
//CHECK-FAST: fmul fast float
@@ -237,13 +237,13 @@ class OFF {
float w = 2 + y() * 7;
//CHECK-LABEL: define {{.*}} void @_ZN3OFFC2Ev{{.*}}
#if DEFAULT
-//CHECK-DDEFAULT: call contract float {{.*}}llvm.fmuladd
+//CHECK-DDEFAULT: call float {{.*}}llvm.fmuladd
#endif
#if EBSTRICT
-//CHECK-DEBSTRICT: call contract float {{.*}}llvm.fmuladd
+//CHECK-DEBSTRICT: call float {{.*}}llvm.fmuladd
#endif
#if NOHONOR
-//CHECK-NOHONOR: call nnan ninf contract float @llvm.fmuladd{{.*}}
+//CHECK-NOHONOR: call nnan ninf float @llvm.fmuladd{{.*}}
#endif
#if FAST
//CHECK-FAST: fmul fast float
diff --git a/clang/test/CodeGenOpenCL/relaxed-fpmath.cl b/clang/test/CodeGenOpenCL/relaxed-fpmath.cl
index 757a2f410dc2..7676ee164ce4 100644
--- a/clang/test/CodeGenOpenCL/relaxed-fpmath.cl
+++ b/clang/test/CodeGenOpenCL/relaxed-fpmath.cl
@@ -8,12 +8,12 @@
float spscalardiv(float a, float b) {
// CHECK: @spscalardiv(
- // NORMAL: fdiv contract float
+ // NORMAL: fdiv float
// FAST: fdiv fast float
- // FINITE: fdiv nnan ninf contract float
- // UNSAFE: fdiv nnan nsz contract float
- // MAD: fdiv contract float
- // NOSIGNED: fdiv nsz contract float
+ // FINITE: fdiv nnan ninf float
+ // UNSAFE: fdiv nnan nsz float
+ // MAD: fdiv float
+ // NOSIGNED: fdiv nsz float
return a / b;
}
// CHECK: attributes
diff --git a/clang/test/CodeGenOpenCL/single-precision-constant.cl b/clang/test/CodeGenOpenCL/single-precision-constant.cl
index 061025d7a893..6ff7bd1bde2d 100644
--- a/clang/test/CodeGenOpenCL/single-precision-constant.cl
+++ b/clang/test/CodeGenOpenCL/single-precision-constant.cl
@@ -1,6 +1,6 @@
// RUN: %clang_cc1 %s -cl-single-precision-constant -emit-llvm -o - | FileCheck %s
float fn(float f) {
- // CHECK: tail call contract float @llvm.fmuladd.f32(float %f, float 2.000000e+00, float 1.000000e+00)
+ // CHECK: tail call float @llvm.fmuladd.f32(float %f, float 2.000000e+00, float 1.000000e+00)
return f*2. + 1.;
}
More information about the cfe-commits
mailing list