[LoopPredication][NFCI] Perform 'visited' check before pushing to worklist

This prevents duplicates to be pushed into the stack and hypothetically
should reduce memory footprint on ugly cornercases with multiple repeating
duplicates in 'and' tree.
This commit is contained in:
Max Kazantsev 2022-11-02 18:02:59 +07:00
parent a68bcd81dc
commit 2baabd2c19

View File

@ -763,17 +763,17 @@ unsigned LoopPredication::collectChecks(SmallVectorImpl<Value *> &Checks,
// resulting list of subconditions in Checks vector.
SmallVector<Value *, 4> Worklist(1, Condition);
SmallPtrSet<Value *, 4> Visited;
Visited.insert(Condition);
Value *WideableCond = nullptr;
do {
Value *Condition = Worklist.pop_back_val();
if (!Visited.insert(Condition).second)
continue;
Value *LHS, *RHS;
using namespace llvm::PatternMatch;
if (match(Condition, m_And(m_Value(LHS), m_Value(RHS)))) {
Worklist.push_back(LHS);
Worklist.push_back(RHS);
if (Visited.insert(LHS).second)
Worklist.push_back(LHS);
if (Visited.insert(RHS).second)
Worklist.push_back(RHS);
continue;
}