[llvm] [CodeGen] Don't merge stack slots accessed with volatile after setjmp (returns twice) calls (PR #181370)
Evgenii Kudriashov via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 20 04:15:07 PST 2026
================
@@ -708,6 +760,29 @@ unsigned StackColoring::collectMarkers(unsigned NumSlot) {
ConservativeSlots.set(slot);
}
+ // Detect volatile accesses to stack slots in successors of setjmp blocks.
+ // Such slots cannot be merged because they must survive potential longjmp.
+ if (MF->exposesReturnsTwice()) {
+ df_iterator_default_set<const MachineBasicBlock *> Visited;
+
+ for (auto *SetJmpBlok : SetjmpBlocks) {
+ for (auto *MBB : depth_first_ext(SetJmpBlok, Visited)) {
+ for (const MachineInstr &MI : *MBB) {
+ if (MI.isDebugInstr())
+ continue;
+
+ for (auto *MO : MI.memoperands()) {
+ if (!MO->isVolatile())
+ continue;
+ VolatileAfterSetjmp.set(NameToSlot.at(MO->getValue()->getName()));
+ }
----------------
e-kud wrote:
```suggestion
for (auto *MO : MI.memoperands())
if (MO->isVolatile())
VolatileAfterSetjmp.set(NameToSlot.at(MO->getValue()->getName()));
```
Nit, it could save some lines until bodies are one liners.
https://github.com/llvm/llvm-project/pull/181370
More information about the llvm-commits
mailing list