[llvm-branch-commits] [llvm] f744390 - [Statepoint] Handle `undef` operands in statepoint.
Denis Antrushin via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Jan 18 04:26:53 PST 2021
Author: Denis Antrushin
Date: 2021-01-18T15:20:54+03:00
New Revision: f7443905af1e06eaacda1e437fff8d54dc89c487
URL: https://github.com/llvm/llvm-project/commit/f7443905af1e06eaacda1e437fff8d54dc89c487
DIFF: https://github.com/llvm/llvm-project/commit/f7443905af1e06eaacda1e437fff8d54dc89c487.diff
LOG: [Statepoint] Handle `undef` operands in statepoint.
Currently when spilling statepoint register operands in FixupStatepoints
we do not pay attention that it might be `undef`. We just generate a
spill, which may lead to verifier error because we have a use without def.
To handle it, let FixupStateponts ignore `undef` register operands
completely and change them to some constant value when generating
stack map. Use same value as used by ISel for this purpose (0xFEFEFEFE).
Reviewed By: reames
Differential Revision: https://reviews.llvm.org/D94703
Added:
llvm/test/CodeGen/X86/statepoint-fixup-undef.mir
Modified:
llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp
llvm/lib/CodeGen/StackMaps.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp b/llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp
index 662bd1a3646f..f8f99b7e87f2 100644
--- a/llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp
+++ b/llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp
@@ -380,7 +380,9 @@ class StatepointState {
EndIdx = MI.getNumOperands();
Idx < EndIdx; ++Idx) {
MachineOperand &MO = MI.getOperand(Idx);
- if (!MO.isReg() || MO.isImplicit())
+ // Leave `undef` operands as is, StackMaps will rewrite them
+ // into a constant.
+ if (!MO.isReg() || MO.isImplicit() || MO.isUndef())
continue;
Register Reg = MO.getReg();
assert(Reg.isPhysical() && "Only physical regs are expected");
diff --git a/llvm/lib/CodeGen/StackMaps.cpp b/llvm/lib/CodeGen/StackMaps.cpp
index 220e85fe90dc..faf07e90c39c 100644
--- a/llvm/lib/CodeGen/StackMaps.cpp
+++ b/llvm/lib/CodeGen/StackMaps.cpp
@@ -234,6 +234,12 @@ StackMaps::parseOperand(MachineInstr::const_mop_iterator MOI,
if (MOI->isImplicit())
return ++MOI;
+ if (MOI->isUndef()) {
+ // Record `undef` register as constant. Use same value as ISel uses.
+ Locs.emplace_back(Location::Constant, sizeof(int64_t), 0, 0xFEFEFEFE);
+ return ++MOI;
+ }
+
assert(Register::isPhysicalRegister(MOI->getReg()) &&
"Virtreg operands should have been rewritten before now.");
const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(MOI->getReg());
diff --git a/llvm/test/CodeGen/X86/statepoint-fixup-undef.mir b/llvm/test/CodeGen/X86/statepoint-fixup-undef.mir
new file mode 100644
index 000000000000..434c8400316d
--- /dev/null
+++ b/llvm/test/CodeGen/X86/statepoint-fixup-undef.mir
@@ -0,0 +1,234 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+# RUN: llc -x mir -run-pass fixup-statepoint-caller-saved -verify-machineinstrs < %s | FileCheck %s
+# RUN: llc -x mir -start-before fixup-statepoint-caller-saved -verify-machineinstrs < %s | FileCheck %s -check-prefix=STACKMAP
+
+--- |
+ ; ModuleID = 'undef.ll'
+ source_filename = "test_undef.ll"
+ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+ target triple = "x86_64-unknown-linux-gnu"
+
+ define void @test_undef(i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2, i8 addrspace(1)* %arg3, i8 addrspace(1)* %arg4) #0 gc "statepoint-example" {
+ bb:
+ %tmp1 = lshr i32 0, undef
+ %tmp2 = load atomic i32, i32 addrspace(1)* undef unordered, align 8
+ %tmp3 = load atomic i32, i32 addrspace(1)* undef unordered, align 8
+ br label %bb7
+
+ bb7: ; preds = %bb
+ %tmp4 = icmp slt i32 %tmp3, undef
+ %tmp5 = select i1 %tmp4, i32 6, i32 undef
+ %tmp6 = add i32 %tmp5, %tmp2
+ %tmp7 = call i8 addrspace(1)* @wombat()
+ %tmp20 = call token (i64, i32, void (i8 addrspace(1)*, i32, i32, i8 addrspace(1)*, i32)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidp1i8i32i32p1i8i32f(i64 2, i32 5, void (i8 addrspace(1)*, i32, i32, i8 addrspace(1)*, i32)* nonnull @hoge, i32 5, i32 0, i8 addrspace(1)* %arg3, i32 %tmp2, i32 %tmp6, i8 addrspace(1)* %tmp7, i32 0, i32 0, i32 0) [ "deopt"(i8 addrspace(1)* %arg2, i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg3, i8 addrspace(1)* %arg4, i32 %tmp2, i32 %tmp1, i32 %tmp5), "gc-live"() ]
+ ret void
+ }
+
+ declare void @hoge(i8 addrspace(1)*, i32, i32, i8 addrspace(1)*, i32) #0
+
+ declare i8 addrspace(1)* @wombat() #0
+
+ ; Function Attrs: nounwind readonly
+ declare i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token, i32 immarg, i32 immarg) #1
+
+ declare token @llvm.experimental.gc.statepoint.p0f_isVoidp1i8i32i32p1i8i32f(i64 immarg, i32 immarg, void (i8 addrspace(1)*, i32, i32, i8 addrspace(1)*, i32)*, i32 immarg, i32 immarg, ...) #0
+
+ attributes #0 = { "target-cpu"="broadwell" }
+ attributes #1 = { nounwind readonly "target-cpu"="broadwell" }
+
+...
+---
+name: test_undef
+alignment: 16
+exposesReturnsTwice: false
+legalized: false
+regBankSelected: false
+selected: false
+failedISel: false
+tracksRegLiveness: true
+hasWinCFI: false
+registers: []
+liveins:
+ - { reg: '$rdi', virtual-reg: '' }
+ - { reg: '$rsi', virtual-reg: '' }
+ - { reg: '$rdx', virtual-reg: '' }
+ - { reg: '$rcx', virtual-reg: '' }
+frameInfo:
+ isFrameAddressTaken: false
+ isReturnAddressTaken: false
+ hasStackMap: false
+ hasPatchPoint: false
+ stackSize: 0
+ offsetAdjustment: 0
+ maxAlignment: 8
+ adjustsStack: false
+ hasCalls: true
+ stackProtector: ''
+ maxCallFrameSize: 4294967295
+ cvBytesOfCalleeSavedRegisters: 0
+ hasOpaqueSPAdjustment: false
+ hasVAStart: false
+ hasMustTailInVarArgFunc: false
+ localFrameSize: 0
+ savePoint: ''
+ restorePoint: ''
+fixedStack: []
+stack:
+ - { id: 0, name: '', type: default, offset: 0, size: 8, alignment: 8,
+ stack-id: default, callee-saved-register: '', callee-saved-restored: true,
+ debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
+ - { id: 1, name: '', type: default, offset: 0, size: 8, alignment: 8,
+ stack-id: default, callee-saved-register: '', callee-saved-restored: true,
+ debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
+ - { id: 2, name: '', type: default, offset: 0, size: 8, alignment: 8,
+ stack-id: default, callee-saved-register: '', callee-saved-restored: true,
+ debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
+ - { id: 3, name: '', type: default, offset: 0, size: 8, alignment: 8,
+ stack-id: default, callee-saved-register: '', callee-saved-restored: true,
+ debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
+callSites: []
+debugValueSubstitutions: []
+constants: []
+machineFunctionInfo: {}
+body: |
+ ; CHECK-LABEL: name: test_undef
+ ; CHECK: bb.0.bb:
+ ; CHECK: successors: %bb.1(0x80000000)
+ ; CHECK: liveins: $rcx, $rdi, $rdx, $rsi
+ ; CHECK: renamable $r15 = COPY $rcx
+ ; CHECK: renamable $r14 = COPY $rdx
+ ; CHECK: renamable $r13 = COPY $rsi
+ ; CHECK: renamable $r12 = COPY $rdi
+ ; CHECK: renamable $ebx = MOV32rm undef renamable $rax, 1, $noreg, 0, $noreg, implicit-def $rbx :: (load unordered 4 from `i32 addrspace(1)* undef`, align 8, addrspace 1)
+ ; CHECK: bb.1.bb7:
+ ; CHECK: liveins: $rbx, $r12, $r13, $r14, $r15
+ ; CHECK: renamable $ebp = LEA64_32r renamable $rbx, 1, $noreg, 6, $noreg
+ ; CHECK: ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
+ ; CHECK: CALL64pcrel32 target-flags(x86-plt) @wombat, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp, implicit-def $rax
+ ; CHECK: ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
+ ; CHECK: MOV64mr %stack.0, 1, $noreg, 0, $noreg, killed renamable $r13 :: (store 8 into %stack.0)
+ ; CHECK: MOV64mr %stack.1, 1, $noreg, 0, $noreg, killed renamable $r12 :: (store 8 into %stack.1)
+ ; CHECK: MOV64mr %stack.2, 1, $noreg, 0, $noreg, renamable $r14 :: (store 8 into %stack.2)
+ ; CHECK: MOV64mr %stack.3, 1, $noreg, 0, $noreg, killed renamable $r15 :: (store 8 into %stack.3)
+ ; CHECK: ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
+ ; CHECK: $rdi = COPY killed renamable $r14
+ ; CHECK: $esi = COPY renamable $ebx
+ ; CHECK: $edx = COPY killed renamable $ebp
+ ; CHECK: $rcx = COPY killed renamable $rax
+ ; CHECK: $r8d = MOV32r0 implicit-def dead $eflags
+ ; CHECK: STATEPOINT 2, 5, 5, undef renamable $rax, $rdi, $esi, $edx, $rcx, killed $r8d, 2, 0, 2, 0, 2, 7, 1, 8, %stack.0, 0, 1, 8, %stack.1, 0, 1, 8, %stack.2, 0, 1, 8, %stack.3, 0, renamable $ebx, undef renamable $eax, 2, 6, 2, 0, 2, 0, 2, 0, csr_64, implicit-def $rsp, implicit-def $ssp, implicit killed $rbx :: (volatile load store 8 on %stack.0), (volatile load store 8 on %stack.1), (volatile load store 8 on %stack.2), (volatile load store 8 on %stack.3)
+ ; CHECK: ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
+ ; CHECK: RET 0
+ ; STACKMAP-LABEL: __LLVM_StackMaps:
+ ; STACKMAP: .byte 3
+ ; STACKMAP: .byte 0
+ ; STACKMAP: .short 0
+ ; STACKMAP: .long 1
+ ; STACKMAP: .long 1
+ ; STACKMAP: .long 1
+ ; STACKMAP: .quad test_undef
+ ; STACKMAP: .quad 88
+ ; STACKMAP: .quad 1
+ ; STACKMAP: .quad 4278124286
+ ; STACKMAP: .quad 2
+ ; STACKMAP: .long .Ltmp0-test_undef
+ ; STACKMAP: .short 0
+ ; STACKMAP: .short 10
+ ; STACKMAP: .byte 4
+ ; STACKMAP: .byte 0
+ ; STACKMAP: .short 8
+ ; STACKMAP: .short 0
+ ; STACKMAP: .short 0
+ ; STACKMAP: .long 0
+ ; STACKMAP: .byte 4
+ ; STACKMAP: .byte 0
+ ; STACKMAP: .short 8
+ ; STACKMAP: .short 0
+ ; STACKMAP: .short 0
+ ; STACKMAP: .long 0
+ ; STACKMAP: .byte 4
+ ; STACKMAP: .byte 0
+ ; STACKMAP: .short 8
+ ; STACKMAP: .short 0
+ ; STACKMAP: .short 0
+ ; STACKMAP: .long 7
+ ; STACKMAP: .byte 3
+ ; STACKMAP: .byte 0
+ ; STACKMAP: .short 8
+ ; STACKMAP: .short 7
+ ; STACKMAP: .short 0
+ ; STACKMAP: .long 32
+ ; STACKMAP: .byte 3
+ ; STACKMAP: .byte 0
+ ; STACKMAP: .short 8
+ ; STACKMAP: .short 7
+ ; STACKMAP: .short 0
+ ; STACKMAP: .long 24
+ ; STACKMAP: .byte 3
+ ; STACKMAP: .byte 0
+ ; STACKMAP: .short 8
+ ; STACKMAP: .short 7
+ ; STACKMAP: .short 0
+ ; STACKMAP: .long 16
+ ; STACKMAP: .byte 3
+ ; STACKMAP: .byte 0
+ ; STACKMAP: .short 8
+ ; STACKMAP: .short 7
+ ; STACKMAP: .short 0
+ ; STACKMAP: .long 8
+ ; STACKMAP: .byte 1
+ ; STACKMAP: .byte 0
+ ; STACKMAP: .short 4
+ ; STACKMAP: .short 3
+ ; STACKMAP: .short 0
+ ; STACKMAP: .long 0
+ ; This is entry we're looking for, reference to constant pool entry 0xFEFEFEFE
+ ; STACKMAP: .byte 5
+ ; STACKMAP: .byte 0
+ ; STACKMAP: .short 8
+ ; STACKMAP: .short 0
+ ; STACKMAP: .short 0
+ ; STACKMAP: .long 0
+ ; STACKMAP: .byte 4
+ ; STACKMAP: .byte 0
+ ; STACKMAP: .short 8
+ ; STACKMAP: .short 0
+ ; STACKMAP: .short 0
+ ; STACKMAP: .long 6
+ ; STACKMAP: .p2align 3
+ ; STACKMAP: .short 0
+ ; STACKMAP: .short 0
+ ; STACKMAP: .p2align 3
+ bb.0.bb:
+ successors: %bb.1(0x80000000)
+ liveins: $rcx, $rdi, $rdx, $rsi
+
+ renamable $r15 = COPY $rcx
+ renamable $r14 = COPY $rdx
+ renamable $r13 = COPY $rsi
+ renamable $r12 = COPY $rdi
+ renamable $ebx = MOV32rm undef renamable $rax, 1, $noreg, 0, $noreg, implicit-def $rbx :: (load unordered 4 from `i32 addrspace(1)* undef`, align 8, addrspace 1)
+
+ bb.1.bb7:
+ liveins: $rbx, $r12, $r13, $r14, $r15
+
+ renamable $ebp = LEA64_32r renamable $rbx, 1, $noreg, 6, $noreg
+ ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
+ CALL64pcrel32 target-flags(x86-plt) @wombat, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp, implicit-def $rax
+ ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
+ MOV64mr %stack.0, 1, $noreg, 0, $noreg, killed renamable $r13 :: (store 8 into %stack.0)
+ MOV64mr %stack.1, 1, $noreg, 0, $noreg, killed renamable $r12 :: (store 8 into %stack.1)
+ MOV64mr %stack.2, 1, $noreg, 0, $noreg, renamable $r14 :: (store 8 into %stack.2)
+ MOV64mr %stack.3, 1, $noreg, 0, $noreg, killed renamable $r15 :: (store 8 into %stack.3)
+ ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
+ $rdi = COPY killed renamable $r14
+ $esi = COPY renamable $ebx
+ $edx = COPY killed renamable $ebp
+ $rcx = COPY killed renamable $rax
+ $r8d = MOV32r0 implicit-def dead $eflags
+ STATEPOINT 2, 5, 5, undef renamable $rax, $rdi, $esi, $edx, $rcx, killed $r8d, 2, 0, 2, 0, 2, 7, 1, 8, %stack.0, 0, 1, 8, %stack.1, 0, 1, 8, %stack.2, 0, 1, 8, %stack.3, 0, renamable $ebx, undef renamable $eax, 2, 6, 2, 0, 2, 0, 2, 0, csr_64, implicit-def $rsp, implicit-def $ssp, implicit killed $rbx :: (volatile load store 8 on %stack.0), (volatile load store 8 on %stack.1), (volatile load store 8 on %stack.2), (volatile load store 8 on %stack.3)
+ ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
+ RET 0
+
+...
+
More information about the llvm-branch-commits
mailing list