Skip to content

Commit

Permalink
[PEI] Don't zero out noreg operands
Browse files Browse the repository at this point in the history
A tail call may have $noreg operands.

Fixes a crash.

Reviewed By: xgupta

Differential Revision: https://reviews.llvm.org/D156485
  • Loading branch information
aeubanks committed Jul 28, 2023
1 parent b5f7852 commit f800c1f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
9 changes: 7 additions & 2 deletions llvm/lib/CodeGen/PrologEpilogInserter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,8 @@ void PEI::insertZeroCallUsedRegs(MachineFunction &MF) {
continue;

MCRegister Reg = MO.getReg();
if (!Reg)
continue;

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

for (const MCPhysReg &Reg :
TRI.sub_and_superregs_inclusive(MO.getReg()))
MCRegister Reg = MO.getReg();
if (!Reg)
continue;

for (const MCPhysReg Reg : TRI.sub_and_superregs_inclusive(Reg))
RegsToZero.reset(Reg);
}
}
Expand Down
14 changes: 14 additions & 0 deletions llvm/test/CodeGen/X86/zero-call-used-regs.ll
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,20 @@ entry:
ret i32 %x
}

define dso_local void @tailcall(ptr %p) local_unnamed_addr #0 "zero-call-used-regs"="used-gpr" {
; I386-LABEL: tailcall:
; I386: # %bb.0:
; I386-NEXT: movl {{[0-9]+}}(%esp), %eax
; I386-NEXT: jmpl *(%eax) # TAILCALL
;
; X86-64-LABEL: tailcall:
; X86-64: # %bb.0:
; X86-64-NEXT: jmpq *(%rdi) # TAILCALL
%c = load ptr, ptr %p
tail call void %c()
ret void
}

; Don't emit zeroing registers in "main" function.
define dso_local i32 @main() local_unnamed_addr #1 {
; I386-LABEL: main:
Expand Down

0 comments on commit f800c1f

Please sign in to comment.