[llvm] [ReachingDefAnalysis][NFC] Fix management of MBBFrameObjsReachingDefs (PR #124943)
Michael Maitland via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 29 08:42:40 PST 2025
https://github.com/michaelmaitland created https://github.com/llvm/llvm-project/pull/124943
@mgudim, can you please take a closer look into what is going on here? This patch causes an assertion failure due to the usage of `at`. I think the problem is that the `MBBNumber` in `processDefs` is the one of the Def, but the `MBBNumber` in `getReachingDef` is the one of the use?
Also, we were missing a reference on `Frame2InstrIdx`, so I don't think we were adding to the data structure as expected.
>From 07f09a4c2c6226a5a6bdd00edede86d255d78fc5 Mon Sep 17 00:00:00 2001
From: Michael Maitland <michaeltmaitland at gmail.com>
Date: Wed, 29 Jan 2025 08:39:09 -0800
Subject: [PATCH] [ReachingDefAnalysis][NFC] Fix management of
MBBFrameObjsReachingDefs
---
llvm/lib/CodeGen/ReachingDefAnalysis.cpp | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/llvm/lib/CodeGen/ReachingDefAnalysis.cpp b/llvm/lib/CodeGen/ReachingDefAnalysis.cpp
index 3d88c6815d51c9..269c8b8dbf53b0 100644
--- a/llvm/lib/CodeGen/ReachingDefAnalysis.cpp
+++ b/llvm/lib/CodeGen/ReachingDefAnalysis.cpp
@@ -147,17 +147,19 @@ void ReachingDefAnalysis::processDefs(MachineInstr *MI) {
assert(FrameIndex >= 0 && "Can't handle negative frame indicies yet!");
if (!isFIDef(*MI, FrameIndex, TII))
continue;
+
+ int Key = FrameIndex - ObjectIndexBegin;
if (MBBFrameObjsReachingDefs.contains(MBBNumber)) {
- auto Frame2InstrIdx = MBBFrameObjsReachingDefs[MBBNumber];
- if (Frame2InstrIdx.count(FrameIndex - ObjectIndexBegin) > 0)
- Frame2InstrIdx[FrameIndex - ObjectIndexBegin].push_back(CurInstr);
+ auto &Frame2InstrIdx = MBBFrameObjsReachingDefs[MBBNumber];
+ if (Frame2InstrIdx.count(Key) > 0)
+ Frame2InstrIdx[Key].push_back(CurInstr);
else
- Frame2InstrIdx[FrameIndex - ObjectIndexBegin] = {CurInstr};
+ Frame2InstrIdx[Key] = {CurInstr};
} else {
- MBBFrameObjsReachingDefs[MBBNumber] = {
- {FrameIndex - ObjectIndexBegin, {CurInstr}}};
+ MBBFrameObjsReachingDefs[MBBNumber] = {{Key, {CurInstr}}};
}
}
+
if (!isValidRegDef(MO))
continue;
for (MCRegUnit Unit : TRI->regunits(MO.getReg().asMCReg())) {
@@ -348,8 +350,8 @@ int ReachingDefAnalysis::getReachingDef(MachineInstr *MI, Register Reg) const {
if (Register::isStackSlot(Reg)) {
int FrameIndex = Register::stackSlot2Index(Reg);
- for (int Def : MBBFrameObjsReachingDefs.lookup(MBBNumber).lookup(
- FrameIndex - ObjectIndexBegin)) {
+ int Key = FrameIndex - ObjectIndexBegin;
+ for (int Def : MBBFrameObjsReachingDefs.at(MBBNumber).at(Key)) {
if (Def >= InstId)
break;
DefRes = Def;
More information about the llvm-commits
mailing list