Skip to content

Commit 9af0962

Browse files
committed
[Statepoint] Treat undef operands less specially
This reverts commit f744390. This is to avoid an assertion if an undef operand appears in a stackmap. This is important to avoid hitting verifier errors when register allocation starts adding undefs in error scenarios. Rather than trying to treat undef operands as special, leave them alone and avoid producing an invalid spill. It would a bit more precise to produce a spill of an undef register here, but that's not exposed through the storeRegToStackSlot API. https://reviews.llvm.org/D122605 This was an alternative to https://reviews.llvm.org/D122582
1 parent b1776bc commit 9af0962

File tree

4 files changed

+81
-12
lines changed

4 files changed

+81
-12
lines changed

llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,6 @@ class StatepointState {
381381
EndIdx = MI.getNumOperands();
382382
Idx < EndIdx; ++Idx) {
383383
MachineOperand &MO = MI.getOperand(Idx);
384-
// Leave `undef` operands as is, StackMaps will rewrite them
385-
// into a constant.
386384
if (!MO.isReg() || MO.isImplicit() || MO.isUndef())
387385
continue;
388386
Register Reg = MO.getReg();

llvm/lib/CodeGen/StackMaps.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,6 @@ StackMaps::parseOperand(MachineInstr::const_mop_iterator MOI,
268268
if (MOI->isImplicit())
269269
return ++MOI;
270270

271-
if (MOI->isUndef()) {
272-
// Record `undef` register as constant. Use same value as ISel uses.
273-
Locs.emplace_back(Location::Constant, sizeof(int64_t), 0, 0xFEFEFEFE);
274-
return ++MOI;
275-
}
276-
277271
assert(MOI->getReg().isPhysical() &&
278272
"Virtreg operands should have been rewritten before now.");
279273
const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(MOI->getReg());
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# RUN: llc -mtriple=x86_64-apple-darwin -start-after=virtregrewriter -o - %s | FileCheck %s
2+
3+
# Check there's no assertion for anyregcc with an undef operand to a stackmap.
4+
5+
# CHECK: __LLVM_StackMaps:
6+
# CHECK-NEXT: .byte 3
7+
# CHECK-NEXT: .byte 0
8+
# CHECK-NEXT: .short 0
9+
# CHECK-NEXT: .long 1
10+
# CHECK-NEXT: .long 0
11+
# CHECK-NEXT: .long 1
12+
# CHECK-NEXT: .quad _undef_anyregcc_patchpoint
13+
# CHECK-NEXT: .quad 8
14+
# CHECK-NEXT: .quad 1
15+
# CHECK-NEXT: .quad 12
16+
# CHECK-NEXT: .long Ltmp0-_undef_anyregcc_patchpoint
17+
# CHECK-NEXT: .short 0
18+
# CHECK-NEXT: .short 2
19+
# CHECK-NEXT: .byte 1
20+
# CHECK-NEXT: .byte 0
21+
# CHECK-NEXT: .short 8
22+
# CHECK-NEXT: .short 0
23+
# CHECK-NEXT: .short 0
24+
# CHECK-NEXT: .long 0
25+
# CHECK-NEXT: .byte 1
26+
# CHECK-NEXT: .byte 0
27+
# CHECK-NEXT: .short 8
28+
# CHECK-NEXT: .short 0
29+
# CHECK-NEXT: .short 0
30+
# CHECK-NEXT: .long 0
31+
# CHECK-NEXT: .p2align 3, 0x0
32+
# CHECK-NEXT: .short 0
33+
# CHECK-NEXT: .short 7
34+
# CHECK-NEXT: .short 0
35+
# CHECK-NEXT: .byte 0
36+
# CHECK-NEXT: .byte 8
37+
# CHECK-NEXT: .short 3
38+
# CHECK-NEXT: .byte 0
39+
# CHECK-NEXT: .byte 8
40+
# CHECK-NEXT: .short 7
41+
# CHECK-NEXT: .byte 0
42+
# CHECK-NEXT: .byte 8
43+
# CHECK-NEXT: .short 12
44+
# CHECK-NEXT: .byte 0
45+
# CHECK-NEXT: .byte 8
46+
# CHECK-NEXT: .short 13
47+
# CHECK-NEXT: .byte 0
48+
# CHECK-NEXT: .byte 8
49+
# CHECK-NEXT: .short 14
50+
# CHECK-NEXT: .byte 0
51+
# CHECK-NEXT: .byte 8
52+
# CHECK-NEXT: .short 15
53+
# CHECK-NEXT: .byte 0
54+
# CHECK-NEXT: .byte 8
55+
# CHECK-NEXT: .p2align 3
56+
---
57+
name: undef_anyregcc_patchpoint
58+
tracksRegLiveness: true
59+
frameInfo:
60+
hasPatchPoint: true
61+
hasCalls: true
62+
adjustsStack: true
63+
fixedStack:
64+
- { id: 0, type: default, offset: 72, size: 8, alignment: 8, stack-id: default,
65+
isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
66+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
67+
body: |
68+
bb.0:
69+
liveins: $rcx, $rdi, $rdx, $rsi, $r8, $r9
70+
71+
ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
72+
dead renamable $rax = MOV64rm %fixed-stack.0, 1, $noreg, 0, $noreg :: (load (s64) from %fixed-stack.0)
73+
renamable $rax = PATCHPOINT 12, 15, 0, 1, 13, undef renamable $rax, csr_64_allregs, implicit-def dead early-clobber $r11, implicit-def $rsp, implicit-def $ssp
74+
ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
75+
RET 0, $rax
76+
77+
...

llvm/test/CodeGen/X86/statepoint-fixup-undef.mir

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,13 @@ body: |
181181
; STACKMAP-NEXT: .short 3
182182
; STACKMAP-NEXT: .short 0
183183
; STACKMAP-NEXT: .long 0
184-
; This is a constant 0xFEFEFEFE we are looking for
185-
; STACKMAP-NEXT: .byte 4
184+
; This is entry we're looking for
185+
; STACKMAP-NEXT: .byte 1
186186
; STACKMAP-NEXT: .byte 0
187-
; STACKMAP-NEXT: .short 8
187+
; STACKMAP-NEXT: .short 4
188188
; STACKMAP-NEXT: .short 0
189189
; STACKMAP-NEXT: .short 0
190-
; STACKMAP-NEXT: .long -16843010
190+
; STACKMAP-NEXT: .long 0
191191
; STACKMAP-NEXT: .byte 4
192192
; STACKMAP-NEXT: .byte 0
193193
; STACKMAP-NEXT: .short 8

0 commit comments

Comments
 (0)