[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

llvm-svn: 258158
This commit is contained in:
Sanjay Patel 2016-01-19 18:38:52 +00:00
parent 0f6650e8e8
commit d1f4f03f5e
2 changed files with 20 additions and 39 deletions

View File

@ -104,23 +104,6 @@ static bool hasUnaryFloatFn(const TargetLibraryInfo *TLI, Type *Ty,
}
}
/// \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(CallInst *CI) {
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.

View File

@ -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)