From 2baabd2c19ee972926a96fa01838ccb7901cac32 Mon Sep 17 00:00:00 2001 From: Max Kazantsev Date: Wed, 2 Nov 2022 18:02:59 +0700 Subject: [PATCH] [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. --- llvm/lib/Transforms/Scalar/LoopPredication.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/LoopPredication.cpp b/llvm/lib/Transforms/Scalar/LoopPredication.cpp index fbd4a39..1e4060a 100644 --- a/llvm/lib/Transforms/Scalar/LoopPredication.cpp +++ b/llvm/lib/Transforms/Scalar/LoopPredication.cpp @@ -763,17 +763,17 @@ unsigned LoopPredication::collectChecks(SmallVectorImpl &Checks, // resulting list of subconditions in Checks vector. SmallVector Worklist(1, Condition); SmallPtrSet 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; } -- 2.7.4