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
|
/// dominated by 'Root'. Exploit this, for example by replacing 'LHS' with
|
||||||
/// 'RHS' everywhere in the scope. Returns whether a change was made.
|
/// 'RHS' everywhere in the scope. Returns whether a change was made.
|
||||||
bool GVN::propagateEquality(Value *LHS, Value *RHS, BasicBlock *Root) {
|
bool GVN::propagateEquality(Value *LHS, Value *RHS, BasicBlock *Root) {
|
||||||
if (LHS == RHS) return false;
|
SmallVector<std::pair<Value*, Value*>, 4> Worklist;
|
||||||
assert(LHS->getType() == RHS->getType() && "Equal but types differ!");
|
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.
|
// Don't try to propagate equalities between constants.
|
||||||
if (isa<Constant>(LHS) && isa<Constant>(RHS))
|
if (isa<Constant>(LHS) && isa<Constant>(RHS)) continue;
|
||||||
return false;
|
|
||||||
|
|
||||||
// Prefer a constant on the right-hand side, or an Argument if no constants.
|
// Prefer a constant on the right-hand side, or an Argument if no constants.
|
||||||
if (isa<Constant>(LHS) || (isa<Argument>(LHS) && !isa<Constant>(RHS)))
|
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
|
// 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
|
// LHS always has at least one use that is not dominated by Root, this will
|
||||||
// never do anything if LHS has only one use.
|
// never do anything if LHS has only one use.
|
||||||
bool Changed = false;
|
|
||||||
if (!LHS->hasOneUse()) {
|
if (!LHS->hasOneUse()) {
|
||||||
unsigned NumReplacements = replaceAllDominatedUsesWith(LHS, RHS, Root);
|
unsigned NumReplacements = replaceAllDominatedUsesWith(LHS, RHS, Root);
|
||||||
Changed |= NumReplacements > 0;
|
Changed |= NumReplacements > 0;
|
||||||
|
@ -2025,11 +2031,11 @@ bool GVN::propagateEquality(Value *LHS, Value *RHS, BasicBlock *Root) {
|
||||||
// RHS are currently supported.
|
// RHS are currently supported.
|
||||||
if (!RHS->getType()->isIntegerTy(1))
|
if (!RHS->getType()->isIntegerTy(1))
|
||||||
// Not a boolean equality - bail out.
|
// Not a boolean equality - bail out.
|
||||||
return Changed;
|
continue;
|
||||||
ConstantInt *CI = dyn_cast<ConstantInt>(RHS);
|
ConstantInt *CI = dyn_cast<ConstantInt>(RHS);
|
||||||
if (!CI)
|
if (!CI)
|
||||||
// RHS neither 'true' nor 'false' - bail out.
|
// RHS neither 'true' nor 'false' - bail out.
|
||||||
return Changed;
|
continue;
|
||||||
// Whether RHS equals 'true'. Otherwise it equals 'false'.
|
// Whether RHS equals 'true'. Otherwise it equals 'false'.
|
||||||
bool isKnownTrue = CI->isAllOnesValue();
|
bool isKnownTrue = CI->isAllOnesValue();
|
||||||
bool isKnownFalse = !isKnownTrue;
|
bool isKnownFalse = !isKnownTrue;
|
||||||
|
@ -2039,9 +2045,9 @@ bool GVN::propagateEquality(Value *LHS, Value *RHS, BasicBlock *Root) {
|
||||||
Value *A, *B;
|
Value *A, *B;
|
||||||
if ((isKnownTrue && match(LHS, m_And(m_Value(A), m_Value(B)))) ||
|
if ((isKnownTrue && match(LHS, m_And(m_Value(A), m_Value(B)))) ||
|
||||||
(isKnownFalse && match(LHS, m_Or(m_Value(A), m_Value(B))))) {
|
(isKnownFalse && match(LHS, m_Or(m_Value(A), m_Value(B))))) {
|
||||||
Changed |= propagateEquality(A, RHS, Root);
|
Worklist.push_back(std::make_pair(A, RHS));
|
||||||
Changed |= propagateEquality(B, RHS, Root);
|
Worklist.push_back(std::make_pair(B, RHS));
|
||||||
return Changed;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we are propagating an equality like "(A == B)" == "true" then also
|
// 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.
|
// A with B everywhere in the scope.
|
||||||
if ((isKnownTrue && Cmp->getPredicate() == CmpInst::ICMP_EQ) ||
|
if ((isKnownTrue && Cmp->getPredicate() == CmpInst::ICMP_EQ) ||
|
||||||
(isKnownFalse && Cmp->getPredicate() == CmpInst::ICMP_NE))
|
(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.
|
// If "A >= B" is known true, replace "A < B" with false everywhere.
|
||||||
CmpInst::Predicate NotPred = Cmp->getInversePredicate();
|
CmpInst::Predicate NotPred = Cmp->getInversePredicate();
|
||||||
|
@ -2079,7 +2085,8 @@ bool GVN::propagateEquality(Value *LHS, Value *RHS, BasicBlock *Root) {
|
||||||
// is replaced with false.
|
// is replaced with false.
|
||||||
addToLeaderTable(Num, NotVal, Root);
|
addToLeaderTable(Num, NotVal, Root);
|
||||||
|
|
||||||
return Changed;
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Changed;
|
return Changed;
|
||||||
|
|
Loading…
Reference in New Issue