diff options
author | Dan Gohman <gohman@apple.com> | 2010-08-12 14:46:54 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-08-12 14:46:54 +0000 |
commit | dc7692b1ad3b2f7eaa7f21504826af7ce1e3b573 (patch) | |
tree | 78a4ae0983e39ebafeb9ccfd6d591bf25ea94fea /lib/Analysis/ScalarEvolution.cpp | |
parent | 335db223926931db204bf54d4accac6677b8e6b1 (diff) |
Optimize ScalarEvolution::getAddExpr's duplicate operand detection
by having it finish processing the whole operand list before
starting the whole getAddExpr process over again, instead of
immediately after the first duplicate is found.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@110914 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ScalarEvolution.cpp')
-rw-r--r-- | lib/Analysis/ScalarEvolution.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index b3ddfc032f..6e41048544 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -1373,6 +1373,7 @@ const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl<const SCEV *> &Ops, // so, merge them together into an multiply expression. Since we sorted the // list, these values are required to be adjacent. const Type *Ty = Ops[0]->getType(); + bool FoundMatch = false; for (unsigned i = 0, e = Ops.size()-1; i != e; ++i) if (Ops[i] == Ops[i+1]) { // X + Y + Y --> X + Y*2 // Found a match, merge the two values into a multiply, and add any @@ -1381,10 +1382,13 @@ const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl<const SCEV *> &Ops, const SCEV *Mul = getMulExpr(Ops[i], Two); if (Ops.size() == 2) return Mul; - Ops.erase(Ops.begin()+i, Ops.begin()+i+2); - Ops.push_back(Mul); - return getAddExpr(Ops, HasNUW, HasNSW); + Ops[i] = Mul; + Ops.erase(Ops.begin()+i+1); + --i; --e; + FoundMatch = true; } + if (FoundMatch) + return getAddExpr(Ops, HasNUW, HasNSW); // Check for truncates. If all the operands are truncated from the same // type, see if factoring out the truncate would permit the result to be |