Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -626,6 +626,11 @@ def : Flag<["-"], "fextended-identifiers">, Group; def : Flag<["-"], "fno-extended-identifiers">, Group, Flags<[Unsupported]>; def fhosted : Flag<["-"], "fhosted">, Group; +def fdenormal_fp_math_EQ : Joined<["-"], "fdenormal-fp-math=">, Group, Flags<[CC1Option]>; +def fexceptions_fp_math : Flag<["-"], "fexceptions-fp-math">, Group, + Flags<[CC1Option]>; +def fno_exceptions_fp_math : Flag<["-"], "fno-exceptions-fp-math">, Group, + Flags<[CC1Option]>; def ffast_math : Flag<["-"], "ffast-math">, Group, Flags<[CC1Option]>, HelpText<"Allow aggressive, lossy floating-point optimizations">; def fno_fast_math : Flag<["-"], "fno-fast-math">, Group; Index: include/clang/Frontend/CodeGenOptions.h =================================================================== --- include/clang/Frontend/CodeGenOptions.h +++ include/clang/Frontend/CodeGenOptions.h @@ -121,6 +121,9 @@ /// The ABI to use for passing floating point arguments. std::string FloatABI; + /// The floating-point denormal mode to use. + std::string FPDenormalMode; + /// The float precision limit to use, if non-empty. std::string LimitFloatPrecision; Index: include/clang/Frontend/CodeGenOptions.def =================================================================== --- include/clang/Frontend/CodeGenOptions.def +++ include/clang/Frontend/CodeGenOptions.def @@ -104,6 +104,8 @@ ///< enabled. CODEGENOPT(EnableSegmentedStacks , 1, 0) ///< Set when -fsplit-stack is enabled. CODEGENOPT(NoImplicitFloat , 1, 0) ///< Set when -mno-implicit-float is enabled. +CODEGENOPT(NoExceptionsFPMath, 1, 0) ///< Set when -fno-exceptions-fp-math is + ///< enabled. CODEGENOPT(NoInfsFPMath , 1, 0) ///< Assume FP arguments, results not +-Inf. CODEGENOPT(NoSignedZeros , 1, 0) ///< Allow ignoring the signedness of FP zero CODEGENOPT(ReciprocalMath , 1, 0) ///< Allow FP divisions to be reassociated. Index: lib/CodeGen/CGCall.cpp =================================================================== --- lib/CodeGen/CGCall.cpp +++ lib/CodeGen/CGCall.cpp @@ -1722,6 +1722,13 @@ FuncAttrs.addAttribute("less-precise-fpmad", llvm::toStringRef(CodeGenOpts.LessPreciseFPMAD)); + + if (!CodeGenOpts.FPDenormalMode.empty()) + FuncAttrs.addAttribute("denormal-fp-math", + CodeGenOpts.FPDenormalMode); + + FuncAttrs.addAttribute("no-exceptions-fp-math", + llvm::toStringRef(CodeGenOpts.NoExceptionsFPMath)); FuncAttrs.addAttribute("no-infs-fp-math", llvm::toStringRef(CodeGenOpts.NoInfsFPMath)); FuncAttrs.addAttribute("no-nans-fp-math", Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -4362,6 +4362,15 @@ if (ReciprocalMath) CmdArgs.push_back("-freciprocal-math"); + if (Args.hasArg(options::OPT_fdenormal_fp_math_EQ)) + Args.AddLastArg(CmdArgs, options::OPT_fdenormal_fp_math_EQ); + + if (Arg * A = Args.getLastArg(options::OPT_fexceptions_fp_math, + options::OPT_fno_exceptions_fp_math)) { + if (A->getOption().getID() == options::OPT_fno_exceptions_fp_math) + CmdArgs.push_back("-fno-exceptions-fp-math"); + } + // Validate and pass through -fp-contract option. if (Arg *A = Args.getLastArg(options::OPT_ffast_math, FastMathAliasOption, options::OPT_fno_fast_math, Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -575,6 +575,7 @@ Opts.CorrectlyRoundedDivSqrt = Args.hasArg(OPT_cl_fp32_correctly_rounded_divide_sqrt); Opts.ReciprocalMath = Args.hasArg(OPT_freciprocal_math); + Opts.NoExceptionsFPMath = Args.hasArg(OPT_fno_exceptions_fp_math); 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); @@ -791,6 +792,18 @@ Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Val; } + if (Arg *A = Args.getLastArg(OPT_fdenormal_fp_math_EQ)) { + StringRef Val = A->getValue(); + if (Val == "ieee") + Opts.FPDenormalMode = "ieee"; + else if (Val == "preserve-sign") + Opts.FPDenormalMode = "preserve-sign"; + else if (Val == "positive-zero") + Opts.FPDenormalMode = "positive-zero"; + else + Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Val; + } + if (Arg *A = Args.getLastArg(OPT_fpcc_struct_return, OPT_freg_struct_return)) { if (A->getOption().matches(OPT_fpcc_struct_return)) { Opts.setStructReturnConvention(CodeGenOptions::SRCK_OnStack); Index: test/CodeGen/denormalfpmode.c =================================================================== --- /dev/null +++ test/CodeGen/denormalfpmode.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -S -fdenormal-fp-math=ieee %s -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-IEEE +// RUN: %clang_cc1 -S -fdenormal-fp-math=preserve-sign %s -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-PS +// RUN: %clang_cc1 -S -fdenormal-fp-math=positive-zero %s -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-PZ + +// CHECK-LABEL: main +// CHECK-IEEE: attributes #0 = {{.*}}"denormal-fp-math"="ieee"{{.*}} +// CHECK-PS: attributes #0 = {{.*}}"denormal-fp-math"="preserve-sign"{{.*}} +// CHECK-PZ: attributes #0 = {{.*}}"denormal-fp-math"="positive-zero"{{.*}} + +int main() { + return 0; +} Index: test/CodeGen/noexceptionsfpmath.c =================================================================== --- /dev/null +++ test/CodeGen/noexceptionsfpmath.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -S -fno-exceptions-fp-math %s -emit-llvm -o - | FileCheck %s + +// CHECK-LABEL: main +// CHECK: attributes #0 = {{.*}}"no-exceptions-fp-math"="true"{{.*}} + +int main() { + return 0; +} Index: test/Driver/fast-math.c =================================================================== --- test/Driver/fast-math.c +++ test/Driver/fast-math.c @@ -231,3 +231,20 @@ // CHECK-NO-UNSAFE-MATH: "-cc1" // CHECK-NO-UNSAFE-MATH-NOT: "-menable-unsafe-fp-math" // CHECK-NO-UNSAFE-MATH: "-o" +// +// RUN: %clang -### -fexceptions-fp-math -fno-exceptions-fp-math -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NO-FP-EXCEPTIONS %s +// RUN: %clang -### -fno-exceptions-fp-math -fexceptions-fp-math -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FP-EXCEPTIONS %s +// CHECK-NO-FP-EXCEPTIONS: "-fno-exceptions-fp-math" +// CHECK-FP-EXCEPTIONS-NOT: "-fno-exceptions-fp-math" +// +// RUN: %clang -### -fdenormal-fp-math=ieee -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FP-DENORMAL-IEEE %s +// RUN: %clang -### -fdenormal-fp-math=preserve-sign -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FP-DENORMAL-PS %s +// RUN: %clang -### -fdenormal-fp-math=positive-zero -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FP-DENORMAL-PZ %s +// CHECK-FP-DENORMAL-IEEE: "-fdenormal-fp-math=ieee" +// CHECK-FP-DENORMAL-PS: "-fdenormal-fp-math=preserve-sign" +// CHECK-FP-DENORMAL-PZ: "-fdenormal-fp-math=positive-zero"