diff --git a/llvm/lib/Target/X86/X86FixupSetCC.cpp b/llvm/lib/Target/X86/X86FixupSetCC.cpp --- a/llvm/lib/Target/X86/X86FixupSetCC.cpp +++ b/llvm/lib/Target/X86/X86FixupSetCC.cpp @@ -97,28 +97,28 @@ if (FlagsDefMI->readsRegister(X86::EFLAGS)) continue; - ++NumSubstZexts; - Changed = true; - // On 32-bit, we need to be careful to force an ABCD register. const TargetRegisterClass *RC = MF.getSubtarget().is64Bit() ? &X86::GR32RegClass : &X86::GR32_ABCDRegClass; - Register ZeroReg = MRI->createVirtualRegister(RC); - Register InsertReg = MRI->createVirtualRegister(RC); + if (!MRI->constrainRegClass(ZExt->getOperand(0).getReg(), RC)) + continue; + + ++NumSubstZexts; + Changed = true; // Initialize a register with 0. This must go before the eflags def + Register ZeroReg = MRI->createVirtualRegister(RC); BuildMI(MBB, FlagsDefMI, MI.getDebugLoc(), TII->get(X86::MOV32r0), ZeroReg); // X86 setcc only takes an output GR8, so fake a GR32 input by inserting // the setcc result into the low byte of the zeroed register. BuildMI(*ZExt->getParent(), ZExt, ZExt->getDebugLoc(), - TII->get(X86::INSERT_SUBREG), InsertReg) + TII->get(X86::INSERT_SUBREG), ZExt->getOperand(0).getReg()) .addReg(ZeroReg) .addReg(MI.getOperand(0).getReg()) .addImm(X86::sub_8bit); - MRI->replaceRegWith(ZExt->getOperand(0).getReg(), InsertReg); ToErase.push_back(ZExt); } }