From: Sanjay Patel <spatel@rotateright.com>
Date: Thu, 31 Dec 2015 23:40:59 +0000 (+0000)
Subject: [LibCallSimplifier] propagate FMF when shrinking binary calls
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=e193ff319c736fa0eaeefb8a6dfc900545324faa;p=oota-llvm.git

[LibCallSimplifier] propagate FMF when shrinking binary calls


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256682 91177308-0d34-0410-b5e6-96231b3b80d8
---

diff --git a/lib/Transforms/Utils/SimplifyLibCalls.cpp b/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 2eba5fe31e0..bf158949de0 100644
--- a/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -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().
diff --git a/test/Transforms/InstCombine/double-float-shrink-1.ll b/test/Transforms/InstCombine/double-float-shrink-1.ll
index 78c60ca6744..319ea325983 100644
--- a/test/Transforms/InstCombine/double-float-shrink-1.ll
+++ b/test/Transforms/InstCombine/double-float-shrink-1.ll
@@ -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