diff --git a/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp b/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp --- a/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp +++ b/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp @@ -3380,11 +3380,13 @@ continue; Register TrueReg = TRI->lookThruCopyLike(Reg, MRI); if (Register::isVirtualRegister(TrueReg)) { - DefMI = MRI->getVRegDef(TrueReg); - if (DefMI->getOpcode() == PPC::LI || DefMI->getOpcode() == PPC::LI8 || - DefMI->getOpcode() == PPC::ADDI || - DefMI->getOpcode() == PPC::ADDI8) { + MachineInstr *DefMIForTrueReg = MRI->getVRegDef(TrueReg); + if (DefMIForTrueReg->getOpcode() == PPC::LI || + DefMIForTrueReg->getOpcode() == PPC::LI8 || + DefMIForTrueReg->getOpcode() == PPC::ADDI || + DefMIForTrueReg->getOpcode() == PPC::ADDI8) { OpNoForForwarding = i; + DefMI = DefMIForTrueReg; // The ADDI and LI operand maybe exist in one instruction at same // time. we prefer to fold LI operand as LI only has one Imm operand // and is more possible to be converted. So if current DefMI is