zahiraam created this revision. zahiraam added reviewers: aaron.ballman, andrew.w.kaylor, rjmccall, joerg, efriedma. Herald added a project: All. zahiraam requested review of this revision. Herald added a subscriber: MaskRay. Herald added a project: clang.
Currently the options ‘ffast-math’ and the option ‘ffp-contract’ are connect. When ‘ffast-math’ is set, ffp-contract is altered this way: -ffast-math/ Ofast -> ffp-contract=fast -fno-fast-math -> if ffp-contract= fast then ffp-contract=on else ffp-contract unchanged This differs from gcc which doesn’t connect the two options, and triggered some spurious warnings; see issue https://github.com/llvm/llvm-project/issues/54625. The source of the problem is that the ‘ffast-math’ option is an on/off flag, but the ‘ffp-contract’ is an on/off/fast flag. So when ‘fno-fast-math’ is used there is no obvious value for ‘ffp-contract’. This patch is proposing a change to make the two options unrelated. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D123630 Files: clang/lib/Driver/ToolChains/Clang.cpp clang/test/CodeGen/ffp-contract-option.c clang/test/CodeGen/ffp-model.c clang/test/Driver/clang_f_opts.c clang/test/Driver/fast-math.c
Index: clang/test/Driver/fast-math.c =================================================================== --- clang/test/Driver/fast-math.c +++ clang/test/Driver/fast-math.c @@ -78,7 +78,7 @@ // 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: "-ffp-contract=on" // CHECK-FAST-MATH-NO-APPROX-FUNC-NOT: "-ffast-math" // CHECK-FAST-MATH-NO-APPROX-FUNC-NOT: "-fapprox-func" // Index: clang/test/Driver/clang_f_opts.c =================================================================== --- clang/test/Driver/clang_f_opts.c +++ clang/test/Driver/clang_f_opts.c @@ -34,9 +34,10 @@ // DEPRECATED-OFF-CHECK-NOT: -fdeprecated-macro // RUN: %clang -### -S -ffp-contract=fast %s 2>&1 | FileCheck -check-prefix=FP-CONTRACT-FAST-CHECK %s -// RUN: %clang -### -S -ffast-math %s 2>&1 | FileCheck -check-prefix=FP-CONTRACT-FAST-CHECK %s +// RUN: %clang -### -S -ffast-math %s 2>&1 | FileCheck -check-prefix=FP-CONTRACT-ON-CHECK %s // RUN: %clang -### -S -ffp-contract=off %s 2>&1 | FileCheck -check-prefix=FP-CONTRACT-OFF-CHECK %s // FP-CONTRACT-FAST-CHECK: -ffp-contract=fast +// FP-CONTRACT-ON-CHECK: -ffp-contract=on // FP-CONTRACT-OFF-CHECK: -ffp-contract=off // RUN: %clang -### -S -funroll-loops %s 2>&1 | FileCheck -check-prefix=CHECK-UNROLL-LOOPS %s Index: clang/test/CodeGen/ffp-model.c =================================================================== --- clang/test/CodeGen/ffp-model.c +++ clang/test/CodeGen/ffp-model.c @@ -36,13 +36,12 @@ // CHECK-STRICT-FAST: load float, float* // CHECK-STRICT-FAST: load float, float* - // CHECK-STRICT-FAST: call fast float @llvm.experimental.constrained.fmul.f32(float {{.*}}, float {{.*}}, {{.*}}) + // CHECK-STRICT-FAST: call reassoc nnan ninf nsz arcp afn float @llvm.experimental.constrained.fmul.f32(float {{.*}}, float {{.*}}, {{.*}}, {{.*}}) // CHECK-STRICT-FAST: load float, float* - // CHECK-STRICT-FAST: call fast float @llvm.experimental.constrained.fadd.f32(float {{.*}}, float {{.*}}, {{.*}} + // CHECK-STRICT-FAST: call reassoc nnan ninf nsz arcp afn float @llvm.experimental.constrained.fadd.f32(float {{.*}}, float {{.*}}, {{.*}}) // CHECK-FAST1: load float, float* // CHECK-FAST1: load float, float* - // CHECK-FAST1: fmul fast float {{.*}}, {{.*}} - // CHECK-FAST1: load float, float* {{.*}} - // CHECK-FAST1: fadd fast float {{.*}}, {{.*}} + // CHECK-FAST1: load float, float* + // CHECK-FAST1: call reassoc nnan ninf nsz arcp afn float @llvm.fmuladd.f32(float {{.*}}, float {{.*}}, float {{.*}}) } Index: clang/test/CodeGen/ffp-contract-option.c =================================================================== --- clang/test/CodeGen/ffp-contract-option.c +++ clang/test/CodeGen/ffp-contract-option.c @@ -35,7 +35,7 @@ // RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-FPC-ON // RUN: %clang -Xclang -no-opaque-pointers -S -emit-llvm -ffp-contract=fast -fno-fast-math \ -// RUN: %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-FPC-ON +// RUN: %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-FPC-FAST // RUN: %clang -Xclang -no-opaque-pointers -S -emit-llvm -ffp-contract=on -fno-fast-math \ // RUN: %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-FPC-ON @@ -44,7 +44,7 @@ // RUN: %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-FPC-OFF // RUN: %clang -Xclang -no-opaque-pointers -S -emit-llvm -ffp-model=fast -fno-fast-math \ -// RUN: %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-FPC-ON +// RUN: %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-FPC-FAST // RUN: %clang -Xclang -no-opaque-pointers -S -emit-llvm -ffp-model=precise -fno-fast-math \ // RUN: %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-FPC-ON @@ -105,6 +105,12 @@ // CHECK-FPC-ON: load float, float* // CHECK-FPC-ON: call float @llvm.fmuladd.f32(float {{.*}}, float {{.*}}, float {{.*}}) + // CHECK-FPC-FAST: load float, float* + // CHECK-FPC-FAST: load float, float* + // CHECK-FPC-FAST: fmul contract float {{.*}}, {{.*}} + // CHECK-FPC-FAST: load float, float* + // CHECK-FPC-FAST: fadd contract float {{.*}}, {{.*}} + // CHECK-FPC-OFF: load float, float* // CHECK-FPC-OFF: load float, float* // CHECK-FPC-OFF: fmul float Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -2990,8 +2990,6 @@ SignedZeros = false; TrappingMath = false; RoundingFPMath = false; - // If fast-math is set then set the fp-contract mode to fast. - FPContract = "fast"; break; case options::OPT_fno_fast_math: HonorINFs = true; @@ -3010,7 +3008,6 @@ if (!JA.isDeviceOffloading(Action::OFK_Cuda) && !JA.isOffloading(Action::OFK_HIP)) if (FPContract == "fast") { - FPContract = "on"; D.Diag(clang::diag::warn_drv_overriding_flag_option) << "-ffp-contract=fast" << "-ffp-contract=on";
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits