aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-05-03 17:00:11 +0000
committerDan Gohman <gohman@apple.com>2010-05-03 17:00:11 +0000
commit6d4e684297d1f31943283c52bca2664920c3c71b (patch)
treea0030723c28e9b74a7b1041f3f0defbf2c78c885
parent4bdc8deea96b2cc8dff8bc898fe80a20cdcfc809 (diff)
downloadexternal_llvm-6d4e684297d1f31943283c52bca2664920c3c71b.zip
external_llvm-6d4e684297d1f31943283c52bca2664920c3c71b.tar.gz
external_llvm-6d4e684297d1f31943283c52bca2664920c3c71b.tar.bz2
In SimplifyICmpOperands, avoid needlessly swapping the operands in the
case where both are addrecs in unrelated loops. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@102924 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Analysis/ScalarEvolution.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index fea0a7a..2a502cd 100644
--- a/lib/Analysis/ScalarEvolution.cpp
+++ b/lib/Analysis/ScalarEvolution.cpp
@@ -4783,13 +4783,16 @@ bool ScalarEvolution::SimplifyICmpOperands(ICmpInst::Predicate &Pred,
}
// If we're comparing an addrec with a value which is loop-invariant in the
- // addrec's loop, put the addrec on the left.
- if (const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(RHS))
- if (LHS->isLoopInvariant(AR->getLoop())) {
+ // addrec's loop, put the addrec on the left. Also make a dominance check,
+ // as both operands could be addrecs loop-invariant in each other's loop.
+ if (const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(RHS)) {
+ const Loop *L = AR->getLoop();
+ if (LHS->isLoopInvariant(L) && LHS->properlyDominates(L->getHeader(), DT)) {
std::swap(LHS, RHS);
Pred = ICmpInst::getSwappedPredicate(Pred);
Changed = true;
}
+ }
// If there's a constant operand, canonicalize comparisons with boundary
// cases, and canonicalize *-or-equal comparisons to regular comparisons.