From: Sanjay Patel Date: Tue, 20 Feb 2018 16:52:17 +0000 (+0000) Subject: [InstCombine] remove compound fdiv pattern folds X-Git-Tag: llvmorg-7.0.0-rc1~12434 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b2d978682b2ddd957d802d209a338f89031fabc0;p=platform%2Fupstream%2Fllvm.git [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. llvm-svn: 325595 --- diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index 7b15076..17f8e30 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -1359,39 +1359,13 @@ Instruction *InstCombiner::visitFDiv(BinaryOperator &I) { if (Instruction *R = FoldOpIntoSelect(I, SI)) return R; - bool AllowReassociate = I.isFast(); if (Constant *Op1C = dyn_cast(Op1)) { if (SelectInst *SI = dyn_cast(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(Y) || !isa(Op1))) {