Fix a problem that Dan Berlin noticed, where reassociation would not succeed
authorChris Lattner <sabre@nondot.org>
Fri, 2 Sep 2005 07:07:58 +0000 (07:07 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 2 Sep 2005 07:07:58 +0000 (07:07 +0000)
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

lib/Transforms/Scalar/Reassociate.cpp

index fb143c98279d44756c1e4782b8be348f2ac9c267..142ede38e1ca6e77ae6f7a8430e9e6cc86c65533 100644 (file)
@@ -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<Instruction>(I->use_back())->getOpcode() == Instruction::Sub)
+      continue;
+
     // First, walk the expression tree, linearizing the tree, collecting
     std::vector<ValueEntry> Ops;
     LinearizeExprTree(I, Ops);