From: Chris Lattner Date: Fri, 2 Sep 2005 07:07:58 +0000 (+0000) Subject: Fix a problem that Dan Berlin noticed, where reassociation would not succeed X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=7b4ad94282b94e1827be29b4db73fdf6e241f748;p=oota-llvm.git Fix a problem that Dan Berlin noticed, where reassociation would not succeed in building maximal expressions before simplifying them. In particular, i cases like this: X-(A+B+X) the code would consider A+B+X to be a maximal expression (not understanding that the single use '-' would be turned into a + later), simplify it (a noop) then later get simplified again. Each of these simplify steps is where the cost of reassociation comes from, so this patch should speed up the already fast pass a bit. Thanks to Dan for noticing this! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23214 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/Reassociate.cpp b/lib/Transforms/Scalar/Reassociate.cpp index fb143c98279..142ede38e1c 100644 --- a/lib/Transforms/Scalar/Reassociate.cpp +++ b/lib/Transforms/Scalar/Reassociate.cpp @@ -612,6 +612,12 @@ void Reassociate::ReassociateBB(BasicBlock *BB) { if (I->hasOneUse() && isReassociableOp(I->use_back(), I->getOpcode())) continue; + // If this is an add tree that is used by a sub instruction, ignore it + // until we process the subtract. + if (I->hasOneUse() && I->getOpcode() == Instruction::Add && + cast(I->use_back())->getOpcode() == Instruction::Sub) + continue; + // First, walk the expression tree, linearizing the tree, collecting std::vector Ops; LinearizeExprTree(I, Ops);