[llvm] [GenericDomTreeConstruction] Store the semidominator value in Label (PR #207603)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 5 11:15:22 PDT 2026
https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/207603
runSemiNCA's eval() stores the vertex with the minimal semidominator in
Label and dereferences NumToInfo[Label]->Semi to compare it. Store the
semidominator (Semi) value directly in Label instead, so eval compares
by number with no NumToInfo lookup.
>From 78a90e3bc82e11342763b73312c7960d0318d480 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Sun, 5 Jul 2026 10:50:53 -0700
Subject: [PATCH] [GenericDomTreeConstruction] Store the semidominator value in
Label
runSemiNCA's eval() stores the vertex with the minimal semidominator in
Label and dereferences NumToInfo[Label]->Semi to compare it. Store the
semidominator (Semi) value directly in Label instead, so eval compares
by number with no NumToInfo lookup.
---
.../llvm/Support/GenericDomTreeConstruction.h | 22 ++++++++++---------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/llvm/include/llvm/Support/GenericDomTreeConstruction.h b/llvm/include/llvm/Support/GenericDomTreeConstruction.h
index 3ed2879002c47..9ac5c5444c88a 100644
--- a/llvm/include/llvm/Support/GenericDomTreeConstruction.h
+++ b/llvm/include/llvm/Support/GenericDomTreeConstruction.h
@@ -270,8 +270,9 @@ template <typename DomTreeT> struct SemiNCAInfo {
// O(m*alpha(m,n)) running time. But it requires two auxiliary arrays (Size
// and Child) and is unlikely to be faster than the simple implementation.
//
- // For each vertex V, its Label points to the vertex with the minimal sdom(U)
- // (Semi) in its path from V (included) to NodeToInfo[V].Parent (excluded).
+ // For each vertex V, its Label is the minimal sdom (Semi) on its path from V
+ // (included) to NodeToInfo[V].Parent (excluded), held directly as a Semi
+ // value.
unsigned eval(unsigned V, unsigned LastLinked,
SmallVectorImpl<InfoRec *> &Stack,
ArrayRef<InfoRec *> NumToInfo) {
@@ -287,17 +288,17 @@ template <typename DomTreeT> struct SemiNCAInfo {
} while (VInfo->Parent >= LastLinked);
// Path compression. Point each vertex's Parent to the root and update its
- // Label if any of its ancestors (PInfo->Label) has a smaller Semi.
+ // Label if any of its ancestors (PLabel) has a smaller Semi.
const InfoRec *PInfo = VInfo;
- const InfoRec *PLabelInfo = NumToInfo[PInfo->Label];
+ unsigned PLabel = PInfo->Label;
do {
VInfo = Stack.pop_back_val();
VInfo->Parent = PInfo->Parent;
- const InfoRec *VLabelInfo = NumToInfo[VInfo->Label];
- if (PLabelInfo->Semi < VLabelInfo->Semi)
- VInfo->Label = PInfo->Label;
+ unsigned VLabel = VInfo->Label;
+ if (PLabel < VLabel)
+ VInfo->Label = PLabel;
else
- PLabelInfo = VLabelInfo;
+ PLabel = VLabel;
PInfo = VInfo;
} while (!Stack.empty());
return VInfo->Label;
@@ -329,11 +330,12 @@ template <typename DomTreeT> struct SemiNCAInfo {
for (unsigned RCIdx = WInfo.ReverseChildrenStart; RCIdx != 0;) {
const auto &Entry = ReverseChildren[RCIdx - 1];
RCIdx = Entry.second;
- unsigned SemiU =
- NumToInfo[eval(Entry.first, i + 1, EvalStack, NumToInfo)]->Semi;
+ unsigned SemiU = eval(Entry.first, i + 1, EvalStack, NumToInfo);
if (SemiU < WInfo.Semi)
WInfo.Semi = SemiU;
}
+ // Label now holds the semidominator value for later eval() calls.
+ WInfo.Label = WInfo.Semi;
}
// Step #2: Explicitly define the immediate dominator of each vertex.
More information about the llvm-commits
mailing list