From: Sanjay Patel Date: Mon, 11 Jan 2016 22:50:36 +0000 (+0000) Subject: [LibCallSimplifier] don't allow sqrt transform unless all ops are unsafe X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=be014a6bcf10c957eab4e6bba3db59045186e309;p=oota-llvm.git [LibCallSimplifier] don't allow sqrt transform unless all ops are unsafe Fix the FIXME added with: http://reviews.llvm.org/rL257400 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257404 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Utils/SimplifyLibCalls.cpp b/lib/Transforms/Utils/SimplifyLibCalls.cpp index ed7ad7a6d2d..ef700499ef2 100644 --- a/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -1422,10 +1422,10 @@ Value *LibCallSimplifier::optimizeSqrt(CallInst *CI, IRBuilder<> &B) { // variations of this pattern because instcombine's visitFMUL and/or the // reassociation pass should give us this form. Value *OtherMul0, *OtherMul1; - // FIXME: This multiply must be unsafe to allow this transform. if (match(Op0, m_FMul(m_Value(OtherMul0), m_Value(OtherMul1)))) { // Pattern: sqrt((x * y) * z) - if (OtherMul0 == OtherMul1) { + if (OtherMul0 == OtherMul1 && + cast(Op0)->hasUnsafeAlgebra()) { // Matched: sqrt((x * x) * z) RepeatOp = OtherMul0; OtherOp = Op1; diff --git a/test/Transforms/InstCombine/fast-math.ll b/test/Transforms/InstCombine/fast-math.ll index b24ce278ca8..6ccf6e9fa77 100644 --- a/test/Transforms/InstCombine/fast-math.ll +++ b/test/Transforms/InstCombine/fast-math.ll @@ -649,6 +649,21 @@ define double @sqrt_intrinsic_three_args6(double %x, double %y) { ; CHECK-NEXT: ret double %1 } +; If any operation is not 'fast', we can't simplify. + +define double @sqrt_intrinsic_not_so_fast(double %x, double %y) { + %mul = fmul double %x, %x + %mul2 = fmul fast double %mul, %y + %sqrt = call fast double @llvm.sqrt.f64(double %mul2) + ret double %sqrt + +; CHECK-LABEL: sqrt_intrinsic_not_so_fast( +; CHECK-NEXT: %mul = fmul double %x, %x +; CHECK-NEXT: %mul2 = fmul fast double %mul, %y +; CHECK-NEXT: %sqrt = call fast double @llvm.sqrt.f64(double %mul2) +; CHECK-NEXT: ret double %sqrt +} + define double @sqrt_intrinsic_arg_4th(double %x) { %mul = fmul fast double %x, %x %mul2 = fmul fast double %mul, %mul