[llvm] r325968 - [InstCombine] simplify code for fabs(X) * fabs(X) -> X * X; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 23 14:38:10 PST 2018


Author: spatel
Date: Fri Feb 23 14:38:10 2018
New Revision: 325968

URL: http://llvm.org/viewvc/llvm-project?rev=325968&view=rev
Log:
[InstCombine] simplify code for fabs(X) * fabs(X) -> X * X; NFC

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp?rev=325968&r1=325967&r2=325968&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Fri Feb 23 14:38:10 2018
@@ -618,18 +618,10 @@ Instruction *InstCombiner::visitFMul(Bin
     }
   }
 
-  if (Op0 == Op1) {
-    if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Op0)) {
-      // fabs(X) * fabs(X) -> X * X
-      if (II->getIntrinsicID() == Intrinsic::fabs) {
-        Instruction *FMulVal = BinaryOperator::CreateFMul(II->getOperand(0),
-                                                          II->getOperand(0),
-                                                          I.getName());
-        FMulVal->copyFastMathFlags(&I);
-        return FMulVal;
-      }
-    }
-  }
+  // fabs(X) * fabs(X) -> X * X
+  Value *X, *Y;
+  if (Op0 == Op1 && match(Op0, m_Intrinsic<Intrinsic::fabs>(m_Value(X))))
+    return BinaryOperator::CreateFMulFMF(X, X, &I);
 
   // Under unsafe algebra do:
   // X * log2(0.5*Y) = X*log2(Y) - X
@@ -659,7 +651,6 @@ Instruction *InstCombiner::visitFMul(Bin
   }
 
   // sqrt(X) * sqrt(Y) -> sqrt(X * Y)
-  Value *X, *Y;
   if (I.hasAllowReassoc() &&
       match(Op0, m_OneUse(m_Intrinsic<Intrinsic::sqrt>(m_Value(X)))) &&
       match(Op1, m_OneUse(m_Intrinsic<Intrinsic::sqrt>(m_Value(Y))))) {




More information about the llvm-commits mailing list