Skip to content

Commit

Permalink
[CodeGen] Don't zero callee-save registers with zero-call-used-regs (…
Browse files Browse the repository at this point in the history
…PR57692)

Callee save registers must be preserved, so -fzero-call-used-regs
should not be zeroing them. The previous implementation only did
not zero callee save registers that were saved&restored inside the
function, but we need preserve all of them.

Fixes #57692.

Differential Revision: https://reviews.llvm.org/D133946

(cherry picked from commit b430980)
  • Loading branch information
nikic authored and tru committed Sep 19, 2022
1 parent 433f2aa commit d4bada9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 55 deletions.
7 changes: 4 additions & 3 deletions llvm/lib/CodeGen/PrologEpilogInserter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1262,9 +1262,10 @@ void PEI::insertZeroCallUsedRegs(MachineFunction &MF) {
}
}

// Don't clear registers that are reset before exiting.
for (const CalleeSavedInfo &CSI : MF.getFrameInfo().getCalleeSavedInfo())
for (MCRegister Reg : TRI.sub_and_superregs_inclusive(CSI.getReg()))
// Don't clear registers that must be preserved.
for (const MCPhysReg *CSRegs = TRI.getCalleeSavedRegs(&MF);
MCPhysReg CSReg = *CSRegs; ++CSRegs)
for (MCRegister Reg : TRI.sub_and_superregs_inclusive(CSReg))
RegsToZero.reset(Reg);

const TargetFrameLowering &TFI = *MF.getSubtarget().getFrameLowering();
Expand Down
32 changes: 0 additions & 32 deletions llvm/test/CodeGen/AArch64/zero-call-used-regs.ll
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,6 @@ define dso_local i32 @all(i32 noundef %a, i32 noundef %b, i32 noundef %c) local_
; DEFAULT-NEXT: movi v5.2d, #0000000000000000
; DEFAULT-NEXT: movi v6.2d, #0000000000000000
; DEFAULT-NEXT: movi v7.2d, #0000000000000000
; DEFAULT-NEXT: movi v8.2d, #0000000000000000
; DEFAULT-NEXT: movi v9.2d, #0000000000000000
; DEFAULT-NEXT: movi v10.2d, #0000000000000000
; DEFAULT-NEXT: movi v11.2d, #0000000000000000
; DEFAULT-NEXT: movi v12.2d, #0000000000000000
; DEFAULT-NEXT: movi v13.2d, #0000000000000000
; DEFAULT-NEXT: movi v14.2d, #0000000000000000
; DEFAULT-NEXT: movi v15.2d, #0000000000000000
; DEFAULT-NEXT: movi v16.2d, #0000000000000000
; DEFAULT-NEXT: movi v17.2d, #0000000000000000
; DEFAULT-NEXT: movi v18.2d, #0000000000000000
Expand Down Expand Up @@ -276,14 +268,6 @@ define dso_local i32 @all(i32 noundef %a, i32 noundef %b, i32 noundef %c) local_
; SVE-NEXT: mov z5.d, #0 // =0x0
; SVE-NEXT: mov z6.d, #0 // =0x0
; SVE-NEXT: mov z7.d, #0 // =0x0
; SVE-NEXT: mov z8.d, #0 // =0x0
; SVE-NEXT: mov z9.d, #0 // =0x0
; SVE-NEXT: mov z10.d, #0 // =0x0
; SVE-NEXT: mov z11.d, #0 // =0x0
; SVE-NEXT: mov z12.d, #0 // =0x0
; SVE-NEXT: mov z13.d, #0 // =0x0
; SVE-NEXT: mov z14.d, #0 // =0x0
; SVE-NEXT: mov z15.d, #0 // =0x0
; SVE-NEXT: mov z16.d, #0 // =0x0
; SVE-NEXT: mov z17.d, #0 // =0x0
; SVE-NEXT: mov z18.d, #0 // =0x0
Expand Down Expand Up @@ -548,14 +532,6 @@ define dso_local double @all_float(double noundef %a, float noundef %b) local_un
; DEFAULT-NEXT: movi v5.2d, #0000000000000000
; DEFAULT-NEXT: movi v6.2d, #0000000000000000
; DEFAULT-NEXT: movi v7.2d, #0000000000000000
; DEFAULT-NEXT: movi v8.2d, #0000000000000000
; DEFAULT-NEXT: movi v9.2d, #0000000000000000
; DEFAULT-NEXT: movi v10.2d, #0000000000000000
; DEFAULT-NEXT: movi v11.2d, #0000000000000000
; DEFAULT-NEXT: movi v12.2d, #0000000000000000
; DEFAULT-NEXT: movi v13.2d, #0000000000000000
; DEFAULT-NEXT: movi v14.2d, #0000000000000000
; DEFAULT-NEXT: movi v15.2d, #0000000000000000
; DEFAULT-NEXT: movi v16.2d, #0000000000000000
; DEFAULT-NEXT: movi v17.2d, #0000000000000000
; DEFAULT-NEXT: movi v18.2d, #0000000000000000
Expand Down Expand Up @@ -604,14 +580,6 @@ define dso_local double @all_float(double noundef %a, float noundef %b) local_un
; SVE-NEXT: mov z5.d, #0 // =0x0
; SVE-NEXT: mov z6.d, #0 // =0x0
; SVE-NEXT: mov z7.d, #0 // =0x0
; SVE-NEXT: mov z8.d, #0 // =0x0
; SVE-NEXT: mov z9.d, #0 // =0x0
; SVE-NEXT: mov z10.d, #0 // =0x0
; SVE-NEXT: mov z11.d, #0 // =0x0
; SVE-NEXT: mov z12.d, #0 // =0x0
; SVE-NEXT: mov z13.d, #0 // =0x0
; SVE-NEXT: mov z14.d, #0 // =0x0
; SVE-NEXT: mov z15.d, #0 // =0x0
; SVE-NEXT: mov z16.d, #0 // =0x0
; SVE-NEXT: mov z17.d, #0 // =0x0
; SVE-NEXT: mov z18.d, #0 // =0x0
Expand Down
20 changes: 0 additions & 20 deletions llvm/test/CodeGen/X86/zero-call-used-regs.ll
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,13 @@ define dso_local i32 @all_gpr(i32 returned %x) local_unnamed_addr #0 "zero-call-
; I386-LABEL: all_gpr:
; I386: # %bb.0: # %entry
; I386-NEXT: movl {{[0-9]+}}(%esp), %eax
; I386-NEXT: xorl %ebp, %ebp
; I386-NEXT: xorl %ebx, %ebx
; I386-NEXT: xorl %ecx, %ecx
; I386-NEXT: xorl %edi, %edi
; I386-NEXT: xorl %edx, %edx
; I386-NEXT: xorl %esi, %esi
; I386-NEXT: retl
;
; X86-64-LABEL: all_gpr:
; X86-64: # %bb.0: # %entry
; X86-64-NEXT: movl %edi, %eax
; X86-64-NEXT: xorl %ebp, %ebp
; X86-64-NEXT: xorl %ebx, %ebx
; X86-64-NEXT: xorl %ecx, %ecx
; X86-64-NEXT: xorl %edi, %edi
; X86-64-NEXT: xorl %edx, %edx
Expand All @@ -131,10 +125,6 @@ define dso_local i32 @all_gpr(i32 returned %x) local_unnamed_addr #0 "zero-call-
; X86-64-NEXT: xorl %r9d, %r9d
; X86-64-NEXT: xorl %r10d, %r10d
; X86-64-NEXT: xorl %r11d, %r11d
; X86-64-NEXT: xorl %r12d, %r12d
; X86-64-NEXT: xorl %r13d, %r13d
; X86-64-NEXT: xorl %r14d, %r14d
; X86-64-NEXT: xorl %r15d, %r15d
; X86-64-NEXT: retq

entry:
Expand Down Expand Up @@ -190,12 +180,8 @@ define dso_local i32 @all(i32 returned %x) local_unnamed_addr #0 "zero-call-used
; I386-NEXT: fstp %st(0)
; I386-NEXT: fstp %st(0)
; I386-NEXT: fstp %st(0)
; I386-NEXT: xorl %ebp, %ebp
; I386-NEXT: xorl %ebx, %ebx
; I386-NEXT: xorl %ecx, %ecx
; I386-NEXT: xorl %edi, %edi
; I386-NEXT: xorl %edx, %edx
; I386-NEXT: xorl %esi, %esi
; I386-NEXT: xorps %xmm0, %xmm0
; I386-NEXT: xorps %xmm1, %xmm1
; I386-NEXT: xorps %xmm2, %xmm2
Expand Down Expand Up @@ -225,8 +211,6 @@ define dso_local i32 @all(i32 returned %x) local_unnamed_addr #0 "zero-call-used
; X86-64-NEXT: fstp %st(0)
; X86-64-NEXT: fstp %st(0)
; X86-64-NEXT: fstp %st(0)
; X86-64-NEXT: xorl %ebp, %ebp
; X86-64-NEXT: xorl %ebx, %ebx
; X86-64-NEXT: xorl %ecx, %ecx
; X86-64-NEXT: xorl %edi, %edi
; X86-64-NEXT: xorl %edx, %edx
Expand All @@ -235,10 +219,6 @@ define dso_local i32 @all(i32 returned %x) local_unnamed_addr #0 "zero-call-used
; X86-64-NEXT: xorl %r9d, %r9d
; X86-64-NEXT: xorl %r10d, %r10d
; X86-64-NEXT: xorl %r11d, %r11d
; X86-64-NEXT: xorl %r12d, %r12d
; X86-64-NEXT: xorl %r13d, %r13d
; X86-64-NEXT: xorl %r14d, %r14d
; X86-64-NEXT: xorl %r15d, %r15d
; X86-64-NEXT: xorps %xmm0, %xmm0
; X86-64-NEXT: xorps %xmm1, %xmm1
; X86-64-NEXT: xorps %xmm2, %xmm2
Expand Down

0 comments on commit d4bada9

Please sign in to comment.