aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/ModuloSchedule.cpp
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2025-03-07 11:09:57 -0800
committerGitHub <noreply@github.com>2025-03-07 11:09:57 -0800
commit4bc3592bd2cb5fae6dfb5b3958727bae4115a800 (patch)
treecd5ec86cb577d838ca9d3b0ac133d821a3ad9dc6 /llvm/lib/CodeGen/ModuloSchedule.cpp
parent6a42dc694cffb4658ef72db308cfae7bfbba16b5 (diff)
downloadllvm-4bc3592bd2cb5fae6dfb5b3958727bae4115a800.zip
llvm-4bc3592bd2cb5fae6dfb5b3958727bae4115a800.tar.gz
llvm-4bc3592bd2cb5fae6dfb5b3958727bae4115a800.tar.bz2
[MachinePipeliner] Fix use-after-free coping values of the same DenseMap (#130311)
After #130165. In the code: `VRMap[CurStageNum][Def] = VRMap[CurStageNum][LoopVal]` `VRMap[CurStageNum][LoopVal]` calculates a reference before `VRMap[CurStageNum][Def]` which may rehash the DenseMap. Then the reference can be dead.
Diffstat (limited to 'llvm/lib/CodeGen/ModuloSchedule.cpp')
-rw-r--r--llvm/lib/CodeGen/ModuloSchedule.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/ModuloSchedule.cpp b/llvm/lib/CodeGen/ModuloSchedule.cpp
index c6d1a41..bff0b7a 100644
--- a/llvm/lib/CodeGen/ModuloSchedule.cpp
+++ b/llvm/lib/CodeGen/ModuloSchedule.cpp
@@ -410,8 +410,11 @@ void ModuloScheduleExpander::generateExistingPhis(
Register NewReg = VRMap[PrevStage][LoopVal];
rewriteScheduledInstr(NewBB, InstrMap, CurStageNum, 0, &*BBI, Def,
InitVal, NewReg);
- if (VRMap[CurStageNum].count(LoopVal))
- VRMap[CurStageNum][Def] = VRMap[CurStageNum][LoopVal];
+ auto It = VRMap[CurStageNum].find(LoopVal);
+ if (It != VRMap[CurStageNum].end()) {
+ Register Reg = It->second;
+ VRMap[CurStageNum][Def] = Reg;
+ }
}
// Adjust the number of Phis needed depending on the number of prologs left,
// and the distance from where the Phi is first scheduled. The number of