diff --git a/llvm/lib/CodeGen/PrologEpilogInserter.cpp b/llvm/lib/CodeGen/PrologEpilogInserter.cpp --- a/llvm/lib/CodeGen/PrologEpilogInserter.cpp +++ b/llvm/lib/CodeGen/PrologEpilogInserter.cpp @@ -1193,7 +1193,8 @@ // Mark all used registers. BitVector UsedRegs(TRI.getNumRegs()); - if (OnlyUsed) + if (OnlyUsed) { + const MachineRegisterInfo &MRI = MF.getRegInfo(); for (const MachineBasicBlock &MBB : MF) for (const MachineInstr &MI : MBB) for (const MachineOperand &MO : MI.operands()) { @@ -1202,9 +1203,10 @@ MCRegister Reg = MO.getReg(); if (AllocatableSet[Reg] && !MO.isImplicit() && - (MO.isDef() || MO.isUse())) + MRI.isPhysRegModified(Reg)) UsedRegs.set(Reg); } + } BitVector RegsToZero(TRI.getNumRegs()); for (MCRegister Reg : AllocatableSet.set_bits()) { diff --git a/llvm/test/CodeGen/AArch64/zero-call-used-regs.ll b/llvm/test/CodeGen/AArch64/zero-call-used-regs.ll --- a/llvm/test/CodeGen/AArch64/zero-call-used-regs.ll +++ b/llvm/test/CodeGen/AArch64/zero-call-used-regs.ll @@ -22,8 +22,6 @@ ; CHECK: // %bb.0: // %entry ; CHECK-NEXT: mul w8, w1, w0 ; CHECK-NEXT: orr w0, w8, w2 -; CHECK-NEXT: mov x1, #0 -; CHECK-NEXT: mov x2, #0 ; CHECK-NEXT: ret entry: @@ -37,8 +35,6 @@ ; CHECK: // %bb.0: // %entry ; CHECK-NEXT: mul w8, w1, w0 ; CHECK-NEXT: orr w0, w8, w2 -; CHECK-NEXT: mov x1, #0 -; CHECK-NEXT: mov x2, #0 ; CHECK-NEXT: mov x8, #0 ; CHECK-NEXT: ret @@ -53,8 +49,6 @@ ; CHECK: // %bb.0: // %entry ; CHECK-NEXT: mul w8, w1, w0 ; CHECK-NEXT: orr w0, w8, w2 -; CHECK-NEXT: mov x1, #0 -; CHECK-NEXT: mov x2, #0 ; CHECK-NEXT: ret entry: @@ -68,8 +62,6 @@ ; CHECK: // %bb.0: // %entry ; CHECK-NEXT: mul w8, w1, w0 ; CHECK-NEXT: orr w0, w8, w2 -; CHECK-NEXT: mov x1, #0 -; CHECK-NEXT: mov x2, #0 ; CHECK-NEXT: mov x8, #0 ; CHECK-NEXT: ret diff --git a/llvm/test/CodeGen/X86/zero-call-used-regs.ll b/llvm/test/CodeGen/X86/zero-call-used-regs.ll --- a/llvm/test/CodeGen/X86/zero-call-used-regs.ll +++ b/llvm/test/CodeGen/X86/zero-call-used-regs.ll @@ -28,7 +28,6 @@ ; X86-64-LABEL: used_gpr_arg: ; X86-64: # %bb.0: # %entry ; X86-64-NEXT: movl %edi, %eax -; X86-64-NEXT: xorl %edi, %edi ; X86-64-NEXT: retq entry: @@ -44,7 +43,6 @@ ; X86-64-LABEL: used_gpr: ; X86-64: # %bb.0: # %entry ; X86-64-NEXT: movl %edi, %eax -; X86-64-NEXT: xorl %edi, %edi ; X86-64-NEXT: retq entry: @@ -60,7 +58,6 @@ ; X86-64-LABEL: used_arg: ; X86-64: # %bb.0: # %entry ; X86-64-NEXT: movl %edi, %eax -; X86-64-NEXT: xorl %edi, %edi ; X86-64-NEXT: retq entry: @@ -76,7 +73,6 @@ ; X86-64-LABEL: used: ; X86-64: # %bb.0: # %entry ; X86-64-NEXT: movl %edi, %eax -; X86-64-NEXT: xorl %edi, %edi ; X86-64-NEXT: retq entry: