Skip to content

Commit

Permalink
[NFC][PowerPC] Add NFC fixes to PPCInstrinfo.cpp when getting the def…
Browse files Browse the repository at this point in the history
…ined machine instruction.

This patch adds the following NFC fixes to PPCInstrInfo.cpp when getting the DefMI:
- Fix documentation error to state that we want to flag a use of register
  between the def and the MI (in post-RA)
- Setting the DefMI to null if the DefMI is neither an LI or and ADDI
  (while still being in SSA form).

In terms of setting the DefMI to null, this change aims to account for the
scenario of when we end up going through all operands on the machine instruction
MI and updating OpNoForForwarding accordingly once an ADDI is found as the DefMI.

It is possible that once an ADDI is found, we will continue to go through all
operands in attempts to find an LI, but end up looking at every operand until
we reach the end if we have not yet found an LI. In the case where the end is
reached and we never end up finding an LI/ADDI, DefMI would be pointing to the
last operand of MI while OpNoForForwarding would still be pointing at the
previous ADDI operand found. We reset DefMI to avoid having DefMI point to an
instruction that differs from the one represented by OpNoForForwarding.

Differential Revision: https://reviews.llvm.org/D137483
  • Loading branch information
amy-kwan committed Dec 6, 2022
1 parent 5ad919a commit 48634b3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
Expand Up @@ -3380,11 +3380,13 @@ MachineInstr *PPCInstrInfo::getForwardingDefMI(
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
Expand Down Expand Up @@ -3424,7 +3426,7 @@ MachineInstr *PPCInstrInfo::getForwardingDefMI(
if (MO.isReg() && MO.isUse() && !MO.isImplicit()) {
Register Reg = MI.getOperand(i).getReg();
// If we see another use of this reg between the def and the MI,
// we want to flat it so the def isn't deleted.
// we want to flag it so the def isn't deleted.
MachineInstr *DefMI = getDefMIPostRA(Reg, MI, SeenIntermediateUse);
if (DefMI) {
// Is this register defined by some form of add-immediate (including
Expand Down

0 comments on commit 48634b3

Please sign in to comment.