[llvm] [DebugInfo][Mem2Reg] Assign uninitialized values with annotated locs (PR #157716)
Stephen Tozer via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 9 10:05:15 PDT 2025
https://github.com/SLTozer created https://github.com/llvm/llvm-project/pull/157716
In PromoteMem2Reg, we perform a DFS over the CFG and track, for each alloca, its incoming value and its associated incoming DebugLoc, both of which are taken from stores to that alloca; these values and DebugLocs are propagated to PHI nodes when new blocks are reached. In the event that for one incoming edge no store instruction has been seen, we propagate an UndefValue and an empty DebugLoc to the PHI.
This is a perfectly valid occurrence, and assigning an empty DebugLoc to the PHI is the correct course of action; therefore, we should pass an annotated DebugLoc instead, so that in DebugLoc coverage tracking we correctly do not expect a valid DebugLoc to be present; we generally mark allocas as having CompilerGenerated locations, so I've chosen to use the same annotation to represent the uninitialized value of that alloca.
This change is NFC outside of DebugLoc coverage tracking builds.
>From d032927228ae75a0ba25f8874970fe1abd6fd20b Mon Sep 17 00:00:00 2001
From: Stephen Tozer <stephen.tozer at sony.com>
Date: Tue, 9 Sep 2025 17:48:19 +0100
Subject: [PATCH] [DebugInfo][Mem2Reg] Assign uninitialized values with
annotated locs
In PromoteMem2Reg, we perform a DFS over the CFG and track, for each alloca,
its incoming value and its associated incoming DebugLoc, both of which are
taken from stores to that alloca; these values and DebugLocs are propagated
to PHI nodes when new blocks are reached. In the event that for one
incoming edge no store instruction has been seen, we propagate an UndefValue
and an empty DebugLoc to the PHI.
This is a perfectly valid occurrence, and assigning an empty DebugLoc to the
PHI is the correct course of action; therefore, we should pass an annotated
DebugLoc instead, so that in DebugLoc coverage tracking we correctly do not
expect a valid DebugLoc to be present; we generally mark allocas as having
CompilerGenerated locations, so I've chosen to use the same annotation to
represent the uninitialized value of that alloca.
This change is NFC outside of DebugLoc coverage tracking builds.
---
llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
index 10c162bc6463a..d93a4d87f30f4 100644
--- a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
+++ b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
@@ -849,9 +849,12 @@ void PromoteMem2Reg::run() {
for (unsigned i = 0, e = Allocas.size(); i != e; ++i)
IncomingVals.init(i, UndefValue::get(Allocas[i]->getAllocatedType()));
- // When handling debug info, treat all incoming values as if they have unknown
- // locations until proven otherwise.
+ // When handling debug info, treat all incoming values as if they have
+ // compiler-generated (empty) locations, representing the uninitialized
+ // alloca, until proven otherwise.
IncomingLocs.resize(Allocas.size());
+ for (unsigned i = 0, e = Allocas.size(); i != e; ++i)
+ IncomingLocs.init(i, DebugLoc::getCompilerGenerated());
// The renamer uses the Visited set to avoid infinite loops.
Visited.resize(F.getMaxBlockNumber(), false);
More information about the llvm-commits
mailing list