Index: lib/CodeGen/TwoAddressInstructionPass.cpp =================================================================== --- lib/CodeGen/TwoAddressInstructionPass.cpp +++ lib/CodeGen/TwoAddressInstructionPass.cpp @@ -1518,7 +1518,8 @@ // If this operand is folding a truncation, the truncation now moves to the // copy so that the register classes remain valid for the operands. MIB.addReg(RegB, 0, SubRegB); - const TargetRegisterClass *RC = MRI->getRegClass(RegB); + const TargetRegisterClass *RC = TII->getRegClass(MI->getDesc(), SrcIdx, TRI, + *MF); if (SubRegB) { if (TargetRegisterInfo::isVirtualRegister(RegA)) { assert(TRI->getMatchingSuperRegClass(RC, MRI->getRegClass(RegA), @@ -1578,7 +1579,8 @@ if (AllUsesCopied) { if (!IsEarlyClobber) { // Replace other (un-tied) uses of regB with LastCopiedReg. - for (MachineOperand &MO : MI->operands()) { + for (unsigned i = 0; i != MI->getNumOperands(); ++i) { + MachineOperand &MO = MI->getOperand(i); if (MO.isReg() && MO.getReg() == RegB && MO.isUse()) { if (MO.isKill()) { @@ -1587,6 +1589,11 @@ } MO.setReg(LastCopiedReg); MO.setSubReg(MO.getSubReg()); + // Apply any constraints for this operand. + if (TargetRegisterInfo::isVirtualRegister(LastCopiedReg)) + MRI->constrainRegClass(LastCopiedReg, + TII->getRegClass(MI->getDesc(), i, TRI, + *MF)); } } } Index: test/CodeGen/PowerPC/fma-mutate.ll =================================================================== --- test/CodeGen/PowerPC/fma-mutate.ll +++ test/CodeGen/PowerPC/fma-mutate.ll @@ -15,7 +15,7 @@ ; CHECK: @foo3 ; CHECK: xsnmsubadp [[REG:[0-9]+]], {{[0-9]+}}, [[REG]] -; CHECK: xsmaddmdp +; CHECK: xsmaddadp ; CHECK: xsmaddadp }