Skip to content

Commit f800c1f

Browse files
committed
[PEI] Don't zero out noreg operands
A tail call may have $noreg operands. Fixes a crash. Reviewed By: xgupta Differential Revision: https://reviews.llvm.org/D156485
1 parent b5f7852 commit f800c1f

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

llvm/lib/CodeGen/PrologEpilogInserter.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,8 @@ void PEI::insertZeroCallUsedRegs(MachineFunction &MF) {
12981298
continue;
12991299

13001300
MCRegister Reg = MO.getReg();
1301+
if (!Reg)
1302+
continue;
13011303

13021304
// This picks up sibling registers (e.q. %al -> %ah).
13031305
for (MCRegUnit Unit : TRI.regunits(Reg))
@@ -1321,8 +1323,11 @@ void PEI::insertZeroCallUsedRegs(MachineFunction &MF) {
13211323
if (!MO.isReg())
13221324
continue;
13231325

1324-
for (const MCPhysReg &Reg :
1325-
TRI.sub_and_superregs_inclusive(MO.getReg()))
1326+
MCRegister Reg = MO.getReg();
1327+
if (!Reg)
1328+
continue;
1329+
1330+
for (const MCPhysReg Reg : TRI.sub_and_superregs_inclusive(Reg))
13261331
RegsToZero.reset(Reg);
13271332
}
13281333
}

llvm/test/CodeGen/X86/zero-call-used-regs.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,20 @@ entry:
241241
ret i32 %x
242242
}
243243

244+
define dso_local void @tailcall(ptr %p) local_unnamed_addr #0 "zero-call-used-regs"="used-gpr" {
245+
; I386-LABEL: tailcall:
246+
; I386: # %bb.0:
247+
; I386-NEXT: movl {{[0-9]+}}(%esp), %eax
248+
; I386-NEXT: jmpl *(%eax) # TAILCALL
249+
;
250+
; X86-64-LABEL: tailcall:
251+
; X86-64: # %bb.0:
252+
; X86-64-NEXT: jmpq *(%rdi) # TAILCALL
253+
%c = load ptr, ptr %p
254+
tail call void %c()
255+
ret void
256+
}
257+
244258
; Don't emit zeroing registers in "main" function.
245259
define dso_local i32 @main() local_unnamed_addr #1 {
246260
; I386-LABEL: main:

0 commit comments

Comments
 (0)