Skip to content

Commit 8638fe1

Browse files
authored
[X86] Fix livein handling in emitStackProbeInlineWindowsCoreCLR64. (#106828)
Stop adding liveins for virtual registers. In the livein interface, the register goes through a MCPhysReg which is uint16_t. This causes the virtual register bit to be dropped making it alias to some nonsense physical register. Recompute the liveins for the continue block to handle any live registers that are needed by instructions that were spliced from the original block. This fixing the machine verifier error so we can remove that fixme now.
1 parent 89fb849 commit 8638fe1

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

llvm/lib/Target/X86/X86FrameLowering.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,8 @@ void X86FrameLowering::emitStackProbeInlineWindowsCoreCLR64(
10371037
.addImm(X86::COND_AE);
10381038

10391039
// Add code to roundMBB to round the final stack pointer to a page boundary.
1040-
RoundMBB->addLiveIn(FinalReg);
1040+
if (InProlog)
1041+
RoundMBB->addLiveIn(FinalReg);
10411042
BuildMI(RoundMBB, DL, TII.get(X86::AND64ri32), RoundedReg)
10421043
.addReg(FinalReg)
10431044
.addImm(PageMask);
@@ -1054,7 +1055,8 @@ void X86FrameLowering::emitStackProbeInlineWindowsCoreCLR64(
10541055
.addMBB(LoopMBB);
10551056
}
10561057

1057-
LoopMBB->addLiveIn(JoinReg);
1058+
if (InProlog)
1059+
LoopMBB->addLiveIn(JoinReg);
10581060
addRegOffset(BuildMI(LoopMBB, DL, TII.get(X86::LEA64r), ProbeReg), JoinReg,
10591061
false, -PageSize);
10601062

@@ -1067,7 +1069,8 @@ void X86FrameLowering::emitStackProbeInlineWindowsCoreCLR64(
10671069
.addReg(0)
10681070
.addImm(0);
10691071

1070-
LoopMBB->addLiveIn(RoundedReg);
1072+
if (InProlog)
1073+
LoopMBB->addLiveIn(RoundedReg);
10711074
BuildMI(LoopMBB, DL, TII.get(X86::CMP64rr))
10721075
.addReg(RoundedReg)
10731076
.addReg(ProbeReg);
@@ -1091,7 +1094,6 @@ void X86FrameLowering::emitStackProbeInlineWindowsCoreCLR64(
10911094

10921095
// Now that the probing is done, add code to continueMBB to update
10931096
// the stack pointer for real.
1094-
ContinueMBB->addLiveIn(SizeReg);
10951097
BuildMI(*ContinueMBB, ContinueMBBI, DL, TII.get(X86::SUB64rr), X86::RSP)
10961098
.addReg(X86::RSP)
10971099
.addReg(SizeReg);
@@ -1103,6 +1105,11 @@ void X86FrameLowering::emitStackProbeInlineWindowsCoreCLR64(
11031105
LoopMBB->addSuccessor(ContinueMBB);
11041106
LoopMBB->addSuccessor(LoopMBB);
11051107

1108+
if (InProlog) {
1109+
LivePhysRegs LiveRegs;
1110+
computeAndAddLiveIns(LiveRegs, *ContinueMBB);
1111+
}
1112+
11061113
// Mark all the instructions added to the prolog as frame setup.
11071114
if (InProlog) {
11081115
for (++BeforeMBBI; BeforeMBBI != MBB.end(); ++BeforeMBBI) {

llvm/test/CodeGen/X86/win_coreclr_chkstk.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
; FIXME: Fix machine verifier issues and remove -verify-machineinstrs=0. PR38376.
2-
; RUN: llc < %s -mtriple=x86_64-pc-win32-coreclr -verify-machineinstrs=0 | FileCheck %s -check-prefix=WIN_X64
1+
; RUN: llc < %s -mtriple=x86_64-pc-win32-coreclr -verify-machineinstrs | FileCheck %s -check-prefix=WIN_X64
32
; RUN: llc < %s -mtriple=x86_64-pc-linux | FileCheck %s -check-prefix=LINUX
43

54
; By default, windows CoreCLR requires an inline prologue stack expansion check

0 commit comments

Comments
 (0)