[llvm] [GVN] Combine visited and worklist in PropagateEquality (PR #216061)
Sven van Haastregt via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 13 07:23:08 PDT 2026
https://github.com/svenvh created https://github.com/llvm/llvm-project/pull/216061
Followup of 0a321f38147f ("[GVN] Track visited nodes in equality propagation to avoid OOM (#212265)", 2026-08-05) to mitigate the compilation time impact of the fix a little further.
>From ff136c4541d27208c25c4f7e6c041dba2aef9172 Mon Sep 17 00:00:00 2001
From: Katy Thackray <katy.thackray2 at arm.com>
Date: Tue, 11 Aug 2026 12:08:08 +0100
Subject: [PATCH] [GVN] Combine visited and worklist in PropagateEquality
Followup of 0a321f38147f ("[GVN] Track visited nodes in equality
propagation to avoid OOM (#212265)", 2026-08-05) to mitigate the
compilation time impact of the fix a little further.
---
llvm/lib/Transforms/Scalar/GVN.cpp | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index 64fd14fcba1c5..bedfda310f4b1 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -3091,9 +3091,8 @@ void GVNPass::assignBlockRPONumber(Function &F) {
bool GVNPass::propagateEquality(
Value *LHS, Value *RHS,
const std::variant<BasicBlockEdge, Instruction *> &Root) {
- SmallVector<std::pair<Value*, Value*>, 4> Worklist;
- SmallDenseSet<std::pair<Value *, Value *>, 4> Visited;
- Worklist.push_back(std::make_pair(LHS, RHS));
+ SmallSetVector<std::pair<Value *, Value *>, 4> Worklist;
+ Worklist.insert({LHS, RHS});
bool Changed = false;
SmallVector<const BasicBlock *> DominatedBlocks;
if (const BasicBlockEdge *Edge = std::get_if<BasicBlockEdge>(&Root)) {
@@ -3107,8 +3106,9 @@ bool GVNPass::propagateEquality(
DominatedBlocks.push_back(Node->getBlock());
}
- while (!Worklist.empty()) {
- std::pair<Value*, Value*> Item = Worklist.pop_back_val();
+ unsigned WorklistIdx = 0;
+ while (WorklistIdx != Worklist.size()) {
+ std::pair<Value *, Value *> Item = Worklist[WorklistIdx++];
LHS = Item.first; RHS = Item.second;
if (LHS == RHS)
@@ -3144,9 +3144,6 @@ bool GVNPass::propagateEquality(
}
}
- if (!Visited.insert({LHS, RHS}).second)
- continue;
-
// If value numbering later sees that an instruction in the scope is equal
// to 'LHS' then ensure it will be turned into 'RHS'. In order to preserve
// the invariant that instructions only occur in the leader table for their
@@ -3206,8 +3203,8 @@ bool GVNPass::propagateEquality(
Value *A, *B;
if ((IsKnownTrue && match(LHS, m_LogicalAnd(m_Value(A), m_Value(B)))) ||
(IsKnownFalse && match(LHS, m_LogicalOr(m_Value(A), m_Value(B))))) {
- Worklist.push_back(std::make_pair(A, RHS));
- Worklist.push_back(std::make_pair(B, RHS));
+ Worklist.insert({A, RHS});
+ Worklist.insert({B, RHS});
continue;
}
@@ -3221,7 +3218,7 @@ bool GVNPass::propagateEquality(
// A with B everywhere in the scope. For floating point operations, we
// have to be careful since equality does not always imply equivalance.
if (Cmp->isEquivalence(IsKnownFalse))
- Worklist.push_back(std::make_pair(Op0, Op1));
+ Worklist.insert({Op0, Op1});
// If "A >= B" is known true, replace "A < B" with false everywhere.
CmpInst::Predicate NotPred = Cmp->getInversePredicate();
@@ -3281,12 +3278,12 @@ bool GVNPass::propagateEquality(
// like (trunc nuw i64 %v to i1) == "true" or (trunc nuw i64 %v to i1) ==
// "false"
if (match(LHS, m_NUWTrunc(m_Value(A)))) {
- Worklist.emplace_back(A, ConstantInt::get(A->getType(), IsKnownTrue));
+ Worklist.insert({A, ConstantInt::get(A->getType(), IsKnownTrue)});
continue;
}
if (match(LHS, m_Not(m_Value(A)))) {
- Worklist.emplace_back(A, ConstantInt::get(A->getType(), !IsKnownTrue));
+ Worklist.insert({A, ConstantInt::get(A->getType(), !IsKnownTrue)});
continue;
}
}
More information about the llvm-commits
mailing list