Make GVN's propagateEquality non-recursive. No intended functionality change.
The modifications are a lot more trivial than they appear to be in the diff! llvm-svn: 154174
This commit is contained in:
parent
6f86004cbc
commit
d12b18f820
|
@ -1974,12 +1974,19 @@ unsigned GVN::replaceAllDominatedUsesWith(Value *From, Value *To,
|
|||
/// dominated by 'Root'. Exploit this, for example by replacing 'LHS' with
|
||||
/// 'RHS' everywhere in the scope. Returns whether a change was made.
|
||||
bool GVN::propagateEquality(Value *LHS, Value *RHS, BasicBlock *Root) {
|
||||
if (LHS == RHS) return false;
|
||||
assert(LHS->getType() == RHS->getType() && "Equal but types differ!");
|
||||
SmallVector<std::pair<Value*, Value*>, 4> Worklist;
|
||||
Worklist.push_back(std::make_pair(LHS, RHS));
|
||||
bool Changed = false;
|
||||
|
||||
while (!Worklist.empty()) {
|
||||
std::pair<Value*, Value*> Item = Worklist.pop_back_val();
|
||||
LHS = Item.first; RHS = Item.second;
|
||||
|
||||
if (LHS == RHS) continue;
|
||||
assert(LHS->getType() == RHS->getType() && "Equality but unequal types!");
|
||||
|
||||
// Don't try to propagate equalities between constants.
|
||||
if (isa<Constant>(LHS) && isa<Constant>(RHS))
|
||||
return false;
|
||||
if (isa<Constant>(LHS) && isa<Constant>(RHS)) continue;
|
||||
|
||||
// Prefer a constant on the right-hand side, or an Argument if no constants.
|
||||
if (isa<Constant>(LHS) || (isa<Argument>(LHS) && !isa<Constant>(RHS)))
|
||||
|
@ -2012,7 +2019,6 @@ bool GVN::propagateEquality(Value *LHS, Value *RHS, BasicBlock *Root) {
|
|||
// Replace all occurrences of 'LHS' with 'RHS' everywhere in the scope. As
|
||||
// LHS always has at least one use that is not dominated by Root, this will
|
||||
// never do anything if LHS has only one use.
|
||||
bool Changed = false;
|
||||
if (!LHS->hasOneUse()) {
|
||||
unsigned NumReplacements = replaceAllDominatedUsesWith(LHS, RHS, Root);
|
||||
Changed |= NumReplacements > 0;
|
||||
|
@ -2025,11 +2031,11 @@ bool GVN::propagateEquality(Value *LHS, Value *RHS, BasicBlock *Root) {
|
|||
// RHS are currently supported.
|
||||
if (!RHS->getType()->isIntegerTy(1))
|
||||
// Not a boolean equality - bail out.
|
||||
return Changed;
|
||||
continue;
|
||||
ConstantInt *CI = dyn_cast<ConstantInt>(RHS);
|
||||
if (!CI)
|
||||
// RHS neither 'true' nor 'false' - bail out.
|
||||
return Changed;
|
||||
continue;
|
||||
// Whether RHS equals 'true'. Otherwise it equals 'false'.
|
||||
bool isKnownTrue = CI->isAllOnesValue();
|
||||
bool isKnownFalse = !isKnownTrue;
|
||||
|
@ -2039,9 +2045,9 @@ bool GVN::propagateEquality(Value *LHS, Value *RHS, BasicBlock *Root) {
|
|||
Value *A, *B;
|
||||
if ((isKnownTrue && match(LHS, m_And(m_Value(A), m_Value(B)))) ||
|
||||
(isKnownFalse && match(LHS, m_Or(m_Value(A), m_Value(B))))) {
|
||||
Changed |= propagateEquality(A, RHS, Root);
|
||||
Changed |= propagateEquality(B, RHS, Root);
|
||||
return Changed;
|
||||
Worklist.push_back(std::make_pair(A, RHS));
|
||||
Worklist.push_back(std::make_pair(B, RHS));
|
||||
continue;
|
||||
}
|
||||
|
||||
// If we are propagating an equality like "(A == B)" == "true" then also
|
||||
|
@ -2054,7 +2060,7 @@ bool GVN::propagateEquality(Value *LHS, Value *RHS, BasicBlock *Root) {
|
|||
// A with B everywhere in the scope.
|
||||
if ((isKnownTrue && Cmp->getPredicate() == CmpInst::ICMP_EQ) ||
|
||||
(isKnownFalse && Cmp->getPredicate() == CmpInst::ICMP_NE))
|
||||
Changed |= propagateEquality(Op0, Op1, Root);
|
||||
Worklist.push_back(std::make_pair(Op0, Op1));
|
||||
|
||||
// If "A >= B" is known true, replace "A < B" with false everywhere.
|
||||
CmpInst::Predicate NotPred = Cmp->getInversePredicate();
|
||||
|
@ -2079,7 +2085,8 @@ bool GVN::propagateEquality(Value *LHS, Value *RHS, BasicBlock *Root) {
|
|||
// is replaced with false.
|
||||
addToLeaderTable(Num, NotVal, Root);
|
||||
|
||||
return Changed;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return Changed;
|
||||
|
|
Loading…
Reference in New Issue