[llvm] r257404 - [LibCallSimplifier] don't allow sqrt transform unless all ops are unsafe
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 11 14:50:36 PST 2016
Author: spatel
Date: Mon Jan 11 16:50:36 2016
New Revision: 257404
URL: http://llvm.org/viewvc/llvm-project?rev=257404&view=rev
Log:
[LibCallSimplifier] don't allow sqrt transform unless all ops are unsafe
Fix the FIXME added with:
http://reviews.llvm.org/rL257400
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/trunk/test/Transforms/InstCombine/fast-math.ll
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp?rev=257404&r1=257403&r2=257404&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp Mon Jan 11 16:50:36 2016
@@ -1422,10 +1422,10 @@ Value *LibCallSimplifier::optimizeSqrt(C
// 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<Instruction>(Op0)->hasUnsafeAlgebra()) {
// Matched: sqrt((x * x) * z)
RepeatOp = OtherMul0;
OtherOp = Op1;
Modified: llvm/trunk/test/Transforms/InstCombine/fast-math.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fast-math.ll?rev=257404&r1=257403&r2=257404&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fast-math.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fast-math.ll Mon Jan 11 16:50:36 2016
@@ -649,6 +649,21 @@ define double @sqrt_intrinsic_three_args
; 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
More information about the llvm-commits
mailing list