diff --git a/llvm/lib/Target/X86/X86FrameLowering.cpp b/llvm/lib/Target/X86/X86FrameLowering.cpp --- a/llvm/lib/Target/X86/X86FrameLowering.cpp +++ b/llvm/lib/Target/X86/X86FrameLowering.cpp @@ -538,14 +538,18 @@ } // For GPRs, we only care to clear out the 32-bit register. + BitVector GPRsToZero(TRI->getNumRegs()); for (MCRegister Reg : RegsToZero.set_bits()) if (TRI->isGeneralPurposeRegister(MF, Reg)) { - Reg = getX86SubSuperRegisterOrZero(Reg, 32); - for (const MCPhysReg &Reg : TRI->sub_and_superregs_inclusive(Reg)) - RegsToZero.reset(Reg); - RegsToZero.set(Reg); + GPRsToZero.set(getX86SubSuperRegisterOrZero(Reg, 32)); + RegsToZero.reset(Reg); } + for (MCRegister Reg : GPRsToZero.set_bits()) + BuildMI(MBB, MBBI, DL, TII.get(X86::XOR32rr), Reg) + .addReg(Reg, RegState::Undef) + .addReg(Reg, RegState::Undef); + // Zero out registers. for (MCRegister Reg : RegsToZero.set_bits()) { if (ST.hasMMX() && X86::VR64RegClass.contains(Reg)) @@ -553,9 +557,7 @@ continue; unsigned XorOp; - if (TRI->isGeneralPurposeRegister(MF, Reg)) { - XorOp = X86::XOR32rr; - } else if (X86::VR128RegClass.contains(Reg)) { + if (X86::VR128RegClass.contains(Reg)) { // XMM# if (!ST.hasSSE1()) continue; 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 @@ -156,6 +156,8 @@ ; X86-64-NEXT: xorl %edi, %edi ; X86-64-NEXT: xorl %edx, %edx ; X86-64-NEXT: xorl %esi, %esi +; X86-64-NEXT: xorl %r8d, %r8d +; X86-64-NEXT: xorl %r9d, %r9d ; X86-64-NEXT: xorps %xmm0, %xmm0 ; X86-64-NEXT: xorps %xmm1, %xmm1 ; X86-64-NEXT: xorps %xmm2, %xmm2 @@ -164,8 +166,6 @@ ; X86-64-NEXT: xorps %xmm5, %xmm5 ; X86-64-NEXT: xorps %xmm6, %xmm6 ; X86-64-NEXT: xorps %xmm7, %xmm7 -; X86-64-NEXT: xorl %r8d, %r8d -; X86-64-NEXT: xorl %r9d, %r9d ; X86-64-NEXT: retq entry: @@ -231,6 +231,14 @@ ; X86-64-NEXT: xorl %edi, %edi ; X86-64-NEXT: xorl %edx, %edx ; X86-64-NEXT: xorl %esi, %esi +; X86-64-NEXT: xorl %r8d, %r8d +; 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 @@ -247,14 +255,6 @@ ; X86-64-NEXT: xorps %xmm13, %xmm13 ; X86-64-NEXT: xorps %xmm14, %xmm14 ; X86-64-NEXT: xorps %xmm15, %xmm15 -; X86-64-NEXT: xorl %r8d, %r8d -; 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: