[PATCH] D144907: [RegAllocFast] insert additional spills along indirect edges of INLINEASM_BR
Nick Desaulniers via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 27 12:37:26 PST 2023
nickdesaulniers created this revision.
Herald added subscribers: pengfei, hiraditya, qcolombet, MatzeB.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
When generating spills (stores) for values produced by INLINEASM_BR
instructions, make sure to insert one spill per indirect target.
Otherwise the reload generated may load from a stack slot that has not
yet been stored to (resulting in a load of an uninitialized stack slot).
Link: https://github.com/llvm/llvm-project/issues/53562
Fixes: https://github.com/llvm/llvm-project/issues/60855
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D144907
Files:
llvm/lib/CodeGen/RegAllocFast.cpp
llvm/test/CodeGen/X86/callbr-asm-outputs-regallocfast.mir
Index: llvm/test/CodeGen/X86/callbr-asm-outputs-regallocfast.mir
===================================================================
--- llvm/test/CodeGen/X86/callbr-asm-outputs-regallocfast.mir
+++ llvm/test/CodeGen/X86/callbr-asm-outputs-regallocfast.mir
@@ -136,6 +136,7 @@
; CHECK-NEXT: bb.3.label.split (machine-block-address-taken, inlineasm-br-indirect-target):
; CHECK-NEXT: successors: %bb.2(0x80000000)
; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: MOV32mr %stack.3, 1, $noreg, 0, $noreg, $eax :: (store (s32) into %stack.3)
; CHECK-NEXT: $eax = MOV32rm %stack.3, 1, $noreg, 0, $noreg :: (load (s32) from %stack.3)
; CHECK-NEXT: MOV32mr %stack.1.x, 1, $noreg, 0, $noreg, killed renamable $eax :: (store (s32) into %ir.x)
; CHECK-NEXT: JMP_1 %bb.2
Index: llvm/lib/CodeGen/RegAllocFast.cpp
===================================================================
--- llvm/lib/CodeGen/RegAllocFast.cpp
+++ llvm/lib/CodeGen/RegAllocFast.cpp
@@ -948,6 +948,19 @@
<< LRI->Reloaded << '\n');
bool Kill = LRI->LastUse == nullptr;
spill(SpillBefore, VirtReg, PhysReg, Kill, LRI->LiveOut);
+
+ if (MI.getOpcode() == TargetOpcode::INLINEASM_BR) {
+ int FI = StackSlotForVirtReg[VirtReg];
+ const TargetRegisterClass &RC = *MRI->getRegClass(VirtReg);
+ for (MachineBasicBlock *Succ : MI.getParent()->successors()) {
+ if (Succ->isInlineAsmBrIndirectTarget()) {
+ TII->storeRegToStackSlot(*Succ, Succ->begin(), PhysReg, Kill,
+ FI, &RC, TRI, VirtReg);
+ ++NumStores;
+ }
+ }
+ }
+
LRI->LastUse = nullptr;
}
LRI->LiveOut = false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144907.500880.patch
Type: text/x-patch
Size: 1691 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230227/9b336534/attachment.bin>
More information about the llvm-commits
mailing list