[llvm] r258158 - [LibCallSimplifier] use instruction-level fast-math-flags to shrink calls

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 19 10:38:55 PST 2016


Author: spatel
Date: Tue Jan 19 12:38:52 2016
New Revision: 258158

URL: http://llvm.org/viewvc/llvm-project?rev=258158&view=rev
Log:
[LibCallSimplifier] use instruction-level fast-math-flags to shrink calls

This is a continuation of adding FMF to call instructions:
http://reviews.llvm.org/rL255555


Modified:
    llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
    llvm/trunk/test/Transforms/InstCombine/double-float-shrink-1.ll

Modified: llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp?rev=258158&r1=258157&r2=258158&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp Tue Jan 19 12:38:52 2016
@@ -104,23 +104,6 @@ static bool hasUnaryFloatFn(const Target
   }
 }
 
-/// \brief Check whether we can use unsafe floating point math for
-/// the function passed as input.
-static bool canUseUnsafeFPMath(Function *F) {
-
-  // FIXME: For finer-grain optimization, we need intrinsics to have the same
-  // fast-math flag decorations that are applied to FP instructions. For now,
-  // we have to rely on the function-level unsafe-fp-math attribute to do this
-  // optimization because there's no other way to express that the call can be
-  // relaxed.
-  if (F->hasFnAttribute("unsafe-fp-math")) {
-    Attribute Attr = F->getFnAttribute("unsafe-fp-math");
-    if (Attr.getValueAsString() == "true")
-      return true;
-  }
-  return false;
-}
-
 /// \brief Returns whether \p F matches the signature expected for the
 /// string/memory copying library function \p Func.
 /// Acceptable functions are st[rp][n]?cpy, memove, memcpy, and memset.
@@ -2184,10 +2167,10 @@ Value *LibCallSimplifier::optimizeCall(C
   IRBuilder<> Builder(CI, /*FPMathTag=*/nullptr, OpBundles);
   bool isCallingConvC = CI->getCallingConv() == llvm::CallingConv::C;
 
-  // Command-line parameter overrides function attribute.
+  // Command-line parameter overrides instruction attribute.
   if (EnableUnsafeFPShrink.getNumOccurrences() > 0)
     UnsafeFPShrink = EnableUnsafeFPShrink;
-  else if (canUseUnsafeFPMath(Callee))
+  else if (isa<FPMathOperator>(CI) && CI->hasUnsafeAlgebra())
     UnsafeFPShrink = true;
 
   // First, check for intrinsics.

Modified: llvm/trunk/test/Transforms/InstCombine/double-float-shrink-1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/double-float-shrink-1.ll?rev=258158&r1=258157&r2=258158&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/double-float-shrink-1.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/double-float-shrink-1.ll Tue Jan 19 12:38:52 2016
@@ -366,30 +366,28 @@ define float @max1(float %a, float %b) {
 
 declare double @fmax(double, double)
 
-declare double @tanh(double) #1
-declare double @tan(double) #1
+declare double @tanh(double)
+declare double @tan(double)
 
 ; sqrt is a special case: the shrinking optimization 
 ; is valid even without unsafe-fp-math.
 declare double @sqrt(double) 
 declare double @llvm.sqrt.f64(double) 
 
-declare double @sin(double) #1
-declare double @log2(double) #1
-declare double @log1p(double) #1
-declare double @log10(double) #1
-declare double @log(double) #1
-declare double @logb(double) #1
-declare double @exp10(double) #1
-declare double @expm1(double) #1
-declare double @exp(double) #1
-declare double @cbrt(double) #1
-declare double @atanh(double) #1
-declare double @atan(double) #1
-declare double @acos(double) #1
-declare double @acosh(double) #1
-declare double @asin(double) #1
-declare double @asinh(double) #1
-
-attributes #1 = { "unsafe-fp-math"="true" }
+declare double @sin(double)
+declare double @log2(double)
+declare double @log1p(double)
+declare double @log10(double)
+declare double @log(double)
+declare double @logb(double)
+declare double @exp10(double)
+declare double @expm1(double)
+declare double @exp(double)
+declare double @cbrt(double)
+declare double @atanh(double)
+declare double @atan(double)
+declare double @acos(double)
+declare double @acosh(double)
+declare double @asin(double)
+declare double @asinh(double)
 




More information about the llvm-commits mailing list