diff options
author | Michael Maitland <michaeltmaitland@gmail.com> | 2025-02-04 10:04:19 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-04 10:04:19 -0500 |
commit | 93b90a532d0ca5a95c226e3d0b37444ef692d3da (patch) | |
tree | 4f2e3a09cd1c806fc22bc3477887f1a8840366d3 /llvm/lib/CodeGen/ReachingDefAnalysis.cpp | |
parent | e73a64bbd1733347a2c30e8fb93079b4aa41187a (diff) | |
download | llvm-93b90a532d0ca5a95c226e3d0b37444ef692d3da.zip llvm-93b90a532d0ca5a95c226e3d0b37444ef692d3da.tar.gz llvm-93b90a532d0ca5a95c226e3d0b37444ef692d3da.tar.bz2 |
[ReachingDefAnalysis] Fix management of MBBFrameObjsReachingDefs (#124943)
MBBFrameObjsReachingDefs was not being built correctly since we were not
inserting into a reference of Frame2InstrIdx. If there was multiple
stack slot defs in the same basic block, then the bug would occur. This
PR fixes this problem while simplifying the insertion logic.
Additionally, when lookup into MBBFrameObjsReachingDefs was occurring,
there was a chance that there was no entry in the map, in the case that
there was no reaching def. This was causing us to return a default
value, which may or may not have been correct. This patch returns the
correct value now.
Diffstat (limited to 'llvm/lib/CodeGen/ReachingDefAnalysis.cpp')
-rw-r--r-- | llvm/lib/CodeGen/ReachingDefAnalysis.cpp | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/llvm/lib/CodeGen/ReachingDefAnalysis.cpp b/llvm/lib/CodeGen/ReachingDefAnalysis.cpp index fa60881..59ad9ff 100644 --- a/llvm/lib/CodeGen/ReachingDefAnalysis.cpp +++ b/llvm/lib/CodeGen/ReachingDefAnalysis.cpp @@ -147,16 +147,7 @@ void ReachingDefAnalysis::processDefs(MachineInstr *MI) { assert(FrameIndex >= 0 && "Can't handle negative frame indicies yet!"); if (!isFIDef(*MI, FrameIndex, TII)) continue; - if (MBBFrameObjsReachingDefs.contains(MBBNumber)) { - auto Frame2InstrIdx = MBBFrameObjsReachingDefs[MBBNumber]; - if (Frame2InstrIdx.count(FrameIndex - ObjectIndexBegin) > 0) - Frame2InstrIdx[FrameIndex - ObjectIndexBegin].push_back(CurInstr); - else - Frame2InstrIdx[FrameIndex - ObjectIndexBegin] = {CurInstr}; - } else { - MBBFrameObjsReachingDefs[MBBNumber] = { - {FrameIndex - ObjectIndexBegin, {CurInstr}}}; - } + MBBFrameObjsReachingDefs[{MBBNumber, FrameIndex}].push_back(CurInstr); } if (!isValidRegDef(MO)) continue; @@ -351,9 +342,13 @@ int ReachingDefAnalysis::getReachingDef(MachineInstr *MI, Register Reg) const { int LatestDef = ReachingDefDefaultVal; if (Reg.isStack()) { + // Check that there was a reaching def. int FrameIndex = Reg.stackSlotIndex(); - for (int Def : MBBFrameObjsReachingDefs.lookup(MBBNumber).lookup( - FrameIndex - ObjectIndexBegin)) { + auto Lookup = MBBFrameObjsReachingDefs.find({MBBNumber, FrameIndex}); + if (Lookup == MBBFrameObjsReachingDefs.end()) + return LatestDef; + auto &Defs = Lookup->second; + for (int Def : Defs) { if (Def >= InstId) break; DefRes = Def; |