[llvm] b430980 - [CodeGen] Don't zero callee-save registers with zero-call-used-regs (PR57692)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 16 02:52:41 PDT 2022
Author: Nikita Popov
Date: 2022-09-16T11:52:29+02:00
New Revision: b4309800e9dc53a84222a6b57c8615d4a3084988
URL: https://github.com/llvm/llvm-project/commit/b4309800e9dc53a84222a6b57c8615d4a3084988
DIFF: https://github.com/llvm/llvm-project/commit/b4309800e9dc53a84222a6b57c8615d4a3084988.diff
LOG: [CodeGen] Don't zero callee-save registers with zero-call-used-regs (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 https://github.com/llvm/llvm-project/issues/57692.
Differential Revision: https://reviews.llvm.org/D133946
Added:
Modified:
llvm/lib/CodeGen/PrologEpilogInserter.cpp
llvm/test/CodeGen/AArch64/zero-call-used-regs.ll
llvm/test/CodeGen/X86/zero-call-used-regs.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/PrologEpilogInserter.cpp b/llvm/lib/CodeGen/PrologEpilogInserter.cpp
index 64536bf324a25..b7f764cc552a0 100644
--- a/llvm/lib/CodeGen/PrologEpilogInserter.cpp
+++ b/llvm/lib/CodeGen/PrologEpilogInserter.cpp
@@ -1273,9 +1273,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();
diff --git a/llvm/test/CodeGen/AArch64/zero-call-used-regs.ll b/llvm/test/CodeGen/AArch64/zero-call-used-regs.ll
index c39089908713b..0cbd1557829f2 100644
--- a/llvm/test/CodeGen/AArch64/zero-call-used-regs.ll
+++ b/llvm/test/CodeGen/AArch64/zero-call-used-regs.ll
@@ -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
@@ -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
@@ -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
@@ -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
diff --git a/llvm/test/CodeGen/X86/zero-call-used-regs.ll b/llvm/test/CodeGen/X86/zero-call-used-regs.ll
index 146f5e37d9a10..63d51c916bb98 100644
--- a/llvm/test/CodeGen/X86/zero-call-used-regs.ll
+++ b/llvm/test/CodeGen/X86/zero-call-used-regs.ll
@@ -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
@@ -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:
@@ -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
@@ -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
@@ -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
More information about the llvm-commits
mailing list