[llvm] r364372 - [PowerPC][NFC] Move peephole optimization of RLDICR into a method.
Kai Luo via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 25 18:34:38 PDT 2019
Author: lkail
Date: Tue Jun 25 18:34:37 2019
New Revision: 364372
URL: http://llvm.org/viewvc/llvm-project?rev=364372&view=rev
Log:
[PowerPC][NFC] Move peephole optimization of RLDICR into a method.
Modified:
llvm/trunk/lib/Target/PowerPC/PPCMIPeephole.cpp
Modified: llvm/trunk/lib/Target/PowerPC/PPCMIPeephole.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCMIPeephole.cpp?rev=364372&r1=364371&r2=364372&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCMIPeephole.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCMIPeephole.cpp Tue Jun 25 18:34:37 2019
@@ -94,6 +94,7 @@ private:
// Perform peepholes.
bool eliminateRedundantCompare(void);
bool eliminateRedundantTOCSaves(std::map<MachineInstr *, bool> &TOCSaves);
+ void emitRLDICWhenLoweringJumpTables(MachineInstr &MI);
void UpdateTOCSaves(std::map<MachineInstr *, bool> &TOCSaves,
MachineInstr *MI);
@@ -760,53 +761,7 @@ bool PPCMIPeephole::simplifyCode(void) {
break;
}
case PPC::RLDICR: {
- // We miss the opportunity to emit an RLDIC when lowering jump tables
- // since ISEL sees only a single basic block. When selecting, the clear
- // and shift left will be in different blocks.
- unsigned SrcReg = MI.getOperand(1).getReg();
- if (!TargetRegisterInfo::isVirtualRegister(SrcReg))
- break;
-
- MachineInstr *SrcMI = MRI->getVRegDef(SrcReg);
- if (SrcMI->getOpcode() != PPC::RLDICL)
- break;
- MachineOperand MOpSHSrc = SrcMI->getOperand(2);
- MachineOperand MOpMBSrc = SrcMI->getOperand(3);
- MachineOperand MOpSHMI = MI.getOperand(2);
- MachineOperand MOpMEMI = MI.getOperand(3);
- if (!(MOpSHSrc.isImm() && MOpMBSrc.isImm() &&
- MOpSHMI.isImm() && MOpMEMI.isImm()))
- break;
- uint64_t SHSrc = MOpSHSrc.getImm();
- uint64_t MBSrc = MOpMBSrc.getImm();
- uint64_t SHMI = MOpSHMI.getImm();
- uint64_t MEMI = MOpMEMI.getImm();
- uint64_t NewSH = SHSrc + SHMI;
- uint64_t NewMB = MBSrc - SHMI;
- if (NewMB > 63 || NewSH > 63)
- break;
-
- // The bits cleared with RLDICL are [0, MBSrc).
- // The bits cleared with RLDICR are (MEMI, 63].
- // After the sequence, the bits cleared are:
- // [0, MBSrc-SHMI) and (MEMI, 63).
- //
- // The bits cleared with RLDIC are [0, NewMB) and (63-NewSH, 63].
- if ((63 - NewSH) != MEMI)
- break;
-
- LLVM_DEBUG(dbgs() << "Converting pair: ");
- LLVM_DEBUG(SrcMI->dump());
- LLVM_DEBUG(MI.dump());
-
- MI.setDesc(TII->get(PPC::RLDIC));
- MI.getOperand(1).setReg(SrcMI->getOperand(1).getReg());
- MI.getOperand(2).setImm(NewSH);
- MI.getOperand(3).setImm(NewMB);
-
- LLVM_DEBUG(dbgs() << "To: ");
- LLVM_DEBUG(MI.dump());
- NumRotatesCollapsed++;
+ emitRLDICWhenLoweringJumpTables(MI);
break;
}
}
@@ -1326,6 +1281,61 @@ bool PPCMIPeephole::eliminateRedundantCo
return Simplified;
}
+// We miss the opportunity to emit an RLDIC when lowering jump tables
+// since ISEL sees only a single basic block. When selecting, the clear
+// and shift left will be in different blocks.
+void PPCMIPeephole::emitRLDICWhenLoweringJumpTables(MachineInstr &MI) {
+ if (MI.getOpcode() != PPC::RLDICR)
+ return;
+
+ unsigned SrcReg = MI.getOperand(1).getReg();
+ if (!TargetRegisterInfo::isVirtualRegister(SrcReg))
+ return;
+
+ MachineInstr *SrcMI = MRI->getVRegDef(SrcReg);
+ if (SrcMI->getOpcode() != PPC::RLDICL)
+ return;
+
+ MachineOperand MOpSHSrc = SrcMI->getOperand(2);
+ MachineOperand MOpMBSrc = SrcMI->getOperand(3);
+ MachineOperand MOpSHMI = MI.getOperand(2);
+ MachineOperand MOpMEMI = MI.getOperand(3);
+ if (!(MOpSHSrc.isImm() && MOpMBSrc.isImm() && MOpSHMI.isImm() &&
+ MOpMEMI.isImm()))
+ return;
+
+ uint64_t SHSrc = MOpSHSrc.getImm();
+ uint64_t MBSrc = MOpMBSrc.getImm();
+ uint64_t SHMI = MOpSHMI.getImm();
+ uint64_t MEMI = MOpMEMI.getImm();
+ uint64_t NewSH = SHSrc + SHMI;
+ uint64_t NewMB = MBSrc - SHMI;
+ if (NewMB > 63 || NewSH > 63)
+ return;
+
+ // The bits cleared with RLDICL are [0, MBSrc).
+ // The bits cleared with RLDICR are (MEMI, 63].
+ // After the sequence, the bits cleared are:
+ // [0, MBSrc-SHMI) and (MEMI, 63).
+ //
+ // The bits cleared with RLDIC are [0, NewMB) and (63-NewSH, 63].
+ if ((63 - NewSH) != MEMI)
+ return;
+
+ LLVM_DEBUG(dbgs() << "Converting pair: ");
+ LLVM_DEBUG(SrcMI->dump());
+ LLVM_DEBUG(MI.dump());
+
+ MI.setDesc(TII->get(PPC::RLDIC));
+ MI.getOperand(1).setReg(SrcMI->getOperand(1).getReg());
+ MI.getOperand(2).setImm(NewSH);
+ MI.getOperand(3).setImm(NewMB);
+
+ LLVM_DEBUG(dbgs() << "To: ");
+ LLVM_DEBUG(MI.dump());
+ NumRotatesCollapsed++;
+}
+
} // end default namespace
INITIALIZE_PASS_BEGIN(PPCMIPeephole, DEBUG_TYPE,
More information about the llvm-commits
mailing list