This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG91628f0616ca: The handling of 'funsafe-math-optimizations' doesn't update the 'MathErrno' (authored by zahiraam).
Changed prior to commit: https://reviews.llvm.org/D137578?vs=474515&id=474762#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D137578/new/ https://reviews.llvm.org/D137578 Files: clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Frontend/CompilerInvocation.cpp clang/test/CodeGenOpenCL/relaxed-fpmath.cl clang/test/Driver/fp-contract.c
Index: clang/test/Driver/fp-contract.c =================================================================== --- clang/test/Driver/fp-contract.c +++ clang/test/Driver/fp-contract.c @@ -1,6 +1,8 @@ // Test that -ffp-contract is set to the right value when combined with -// the options -ffast-math and -fno-fast-math. +// the options -ffast-math, -fno-fast-math, funsafe-math-optimizations, +// fno-unsafe-math-optimizations. +// ffast-math, fno-fast-math // RUN: %clang -### -ffast-math -c %s 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-FPC-FAST %s // CHECK-FPC-FAST: "-ffp-contract=fast" @@ -112,3 +114,123 @@ // RUN: %clang -### -fno-fast-math -ffast-math -ffp-contract=off \ // RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-OFF %s +// funsafe-math-optimizations, fno-unsafe-math-optimizations +// RUN: %clang -### -funsafe-math-optimizations -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPC-FAST %s + +// RUN: %clang -### -fno-unsafe-math-optimizations -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPC-ON %s + +// RUN: %clang -### -funsafe-math-optimizations -ffp-contract=on -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPC-ON %s + +// RUN: %clang -### -funsafe-math-optimizations -ffp-contract=off -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPC-OFF %s + +// RUN: %clang -### -funsafe-math-optimizations -ffp-contract=fast -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPC-FAST %s + +// RUN: %clang -### -ffp-contract=fast -funsafe-math-optimizations -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPC-FAST %s +// RUN: %clang -### -ffp-contract=on -funsafe-math-optimizations -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPC-FAST %s +// RUN: %clang -### -ffp-contract=off -funsafe-math-optimizations -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPC-FAST %s + +// RUN: %clang -### -ffp-contract=fast -fno-unsafe-math-optimizations -c \ +// RUN: %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-FAST %s +// RUN: %clang -### -ffp-contract=on -fno-unsafe-math-optimizations -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPC-ON %s +// RUN: %clang -### -ffp-contract=off -fno-unsafe-math-optimizations -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPC-OFF %s + +// RUN: %clang -### -funsafe-math-optimizations -ffp-contract=fast \ +// RUN: -ffp-contract=on -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-ON %s + +// RUN: %clang -### -funsafe-math-optimizations -ffp-contract=on \ +// RUN: -ffp-contract=off -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-OFF %s + +// RUN: %clang -### -funsafe-math-optimizations -ffp-contract=on \ +// RUN: -ffp-contract=fast -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPC-FAST %s + +// RUN: %clang -### -funsafe-math-optimizations -ffp-contract=off \ +// RUN: -ffp-contract=on -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-ON %s + +// RUN: %clang -### -funsafe-math-optimizations -ffp-contract=off \ +// RUN: -ffp-contract=fast \ +// RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-FAST %s + +// RUN: %clang -### -funsafe-math-optimizations -ffp-contract=on \ +// RUN: -fno-unsafe-math-optimizations -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPC-ON %s + +// RUN: %clang -### -funsafe-math-optimizations -ffp-contract=off \ +// RUN: -fno-unsafe-math-optimizations -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPC-OFF %s + +// RUN: %clang -### -funsafe-math-optimizations -ffp-contract=fast \ +// RUN: -fno-unsafe-math-optimizations -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPC-FAST %s + +// RUN: %clang -### -funsafe-math-optimizations -fno-unsafe-math-optimizations \ +// RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-ON %s + +// RUN: %clang -### -fno-unsafe-math-optimizations -funsafe-math-optimizations \ +// RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-FAST %s + +// RUN: %clang -### -fno-unsafe-math-optimizations -ffp-contract=on -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPC-ON %s + +// RUN: %clang -### -fno-unsafe-math-optimizations -ffp-contract=off -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPC-OFF %s + +// RUN: %clang -### -fno-unsafe-math-optimizations -ffp-contract=fast -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPC-FAST %s + +// RUN: %clang -### -ffp-contract=fast -fno-unsafe-math-optimizations \ +// RUN: -ffp-contract=on \ +// RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-ON %s + +// RUN: %clang -### -ffp-contract=fast -fno-unsafe-math-optimizations \ +// RUN: -ffp-contract=off \ +// RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-OFF %s + +// RUN: %clang -### -ffp-contract=off -fno-unsafe-math-optimizations \ +// RUN: -ffp-contract=fast \ +// RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-FAST %s + +// RUN: %clang -### -ffp-contract=off -fno-unsafe-math-optimizations \ +// RUN: -ffp-contract=on -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-ON %s + +// RUN: %clang -### -ffp-contract=on -funsafe-math-optimizations -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPC-FAST %s + +// RUN: %clang -### -ffp-contract=off -funsafe-math-optimizations -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPC-FAST %s + +// RUN: %clang -### -ffp-contract=fast -funsafe-math-optimizations -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPC-FAST %s + +// RUN: %clang -### -ffp-contract=on -funsafe-math-optimizations \ +// RUN: -fno-unsafe-math-optimizations -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPC-ON %s + +// RUN: %clang -### -ffp-contract=off -funsafe-math-optimizations \ +// RUN: -fno-unsafe-math-optimizations -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPC-OFF %s + +// RUN: %clang -### -ffp-contract=fast -funsafe-math-optimizations \ +// RUN: -fno-unsafe-math-optimizations -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FPC-FAST %s + +// RUN: %clang -### -fno-unsafe-math-optimizations -funsafe-math-optimizations \ +// RUN: -ffp-contract=fast \ +// RUN: -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-FAST %s + +// RUN: %clang -### -fno-unsafe-math-optimizations -funsafe-math-optimizations \ +// RUN: -ffp-contract=on -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-ON %s + +// RUN: %clang -### -fno-unsafe-math-optimizations -funsafe-math-optimizations \ +// RUN: -ffp-contract=off -c %s 2>&1 | FileCheck --check-prefix=CHECK-FPC-OFF %s + Index: clang/test/CodeGenOpenCL/relaxed-fpmath.cl =================================================================== --- clang/test/CodeGenOpenCL/relaxed-fpmath.cl +++ clang/test/CodeGenOpenCL/relaxed-fpmath.cl @@ -22,7 +22,7 @@ // NORMAL: fdiv float // FAST: fdiv fast float // FINITE: fdiv nnan ninf float - // UNSAFE: fdiv reassoc nsz arcp afn float + // UNSAFE: fdiv reassoc nsz arcp contract afn float // MAD: fdiv float // NOSIGNED: fdiv nsz float return a / b; Index: clang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -3799,7 +3799,7 @@ else Opts.LongDoubleSize = 0; } - if (Opts.FastRelaxedMath) + if (Opts.FastRelaxedMath || Opts.CLUnsafeMath) Opts.setDefaultFPContractMode(LangOptions::FPM_Fast); llvm::sort(Opts.ModuleFeatures); Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -2787,7 +2787,7 @@ // If one wasn't given by the user, don't pass it here. StringRef FPContract; StringRef LastSeenFfpContractOption; - bool SeenFfastMathOption = false; + bool SeenUnsafeMathModeOption = false; if (!JA.isDeviceOffloading(Action::OFK_Cuda) && !JA.isOffloading(Action::OFK_HIP)) FPContract = "on"; @@ -3003,6 +3003,8 @@ ApproxFunc = true; TrappingMath = false; FPExceptionBehavior = ""; + FPContract = "fast"; + SeenUnsafeMathModeOption = true; break; case options::OPT_fno_unsafe_math_optimizations: AssociativeMath = false; @@ -3015,6 +3017,13 @@ // The target may have opted to flush by default, so force IEEE. DenormalFPMath = llvm::DenormalMode::getIEEE(); DenormalFP32Math = llvm::DenormalMode::getIEEE(); + if (!JA.isDeviceOffloading(Action::OFK_Cuda) && + !JA.isOffloading(Action::OFK_HIP)) { + if (LastSeenFfpContractOption != "") { + FPContract = LastSeenFfpContractOption; + } else if (SeenUnsafeMathModeOption) + FPContract = "on"; + } break; case options::OPT_Ofast: @@ -3034,7 +3043,7 @@ RoundingFPMath = false; // If fast-math is set then set the fp-contract mode to fast. FPContract = "fast"; - SeenFfastMathOption = true; + SeenUnsafeMathModeOption = true; break; case options::OPT_fno_fast_math: HonorINFs = true; @@ -3054,7 +3063,7 @@ !JA.isOffloading(Action::OFK_HIP)) { if (LastSeenFfpContractOption != "") { FPContract = LastSeenFfpContractOption; - } else if (SeenFfastMathOption) + } else if (SeenUnsafeMathModeOption) FPContract = "on"; } break; @@ -3095,8 +3104,8 @@ if (MathErrno) CmdArgs.push_back("-fmath-errno"); - if (!MathErrno && AssociativeMath && ReciprocalMath && !SignedZeros && - ApproxFunc && !TrappingMath) + if (AssociativeMath && ReciprocalMath && !SignedZeros && ApproxFunc && + !TrappingMath) CmdArgs.push_back("-funsafe-math-optimizations"); if (!SignedZeros)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits