[LibCallSimplifier] propagate FMF when shrinking binary calls
authorSanjay Patel <spatel@rotateright.com>
Thu, 31 Dec 2015 23:40:59 +0000 (23:40 +0000)
committerSanjay Patel <spatel@rotateright.com>
Thu, 31 Dec 2015 23:40:59 +0000 (23:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256682 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/SimplifyLibCalls.cpp
test/Transforms/InstCombine/double-float-shrink-1.ll

index 2eba5fe31e0901573aa9def1e5db3e1eeee77bab..bf158949de0c43aca31b6b5c3cb28d6e63f30773 100644 (file)
@@ -1033,6 +1033,10 @@ Value *LibCallSimplifier::optimizeBinaryDoubleFP(CallInst *CI, IRBuilder<> &B) {
   if (V2 == nullptr)
     return nullptr;
 
+  // Propagate fast-math flags from the existing call to the new call.
+  IRBuilder<>::FastMathFlagGuard Guard(B);
+  B.SetFastMathFlags(CI->getFastMathFlags());
+
   // fmin((double)floatval1, (double)floatval2)
   //                      -> (double)fminf(floatval1, floatval2)
   // TODO: Handle intrinsics in the same way as in optimizeUnaryDoubleFP().
index 78c60ca6744b8472e95c8747e84fa67f53bef85e..319ea32598306799056e38c4b8f85313e7e9fe65 100644 (file)
@@ -350,6 +350,22 @@ define double @tanh_test2(float %f) {
 ; CHECK: call fast double @tanh(double %conv)
 }
 
+; 'arcp' on an fmax() is meaningless. This test just proves that
+; flags are propagated for shrunken *binary* double FP calls.
+define float @max1(float %a, float %b) {
+  %c = fpext float %a to double
+  %d = fpext float %b to double
+  %e = call arcp double @fmax(double %c, double %d)
+  %f = fptrunc double %e to float
+  ret float %f
+
+; CHECK-LABEL: max1(
+; CHECK-NEXT:  call arcp float @fmaxf(float %a, float %b)
+; CHECK-NEXT:  ret
+}
+
+declare double @fmax(double, double)
+
 declare double @tanh(double) #1
 declare double @tan(double) #1