[llvm] r325595 - [InstCombine] remove compound fdiv pattern folds

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 20 08:52:17 PST 2018


Author: spatel
Date: Tue Feb 20 08:52:17 2018
New Revision: 325595

URL: http://llvm.org/viewvc/llvm-project?rev=325595&view=rev
Log:
[InstCombine] remove compound fdiv pattern folds

These are fdiv-with-constant-divisor, so they already become
reciprocal multiplies. The last gap for vector ops should be
closed with rL325590.

It's possible that we're missing folds for some edge cases 
with denormal intermediate constants after deleting these,
but there are no tests for those patterns, and it would be 
better to handle denormals more consistently (and less 
conservatively) as noted in TODO comments.

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=325595&r1=325594&r2=325595&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Tue Feb 20 08:52:17 2018
@@ -1359,39 +1359,13 @@ Instruction *InstCombiner::visitFDiv(Bin
       if (Instruction *R = FoldOpIntoSelect(I, SI))
         return R;
 
-  bool AllowReassociate = I.isFast();
   if (Constant *Op1C = dyn_cast<Constant>(Op1)) {
     if (SelectInst *SI = dyn_cast<SelectInst>(Op0))
       if (Instruction *R = FoldOpIntoSelect(I, SI))
         return R;
-
-    if (AllowReassociate) {
-      Constant *C1 = nullptr;
-      Constant *C2 = Op1C;
-      Value *X;
-      Instruction *Res = nullptr;
-
-      if (match(Op0, m_FMul(m_Value(X), m_Constant(C1)))) {
-        // (X*C1)/C2 => X * (C1/C2)
-        Constant *C = ConstantExpr::getFDiv(C1, C2);
-        if (C->isNormalFP())
-          Res = BinaryOperator::CreateFMul(X, C);
-      } else if (match(Op0, m_FDiv(m_Value(X), m_Constant(C1)))) {
-        // (X/C1)/C2 => X /(C2*C1)
-        Constant *C = ConstantExpr::getFMul(C1, C2);
-        if (C->isNormalFP())
-          Res = BinaryOperator::CreateFDiv(X, C);
-      }
-
-      if (Res) {
-        Res->setFastMathFlags(I.getFastMathFlags());
-        return Res;
-      }
-    }
-    return nullptr;
   }
 
-  if (AllowReassociate) {
+  if (I.isFast()) {
     Value *X, *Y;
     if (match(Op0, m_OneUse(m_FDiv(m_Value(X), m_Value(Y)))) &&
         (!isa<Constant>(Y) || !isa<Constant>(Op1))) {




More information about the llvm-commits mailing list