From 836904e7cf5d12fe08026145404f1e7944e6deac Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Fri, 23 Jan 2015 16:40:50 +0000 Subject: [PATCH] Process the -fno-signed-zeros optimization flag (PR20870) The driver currently accepts but ignores the -fno-signed-zeros flag. This patch passes the flag through and enables 'nsz' fast-math-flag generation in IR. The existing OpenCL flag for the same functionality is made into an alias here. It may be removed in a subsequent patch. This should resolve bug 20870 ( http://llvm.org/bugs/show_bug.cgi?id=20870 ); patches for the optimizer were checked in at: http://llvm.org/viewvc/llvm-project?view=revision&revision=225050 http://llvm.org/viewvc/llvm-project?view=revision&revision=224583 Differential Revision: http://reviews.llvm.org/D6873 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@226915 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/CC1Options.td | 2 +- include/clang/Driver/Options.td | 4 +++- lib/Driver/Tools.cpp | 2 ++ lib/Frontend/CompilerInvocation.cpp | 2 +- test/CodeGen/finite-math.c | 8 ++++++-- test/Driver/fast-math.c | 15 +++++++++++++++ 6 files changed, 28 insertions(+), 5 deletions(-) diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index e043001410..4406fc83cf 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -580,7 +580,7 @@ def cl_finite_math_only : Flag<["-"], "cl-finite-math-only">, HelpText<"OpenCL only. Allow floating-point optimizations that assume arguments and results are not NaNs or +-Inf.">; def cl_kernel_arg_info : Flag<["-"], "cl-kernel-arg-info">, HelpText<"OpenCL only. Generate kernel argument metadata.">; -def cl_no_signed_zeros : Flag<["-"], "cl-no-signed-zeros">, +def : Flag<["-"], "cl-no-signed-zeros">, Alias, HelpText<"OpenCL only. Allow optimizations to ignore the signedness of the floating-point zero.">; def cl_unsafe_math_optimizations : Flag<["-"], "cl-unsafe-math-optimizations">, HelpText<"OpenCL only. Allow unsafe floating-point optimizations. Also implies -cl-no-signed-zeros and -cl-mad-enable">; diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index c538ac4ecb..f96da51563 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -566,7 +566,9 @@ def fno_reciprocal_math : Flag<["-"], "fno-reciprocal-math">, Group; def ffinite_math_only : Flag<["-"], "ffinite-math-only">, Group, Flags<[CC1Option]>; def fno_finite_math_only : Flag<["-"], "fno-finite-math-only">, Group; def fsigned_zeros : Flag<["-"], "fsigned-zeros">, Group; -def fno_signed_zeros : Flag<["-"], "fno-signed-zeros">, Group; +def fno_signed_zeros : + Flag<["-"], "fno-signed-zeros">, Group, Flags<[CC1Option]>, + HelpText<"Allow optimizations that ignore the sign of floating point zeros">; def fhonor_nans : Flag<["-"], "fhonor-nans">, Group; def fno_honor_nans : Flag<["-"], "fno-honor-nans">, Group; def fhonor_infinities : Flag<["-"], "fhonor-infinities">, Group; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 680539bcfe..1f0d4f09f8 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -2955,6 +2955,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, !TrappingMath) CmdArgs.push_back("-menable-unsafe-fp-math"); + if (!SignedZeros) + CmdArgs.push_back("-fno-signed-zeros"); // Validate and pass through -fp-contract option. if (Arg *A = Args.getLastArg(options::OPT_ffast_math, FastMathAliasOption, diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index dd1a60611a..ab5c8f8168 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -441,7 +441,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, Args.hasArg(OPT_cl_unsafe_math_optimizations) || Args.hasArg(OPT_cl_finite_math_only) || Args.hasArg(OPT_cl_fast_relaxed_math)); - Opts.NoSignedZeros = Args.hasArg(OPT_cl_no_signed_zeros); + Opts.NoSignedZeros = Args.hasArg(OPT_fno_signed_zeros); Opts.NoZeroInitializedInBSS = Args.hasArg(OPT_mno_zero_initialized_in_bss); Opts.BackendOptions = Args.getAllArgValues(OPT_backend_option); Opts.NumRegisterParameters = getLastArgIntValue(Args, OPT_mregparm, 0, Diags); diff --git a/test/CodeGen/finite-math.c b/test/CodeGen/finite-math.c index b0ee15759a..fd8fcf6fad 100644 --- a/test/CodeGen/finite-math.c +++ b/test/CodeGen/finite-math.c @@ -1,11 +1,15 @@ -// RUN: %clang_cc1 -ffinite-math-only -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -ffinite-math-only -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK -check-prefix=FINITE +// RUN: %clang_cc1 -fno-signed-zeros -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK -check-prefix=NSZ + float f0, f1, f2; void foo(void) { // CHECK-LABEL: define void @foo() - // CHECK: fadd nnan ninf + // FINITE: fadd nnan ninf + // NSZ: fadd nsz f0 = f1 + f2; // CHECK: ret } + diff --git a/test/Driver/fast-math.c b/test/Driver/fast-math.c index 690d7a1e6e..bacd7fe4cb 100644 --- a/test/Driver/fast-math.c +++ b/test/Driver/fast-math.c @@ -25,6 +25,21 @@ // CHECK-NO-INFS-NO-FAST-MATH: "-cc1" // CHECK-NO-INFS-NO-FAST-MATH-NOT: "-menable-no-infs" // +// RUN: %clang -### -fno-signed-zeros -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-SIGNED-ZEROS %s +// CHECK-NO-SIGNED-ZEROS: "-cc1" +// CHECK-NO-SIGNED-ZEROS: "-fno-signed-zeros" +// +// RUN: %clang -### -fno-fast-math -fno-signed-zeros -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-FAST-MATH-NO-SIGNED-ZEROS %s +// CHECK-NO-FAST-MATH-NO-SIGNED-ZEROS: "-cc1" +// CHECK-NO-FAST-MATH-NO-SIGNED-ZEROS: "-fno-signed-zeros" +// +// RUN: %clang -### -fno-signed-zeros -fno-fast-math -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-SIGNED-ZEROS-NO-FAST-MATH %s +// CHECK-NO-SIGNED-ZEROS-NO-FAST-MATH: "-cc1" +// CHECK-NO-SIGNED-ZEROS-NO-FAST-MATH-NOT: "-fno-signed-zeros" +// // RUN: %clang -### -fno-honor-nans -c %s 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-NO-NANS %s // CHECK-NO-NANS: "-cc1" -- 2.40.0