[llvm-branch-commits] [cfe-branch] r331731 - Cherry-pick @=r331041 to google/stable for 2018-04-24

David L. Jones via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon May 7 21:12:13 PDT 2018


Author: dlj
Date: Mon May  7 21:12:13 2018
New Revision: 331731

URL: http://llvm.org/viewvc/llvm-project?rev=331731&view=rev
Log:
Cherry-pick @=r331041 to google/stable for 2018-04-24

Added:
    cfe/branches/google/stable/test/CodeGen/no-junk-ftrunc.c
      - copied unchanged from r331041, cfe/trunk/test/CodeGen/no-junk-ftrunc.c
Modified:
    cfe/branches/google/stable/   (props changed)
    cfe/branches/google/stable/BRANCH_HISTORY
    cfe/branches/google/stable/docs/UsersManual.rst
    cfe/branches/google/stable/include/clang/Driver/Options.td
    cfe/branches/google/stable/include/clang/Frontend/CodeGenOptions.def
    cfe/branches/google/stable/lib/CodeGen/CGCall.cpp
    cfe/branches/google/stable/lib/Driver/ToolChains/Clang.cpp
    cfe/branches/google/stable/lib/Frontend/CompilerInvocation.cpp
    cfe/branches/google/stable/test/Driver/fast-math.c

Propchange: cfe/branches/google/stable/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon May  7 21:12:13 2018
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:330997
+/cfe/trunk:330997,331041
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/google/stable/BRANCH_HISTORY
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/google/stable/BRANCH_HISTORY?rev=331731&r1=331730&r2=331731&view=diff
==============================================================================
--- cfe/branches/google/stable/BRANCH_HISTORY (original)
+++ cfe/branches/google/stable/BRANCH_HISTORY Mon May  7 21:12:13 2018
@@ -1,2 +1,3 @@
 @r330764
 @=r330997
+@=r331041

Modified: cfe/branches/google/stable/docs/UsersManual.rst
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/google/stable/docs/UsersManual.rst?rev=331731&r1=331730&r2=331731&view=diff
==============================================================================
--- cfe/branches/google/stable/docs/UsersManual.rst (original)
+++ cfe/branches/google/stable/docs/UsersManual.rst Mon May  7 21:12:13 2018
@@ -1255,6 +1255,16 @@ are listed below.
    flushed-to-zero number is preserved in the sign of 0, denormals are
    flushed to positive zero, respectively.
 
+.. option:: -f[no-]fp-cast-overflow-workaround
+
+   Enable a workaround for code that casts floating-point values to 
+   integers and back to floating-point. If the floating-point value 
+   is not representable in the intermediate integer type, the code is
+   incorrect according to the language standard. This flag will attempt 
+   to generate code as if the result of an overflowing conversion matches
+   the overflowing behavior of a target's native float-to-int conversion
+   instructions.
+
 .. option:: -fwhole-program-vtables
 
    Enable whole-program vtable optimizations, such as single-implementation

Modified: cfe/branches/google/stable/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/google/stable/include/clang/Driver/Options.td?rev=331731&r1=331730&r2=331731&view=diff
==============================================================================
--- cfe/branches/google/stable/include/clang/Driver/Options.td (original)
+++ cfe/branches/google/stable/include/clang/Driver/Options.td Mon May  7 21:12:13 2018
@@ -1029,6 +1029,11 @@ def ffp_contract : Joined<["-"], "ffp-co
   Flags<[CC1Option]>, HelpText<"Form fused FP ops (e.g. FMAs): fast (everywhere)"
   " | on (according to FP_CONTRACT pragma, default) | off (never fuse)">, Values<"fast,on,off">;
 
+def ffp_cast_overflow_workaround : Flag<["-"],
+  "ffp-cast-overflow-workaround">, Group<f_Group>, Flags<[CC1Option]>;
+def fno_fp_cast_overflow_workaround : Flag<["-"],
+  "fno-fp-cast-overflow-workaround">, Group<f_Group>, Flags<[CC1Option]>;
+
 def ffor_scope : Flag<["-"], "ffor-scope">, Group<f_Group>;
 def fno_for_scope : Flag<["-"], "fno-for-scope">, Group<f_Group>;
 

Modified: cfe/branches/google/stable/include/clang/Frontend/CodeGenOptions.def
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/google/stable/include/clang/Frontend/CodeGenOptions.def?rev=331731&r1=331730&r2=331731&view=diff
==============================================================================
--- cfe/branches/google/stable/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/branches/google/stable/include/clang/Frontend/CodeGenOptions.def Mon May  7 21:12:13 2018
@@ -136,6 +136,12 @@ CODEGENOPT(NoTrappingMath    , 1, 0) ///
 CODEGENOPT(NoNaNsFPMath      , 1, 0) ///< Assume FP arguments, results not NaN.
 CODEGENOPT(FlushDenorm       , 1, 0) ///< Allow FP denorm numbers to be flushed to zero
 CODEGENOPT(CorrectlyRoundedDivSqrt, 1, 0) ///< -cl-fp32-correctly-rounded-divide-sqrt
+
+/// Disable a float-to-int-to-float cast optimization. This attempts to generate
+/// code as if the result of an overflowing conversion matches the overflowing
+/// behavior of a target's native float-to-int conversion instructions.
+CODEGENOPT(FPCastOverflowWorkaround, 1, 0)
+
 CODEGENOPT(UniformWGSize     , 1, 0) ///< -cl-uniform-work-group-size
 CODEGENOPT(NoZeroInitializedInBSS , 1, 0) ///< -fno-zero-initialized-in-bss.
 /// \brief Method of Objective-C dispatch to use.

Modified: cfe/branches/google/stable/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/google/stable/lib/CodeGen/CGCall.cpp?rev=331731&r1=331730&r2=331731&view=diff
==============================================================================
--- cfe/branches/google/stable/lib/CodeGen/CGCall.cpp (original)
+++ cfe/branches/google/stable/lib/CodeGen/CGCall.cpp Mon May  7 21:12:13 2018
@@ -1727,6 +1727,9 @@ void CodeGenModule::ConstructDefaultFnAt
     FuncAttrs.addAttribute("no-trapping-math",
                            llvm::toStringRef(CodeGenOpts.NoTrappingMath));
 
+    if (CodeGenOpts.FPCastOverflowWorkaround)
+      FuncAttrs.addAttribute("fp-cast-overflow-workaround", "true");
+
     // TODO: Are these all needed?
     // unsafe/inf/nan/nsz are handled by instruction-level FastMathFlags.
     FuncAttrs.addAttribute("no-infs-fp-math",

Modified: cfe/branches/google/stable/lib/Driver/ToolChains/Clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/google/stable/lib/Driver/ToolChains/Clang.cpp?rev=331731&r1=331730&r2=331731&view=diff
==============================================================================
--- cfe/branches/google/stable/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/branches/google/stable/lib/Driver/ToolChains/Clang.cpp Mon May  7 21:12:13 2018
@@ -2241,6 +2241,11 @@ static void RenderFloatingPointOptions(c
     CmdArgs.push_back("-mfpmath");
     CmdArgs.push_back(A->getValue());
   }
+
+  // Disable a codegen optimization for floating-point casts.
+  if (Args.hasFlag(options::OPT_ffp_cast_overflow_workaround,
+                   options::OPT_fno_fp_cast_overflow_workaround, false))
+    CmdArgs.push_back("-ffp-cast-overflow-workaround");
 }
 
 static void RenderAnalyzerOptions(const ArgList &Args, ArgStringList &CmdArgs,

Modified: cfe/branches/google/stable/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/google/stable/lib/Frontend/CompilerInvocation.cpp?rev=331731&r1=331730&r2=331731&view=diff
==============================================================================
--- cfe/branches/google/stable/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/branches/google/stable/lib/Frontend/CompilerInvocation.cpp Mon May  7 21:12:13 2018
@@ -699,6 +699,8 @@ static bool ParseCodeGenArgs(CodeGenOpti
   Opts.Reciprocals = Args.getAllArgValues(OPT_mrecip_EQ);
   Opts.ReciprocalMath = Args.hasArg(OPT_freciprocal_math);
   Opts.NoTrappingMath = Args.hasArg(OPT_fno_trapping_math);
+  Opts.FPCastOverflowWorkaround = Args.hasArg(OPT_ffp_cast_overflow_workaround);
+
   Opts.NoZeroInitializedInBSS = Args.hasArg(OPT_mno_zero_initialized_in_bss);
   Opts.NumRegisterParameters = getLastArgIntValue(Args, OPT_mregparm, 0, Diags);
   Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack);

Modified: cfe/branches/google/stable/test/Driver/fast-math.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/google/stable/test/Driver/fast-math.c?rev=331731&r1=331730&r2=331731&view=diff
==============================================================================
--- cfe/branches/google/stable/test/Driver/fast-math.c (original)
+++ cfe/branches/google/stable/test/Driver/fast-math.c Mon May  7 21:12:13 2018
@@ -287,3 +287,27 @@
 // RUN: %clang -### -ftrapping-math -fno-trapping-math -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-TRAPPING-MATH %s
 // CHECK-NO-TRAPPING-MATH: "-fno-trapping-math"
+
+// This isn't fast-math, but the option is handled in the same place as other FP params.
+// Last option wins, and the flag is *not* passed by default. 
+
+// RUN: %clang -### -ffp-cast-overflow-workaround -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPOV-WORKAROUND %s
+// CHECK-FPOV-WORKAROUND: "-cc1"
+// CHECK-FPOV-WORKAROUND: "-ffp-cast-overflow-workaround"
+
+// RUN: %clang -### -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPOV-WORKAROUND-DEFAULT %s
+// CHECK-FPOV-WORKAROUND-DEFAULT: "-cc1"
+// CHECK-FPOV-WORKAROUND-DEFAULT-NOT: "-ffp-cast-overflow-workaround"
+
+// RUN: %clang -### -fno-fp-cast-overflow-workaround -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-FPOV-WORKAROUND %s
+// CHECK-NO-FPOV-WORKAROUND: "-cc1"
+// CHECK-NO-FPOV-WORKAROUND-NOT: "-ffp-cast-overflow-workaround"
+
+// RUN: %clang -### -ffp-cast-overflow-workaround -fno-fp-cast-overflow-workaround -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-FPOV-WORKAROUND-OVERRIDE %s
+// CHECK-NO-FPOV-WORKAROUND-OVERRIDE: "-cc1"
+// CHECK-NO-FPOV-WORKAROUND-OVERRIDE-NOT: "-ffp-cast-overflow-workaround"
+




More information about the llvm-branch-commits mailing list