[llvm] [GVN] Share equality propagation for assume and condition (PR #161639)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 2 05:54:06 PDT 2025
================
@@ -2652,26 +2558,45 @@ bool GVNPass::propagateEquality(Value *LHS, Value *RHS,
// If the number we were assigned was brand new then there is no point in
// looking for an instruction realizing it: there cannot be one!
if (Num < NextNum) {
- Value *NotCmp = findLeader(Root.getEnd(), Num);
- if (NotCmp && isa<Instruction>(NotCmp)) {
- unsigned NumReplacements =
- DominatesByEdge
- ? replaceDominatedUsesWith(NotCmp, NotVal, *DT, Root)
- : replaceDominatedUsesWith(NotCmp, NotVal, *DT,
- Root.getStart());
- Changed |= NumReplacements > 0;
- NumGVNEqProp += NumReplacements;
- // Cached information for anything that uses NotCmp will be invalid.
- if (MD)
- MD->invalidateCachedPointerInfo(NotCmp);
+ for (const auto &Entry : LeaderTable.getLeaders(Num)) {
----------------
nikic wrote:
To explain what is going on here: I initially changed this to look for leaders in DominatedBlocks instead, but that caused regressions for the case where the edge is non-dominating, but there is a phi use of the inverted condition.
So instead I explicitly loop over the leaders and inspect the ones that could potentially have replaceable uses. Worth noting that what findLeader() does internally is also loop over the leaders and perform a dominance check, we just need more flexibility here for the dominance condition to use.
This change is what accounts for the improvements in llvm-opt-benchmark.
https://github.com/llvm/llvm-project/pull/161639
More information about the llvm-commits
mailing list