[clang] 96515df - [PowerPC] Fix the check for scalar MASS conversion
Author: Masoud Ataei Date: 2022-07-06T11:44:00-07:00 New Revision: 96515df816ebc3af2a632669a26374745e98b0c5 URL: https://github.com/llvm/llvm-project/commit/96515df816ebc3af2a632669a26374745e98b0c5 DIFF: https://github.com/llvm/llvm-project/commit/96515df816ebc3af2a632669a26374745e98b0c5.diff LOG: [PowerPC] Fix the check for scalar MASS conversion Proposing to move the check for scalar MASS conversion from constructor of PPCTargetLowering to the lowerLibCallBase function which decides about the lowering. The Target machine option Options.PPCGenScalarMASSEntries is set in PPCTargetMachine.cpp. But an object of the class PPCTargetLowering is created in one of the included header files. So, the constructor will run before setting PPCGenScalarMASSEntries to correct value. So, we cannot check this option in the constructor. Differential: https://reviews.llvm.org/D128653 Reviewer: @bmahjour Added: clang/test/CodeGen/lower-mass-end-to-end.c Modified: llvm/lib/Target/PowerPC/PPCISelLowering.cpp llvm/lib/Target/PowerPC/PPCISelLowering.h Removed: diff --git a/clang/test/CodeGen/lower-mass-end-to-end.c b/clang/test/CodeGen/lower-mass-end-to-end.c new file mode 100644 index 0..23e50ebc48e91 --- /dev/null +++ b/clang/test/CodeGen/lower-mass-end-to-end.c @@ -0,0 +1,147 @@ +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fapprox-func --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-AFN +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -Ofast --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-FAST +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fapprox-func --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-AFN +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -Ofast --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-FAST + +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -O3 -fapprox-func --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -Ofast --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -O3 -fapprox-func --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -Ofast --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST + +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fno-approx-func --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -fno-fast-math --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fno-approx-func --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -fno-fast-math --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST + +extern double sin(double a); +extern double cos(double a); +extern double pow(double a, double b); +extern double log(double a); +extern double log10(double a); +extern double exp(double a); +extern float sinf(float a); +extern float cosf(float a); +extern float powf(float a, float b); +extern float logf(float a); +extern float log10f(float a); +extern float expf(float a); + +double sin_f64(double a) { +// CHECK-LABEL: sin_f64 +// CHECK-MASS-FAST: __xl_sin_finite +// CHECK-MASS-AFN: __xl_sin +// CHECK-NO-MASS-FAST-NOT: {{__xl_sin|__xl_sin_finite}} +// CHECK-NO-MASS-AFN-NOT: {{__xl_sin|__xl_sin_finite}} +// CHECK: blr + return sin(a); +} + +double cos_f64(double a) { +// CHECK-LABEL: cos_f64 +// CHECK-MASS-FAST: __xl_cos_finite +// CHECK-MASS-AFN: __xl_cos +// CHECK-NO-MASS-FAST-NOT: {{__xl_cos|__xl_cos_finite}} +// CHECK-NO-MASS-AFN-NOT: {{__xl_cos|__xl_cos_finite}} +// CHECK: blr + return cos(a); +} + +double pow_f64(double a, double b) { +// CHECK-LABEL: pow_f64 +// CHECK-MASS-FAST: __xl_pow_finite +// CHECK-MASS-AFN: __xl_pow +// CHECK-NO-MASS-FAST-NOT: {{__xl_pow|__xl_pow_finite}} +// CHECK-NO-MASS-AFN-NOT: {{__xl_pow|__xl_pow_finite}} +// CHECK: blr + return pow(a, b); +} + +double log_f64(double a) { +// CHECK-LABEL: log_f64 +// CHECK-MASS-FAST: __xl_log_finite +// CHECK-MASS-AFN: __xl_log +// CHECK-NO-MASS-FAST-NOT: {{__xl_log|__xl_log_finite}} +// CHECK-NO-MASS-AFN-NOT: {{__xl_log|__xl_log_finite}} +// CHECK: blr + return log(a); +} + +double log10_f64(double a) { +// CHECK-LABEL: log10_f64 +// CHECK-MASS-FAST: __xl_log10_finite +// CHECK-MASS-AFN: __xl_log10 +// CHECK-NO-MASS-FAST-NOT: {{__xl_log10|__xl_log10_finit
[clang] d34315e - Removing this test temporarily beacuse of a failure in x86_64
Author: Masoud Ataei Date: 2022-07-06T12:41:13-07:00 New Revision: d34315e71adf2d460770a7d1f8b916c4ff4f9ccd URL: https://github.com/llvm/llvm-project/commit/d34315e71adf2d460770a7d1f8b916c4ff4f9ccd DIFF: https://github.com/llvm/llvm-project/commit/d34315e71adf2d460770a7d1f8b916c4ff4f9ccd.diff LOG: Removing this test temporarily beacuse of a failure in x86_64 Added: Modified: Removed: clang/test/CodeGen/lower-mass-end-to-end.c diff --git a/clang/test/CodeGen/lower-mass-end-to-end.c b/clang/test/CodeGen/lower-mass-end-to-end.c deleted file mode 100644 index 23e50ebc48e9.. --- a/clang/test/CodeGen/lower-mass-end-to-end.c +++ /dev/null @@ -1,147 +0,0 @@ -// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fapprox-func --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-AFN -// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -Ofast --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-FAST -// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fapprox-func --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-AFN -// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -Ofast --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-FAST - -// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -O3 -fapprox-func --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN -// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -Ofast --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST -// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -O3 -fapprox-func --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN -// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -Ofast --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST - -// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fno-approx-func --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN -// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -fno-fast-math --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST -// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fno-approx-func --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN -// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -fno-fast-math --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST - -extern double sin(double a); -extern double cos(double a); -extern double pow(double a, double b); -extern double log(double a); -extern double log10(double a); -extern double exp(double a); -extern float sinf(float a); -extern float cosf(float a); -extern float powf(float a, float b); -extern float logf(float a); -extern float log10f(float a); -extern float expf(float a); - -double sin_f64(double a) { -// CHECK-LABEL: sin_f64 -// CHECK-MASS-FAST: __xl_sin_finite -// CHECK-MASS-AFN: __xl_sin -// CHECK-NO-MASS-FAST-NOT: {{__xl_sin|__xl_sin_finite}} -// CHECK-NO-MASS-AFN-NOT: {{__xl_sin|__xl_sin_finite}} -// CHECK: blr - return sin(a); -} - -double cos_f64(double a) { -// CHECK-LABEL: cos_f64 -// CHECK-MASS-FAST: __xl_cos_finite -// CHECK-MASS-AFN: __xl_cos -// CHECK-NO-MASS-FAST-NOT: {{__xl_cos|__xl_cos_finite}} -// CHECK-NO-MASS-AFN-NOT: {{__xl_cos|__xl_cos_finite}} -// CHECK: blr - return cos(a); -} - -double pow_f64(double a, double b) { -// CHECK-LABEL: pow_f64 -// CHECK-MASS-FAST: __xl_pow_finite -// CHECK-MASS-AFN: __xl_pow -// CHECK-NO-MASS-FAST-NOT: {{__xl_pow|__xl_pow_finite}} -// CHECK-NO-MASS-AFN-NOT: {{__xl_pow|__xl_pow_finite}} -// CHECK: blr - return pow(a, b); -} - -double log_f64(double a) { -// CHECK-LABEL: log_f64 -// CHECK-MASS-FAST: __xl_log_finite -// CHECK-MASS-AFN: __xl_log -// CHECK-NO-MASS-FAST-NOT: {{__xl_log|__xl_log_finite}} -// CHECK-NO-MASS-AFN-NOT: {{__xl_log|__xl_log_finite}} -// CHECK: blr - return log(a); -} - -double log10_f64(double a) { -// CHECK-LABEL: log10_f64 -// CHECK-MASS-FAST: __xl_log10_finite -// CHECK-MASS-AFN: __xl_log10 -// CHECK-NO-MASS-FAST-NOT: {{__xl_log10|__xl_log10_finite}} -// CHECK-NO-MASS-AFN-NOT: {{__xl_log10|__xl_log10_finite}} -// CHECK: blr - return log10(a); -} - -double exp_f64(double a) { -// CHECK-LABEL: exp_f64 -// CHECK-MASS-FAST: __xl_exp_finite -// CHECK-MASS-AFN: __xl_exp -// CHECK-NO-MASS-FAST-NOT: {{__xl_exp|__xl_exp_finite}} -// CHECK-NO-MASS-AFN-NOT: {{__xl_exp|__xl_exp_finite}} -// CHECK: blr - return exp(a); -} - -float sin_f32(float a) { -// CHECK-LABEL: sin_f32 -// CHECK-MASS-FAST: __xl_sinf_finite -// CHECK-MASS-AFN: __xl_sinf -// CHECK-NO-MASS-FAST-NOT: {{__xl_sinf|__xl_sinf_finite}} -// CHECK-NO-MASS-AFN-NOT: {{__xl_sinf|__xl_sinf_finite}} -// CHECK: blr -
[clang] fe06b9f - Bringing back the test with the required target related to commit 96515df816ebc3af2a632669a26374745e98b0c5
Author: Masoud Ataei Date: 2022-07-06T13:04:17-07:00 New Revision: fe06b9f02ccddc2843505927fbd38a712d06822d URL: https://github.com/llvm/llvm-project/commit/fe06b9f02ccddc2843505927fbd38a712d06822d DIFF: https://github.com/llvm/llvm-project/commit/fe06b9f02ccddc2843505927fbd38a712d06822d.diff LOG: Bringing back the test with the required target related to commit 96515df816ebc3af2a632669a26374745e98b0c5 Added: clang/test/CodeGen/lower-mass-end-to-end.c Modified: Removed: diff --git a/clang/test/CodeGen/lower-mass-end-to-end.c b/clang/test/CodeGen/lower-mass-end-to-end.c new file mode 100644 index 0..41a65900d4d23 --- /dev/null +++ b/clang/test/CodeGen/lower-mass-end-to-end.c @@ -0,0 +1,148 @@ +// REQUIRES: powerpc-registered-target +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fapprox-func --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-AFN +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -Ofast --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-FAST +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fapprox-func --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-AFN +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -Ofast --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-FAST + +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -O3 -fapprox-func --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -Ofast --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -O3 -fapprox-func --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -Ofast --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST + +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fno-approx-func --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -fno-fast-math --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fno-approx-func --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN +// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -fno-fast-math --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST + +extern double sin(double a); +extern double cos(double a); +extern double pow(double a, double b); +extern double log(double a); +extern double log10(double a); +extern double exp(double a); +extern float sinf(float a); +extern float cosf(float a); +extern float powf(float a, float b); +extern float logf(float a); +extern float log10f(float a); +extern float expf(float a); + +double sin_f64(double a) { +// CHECK-LABEL: sin_f64 +// CHECK-MASS-FAST: __xl_sin_finite +// CHECK-MASS-AFN: __xl_sin +// CHECK-NO-MASS-FAST-NOT: {{__xl_sin|__xl_sin_finite}} +// CHECK-NO-MASS-AFN-NOT: {{__xl_sin|__xl_sin_finite}} +// CHECK: blr + return sin(a); +} + +double cos_f64(double a) { +// CHECK-LABEL: cos_f64 +// CHECK-MASS-FAST: __xl_cos_finite +// CHECK-MASS-AFN: __xl_cos +// CHECK-NO-MASS-FAST-NOT: {{__xl_cos|__xl_cos_finite}} +// CHECK-NO-MASS-AFN-NOT: {{__xl_cos|__xl_cos_finite}} +// CHECK: blr + return cos(a); +} + +double pow_f64(double a, double b) { +// CHECK-LABEL: pow_f64 +// CHECK-MASS-FAST: __xl_pow_finite +// CHECK-MASS-AFN: __xl_pow +// CHECK-NO-MASS-FAST-NOT: {{__xl_pow|__xl_pow_finite}} +// CHECK-NO-MASS-AFN-NOT: {{__xl_pow|__xl_pow_finite}} +// CHECK: blr + return pow(a, b); +} + +double log_f64(double a) { +// CHECK-LABEL: log_f64 +// CHECK-MASS-FAST: __xl_log_finite +// CHECK-MASS-AFN: __xl_log +// CHECK-NO-MASS-FAST-NOT: {{__xl_log|__xl_log_finite}} +// CHECK-NO-MASS-AFN-NOT: {{__xl_log|__xl_log_finite}} +// CHECK: blr + return log(a); +} + +double log10_f64(double a) { +// CHECK-LABEL: log10_f64 +// CHECK-MASS-FAST: __xl_log10_finite +// CHECK-MASS-AFN: __xl_log10 +// CHECK-NO-MASS-FAST-NOT: {{__xl_log10|__xl_log10_finite}} +// CHECK-NO-MASS-AFN-NOT: {{__xl_log10|__xl_log10_finite}} +// CHECK: blr + return log10(a); +} + +double exp_f64(double a) { +// CHECK-LABEL: exp_f64 +// CHECK-MASS-FAST: __xl_exp_finite +// CHECK-MASS-AFN: __xl_exp +// CHECK-NO-MASS-FAST-NOT: {{__xl_exp|__xl_exp_finite}} +// CHECK-NO-MASS-AFN-NOT: {{__xl_exp|__xl_exp_finite}} +// CHECK: blr + return exp(a); +} + +float sin_f32(float a) { +// CHECK-LABEL: sin_f32 +// CHECK-MASS-FAST: __xl_sinf_finite +// CHECK-MASS-AFN: __xl_sinf +// CHECK-NO-MASS-FAST-NOT: {{__xl_sinf|__xl_sinf_
[clang] fc750f6 - [PPC] Fixing a typo in altivec.h. Commenting out an unnecessary macro
Author: Masoud Ataei Date: 2020-12-08T19:21:02Z New Revision: fc750f609dfb2fd51b6810cc55058568dfe4b3a9 URL: https://github.com/llvm/llvm-project/commit/fc750f609dfb2fd51b6810cc55058568dfe4b3a9 DIFF: https://github.com/llvm/llvm-project/commit/fc750f609dfb2fd51b6810cc55058568dfe4b3a9.diff LOG: [PPC] Fixing a typo in altivec.h. Commenting out an unnecessary macro Added: Modified: clang/lib/Headers/altivec.h Removed: diff --git a/clang/lib/Headers/altivec.h b/clang/lib/Headers/altivec.h index 24d600e95201..2b82113de311 100644 --- a/clang/lib/Headers/altivec.h +++ b/clang/lib/Headers/altivec.h @@ -3502,7 +3502,7 @@ static __inline__ vector signed __int128 __ATTRS_o_ai vec_div(vector signed __int128 __a, vector signed __int128 __b) { return __a / __b; } -#endif __POWER10_VECTOR__ +#endif /* __POWER10_VECTOR__ */ /* vec_xvtdiv */ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] d261660 - Fix the use of -fno-approx-func along with -Ofast or -ffast-math
Author: Masoud Ataei Date: 2022-01-19T08:05:08-08:00 New Revision: d261660af96d402689d025b4584e925869a9b413 URL: https://github.com/llvm/llvm-project/commit/d261660af96d402689d025b4584e925869a9b413 DIFF: https://github.com/llvm/llvm-project/commit/d261660af96d402689d025b4584e925869a9b413.diff LOG: Fix the use of -fno-approx-func along with -Ofast or -ffast-math Fix how -fapprox-func interact correctly with the other floating point options. Reported bug Number 52565: https://bugs.llvm.org/show_bug.cgi?id=52565 Differential: https://reviews.llvm.org/D114564 Reviewer: @andrew.w.kaylor Added: Modified: clang/lib/Driver/ToolChains/Clang.cpp clang/test/Driver/fast-math.c clang/test/Preprocessor/aarch64-target-features.c clang/test/Preprocessor/arm-target-features.c Removed: diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index fd300fbe40145..253c52cf0ba85 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -2902,6 +2902,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, AssociativeMath = true; ReciprocalMath = true; SignedZeros = false; + ApproxFunc = true; TrappingMath = false; FPExceptionBehavior = ""; break; @@ -2909,6 +2910,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, AssociativeMath = false; ReciprocalMath = false; SignedZeros = true; + ApproxFunc = false; TrappingMath = true; FPExceptionBehavior = "strict"; @@ -2928,6 +2930,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, MathErrno = false; AssociativeMath = true; ReciprocalMath = true; + ApproxFunc = true; SignedZeros = false; TrappingMath = false; RoundingFPMath = false; @@ -2943,6 +2946,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, MathErrno = TC.IsMathErrnoDefault(); AssociativeMath = false; ReciprocalMath = false; + ApproxFunc = false; SignedZeros = true; // -fno_fast_math restores default denormal and fpcontract handling DenormalFPMath = DefaultDenormalFPMath; @@ -2961,7 +2965,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, // If -ffp-model=strict has been specified on command line but // subsequent options conflict then emit warning diagnostic. if (HonorINFs && HonorNaNs && !AssociativeMath && !ReciprocalMath && - SignedZeros && TrappingMath && RoundingFPMath && + SignedZeros && TrappingMath && RoundingFPMath && !ApproxFunc && DenormalFPMath == llvm::DenormalMode::getIEEE() && DenormalFP32Math == llvm::DenormalMode::getIEEE() && FPContract.equals("off")) @@ -2994,7 +2998,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, CmdArgs.push_back("-fmath-errno"); if (!MathErrno && AssociativeMath && ReciprocalMath && !SignedZeros && - !TrappingMath) + ApproxFunc && !TrappingMath) CmdArgs.push_back("-menable-unsafe-fp-math"); if (!SignedZeros) @@ -3045,7 +3049,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, // -ffast-math enables the __FAST_MATH__ preprocessor macro, but check for the // individual features enabled by -ffast-math instead of the option itself as // that's consistent with gcc's behaviour. - if (!HonorINFs && !HonorNaNs && !MathErrno && AssociativeMath && + if (!HonorINFs && !HonorNaNs && !MathErrno && AssociativeMath && ApproxFunc && ReciprocalMath && !SignedZeros && !TrappingMath && !RoundingFPMath) { CmdArgs.push_back("-ffast-math"); if (FPModel.equals("fast")) { diff --git a/clang/test/Driver/fast-math.c b/clang/test/Driver/fast-math.c index 8d293c2ea01ff..a66e9d0eca177 100644 --- a/clang/test/Driver/fast-math.c +++ b/clang/test/Driver/fast-math.c @@ -70,6 +70,23 @@ // CHECK-NO-NANS-NO-FAST-MATH: "-cc1" // CHECK-NO-NANS-NO-FAST-MATH-NOT: "-menable-no-nans" // +// RUN: %clang -### -ffast-math -fno-approx-func -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FAST-MATH-NO-APPROX-FUNC %s +// CHECK-FAST-MATH-NO-APPROX-FUNC: "-cc1" +// CHECK-FAST-MATH-NO-APPROX-FUNC: "-menable-no-infs" +// CHECK-FAST-MATH-NO-APPROX-FUNC: "-menable-no-nans" +// CHECK-FAST-MATH-NO-APPROX-FUNC: "-fno-signed-zeros" +// CHECK-FAST-MATH-NO-APPROX-FUNC: "-mreassociate" +// CHECK-FAST-MATH-NO-APPROX-FUNC: "-freciprocal-math" +// CHECK-FAST-MATH-NO-APPROX-FUNC: "-ffp-contract=fast" +// CHECK-FAST-MATH-NO-APPROX-FUNC-NOT: "-ffast-math" +// CHECK-FAST-MATH-NO-APPROX-FUNC-NOT: "-fapprox-func" +// +// RUN: %clang -### -fno-approx-func -ffast-math -c %s 2>&1 \ +// RUN: | FileChe
[clang] b0f6879 - [clang] Option control afn flag
Author: Masoud Ataei Date: 2021-10-08T14:26:14-04:00 New Revision: b0f68791f0ad867118497daf6aa23f9a71500012 URL: https://github.com/llvm/llvm-project/commit/b0f68791f0ad867118497daf6aa23f9a71500012 DIFF: https://github.com/llvm/llvm-project/commit/b0f68791f0ad867118497daf6aa23f9a71500012.diff LOG: [clang] Option control afn flag Clang option to set/unset afn fast-math flag. Differential: https://reviews.llvm.org/D106191 Reviewd with: aaron.ballman, erichkeane, and others Added: clang/test/CodeGen/afn-flag-test.c Modified: clang/docs/UsersManual.rst clang/include/clang/Driver/Options.td clang/lib/CodeGen/BackendUtil.cpp clang/lib/CodeGen/CGCall.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/test/Driver/fast-math.c llvm/include/llvm/Target/TargetOptions.h Removed: diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst index f025028c1721d..30da581c67700 100644 --- a/clang/docs/UsersManual.rst +++ b/clang/docs/UsersManual.rst @@ -1386,6 +1386,17 @@ are listed below. If both ``-fno-honor-infinities`` and ``-fno-honor-nans`` are used, has the same effect as specifying ``-ffinite-math-only``. +.. _opt_fapprox-func: + +**-f[no-]approx-func** + + Allow certain math function calls (such as ``log``, ``sqrt``, ``pow``, etc) + to be replaced with an approximately equivalent set of instructions + or alternative math function calls. For example, a ``pow(x, 0.25)`` + may be replaced with ``sqrt(sqrt(x))``, despite being an inexact result + in cases where ``x`` is ``-0.0`` or ``-inf``. + Defaults to ``-fno-approx-func``. + .. _opt_fsigned-zeros: **-f[no-]signed-zeros** diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 5a87f1276d1f3..9b0d0dfb7628c 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1764,8 +1764,11 @@ defm reciprocal_math : BoolFOption<"reciprocal-math", PosFlag, NegFlag>; -def fapprox_func : Flag<["-"], "fapprox-func">, Group, Flags<[CC1Option, NoDriverOption]>, - MarshallingInfoFlag>, ImpliedByAnyOf<[menable_unsafe_fp_math.KeyPath]>; +defm approx_func : BoolFOption<"approx-func", LangOpts<"ApproxFunc">, DefaultFalse, + PosFlag, + NegFlag>; defm finite_math_only : BoolFOption<"finite-math-only", LangOpts<"FiniteMathOnly">, DefaultFalse, PosFlag, diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 99e33b227f792..76f6985d5cfa3 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -539,6 +539,7 @@ static bool initTargetOptions(DiagnosticsEngine &Diags, Options.NoNaNsFPMath = LangOpts.NoHonorNaNs; Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS; Options.UnsafeFPMath = LangOpts.UnsafeFPMath; + Options.ApproxFuncFPMath = LangOpts.ApproxFunc; Options.BBSections = llvm::StringSwitch(CodeGenOpts.BBSections) diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 70966c9e7b357..af5f519c6fced 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1848,6 +1848,8 @@ void CodeGenModule::getDefaultFunctionAttributes(StringRef Name, FuncAttrs.addAttribute("no-infs-fp-math", "true"); if (LangOpts.NoHonorNaNs) FuncAttrs.addAttribute("no-nans-fp-math", "true"); +if (LangOpts.ApproxFunc) + FuncAttrs.addAttribute("approx-func-fp-math", "true"); if (LangOpts.UnsafeFPMath) FuncAttrs.addAttribute("unsafe-fp-math", "true"); if (CodeGenOpts.SoftFloat) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index c636c25a1dc81..f1771d4fa35d2 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -2614,6 +2614,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, // LLVM flags based on the final state. bool HonorINFs = true; bool HonorNaNs = true; + bool ApproxFunc = false; // -fmath-errno is the default on some platforms, e.g. BSD-derived OSes. bool MathErrno = TC.IsMathErrnoDefault(); bool AssociativeMath = false; @@ -2718,6 +2719,8 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, case options::OPT_fno_honor_infinities: HonorINFs = false;break; case options::OPT_fhonor_nans: HonorNaNs = true; break; case options::OPT_fno_honor_nans: HonorNaNs = false;break; +case options::OPT_fapprox_func: ApproxFunc = true;break; +case options::OPT_fno_approx_func: ApproxFunc = false; break; case options::OPT_fmath_errno: MathErrno = true; break; case options::OPT_fno_math_errno: MathErrno = false;break; case options::OPT_fassociative_math:AssociativeMath = true;