[llvm] Promote 32bit pseudo instr that infer extsw removal to 64bit in PPCMIPeephole (PR #85451)
zhijian lin via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 23 10:58:10 PDT 2024
================
@@ -5234,6 +5234,216 @@ bool PPCInstrInfo::isTOCSaveMI(const MachineInstr &MI) const {
// We limit the max depth to track incoming values of PHIs or binary ops
// (e.g. AND) to avoid excessive cost.
const unsigned MAX_BINOP_DEPTH = 1;
+
+// This function will promote the instruction which defines the register `Reg`
+// in the parameter from a 32-bit to a 64-bit instruction if needed. The logic
+// used to check whether an instruction needs to be promoted or not is similar
+// to the logic used to check whether or not a defined register is sign or zero
+// extended within the function PPCInstrInfo::isSignOrZeroExtended.
+// Additionally, the `promoteInstr32To64ForElimEXTSW` function is recursive.
+// BinOpDepth does not count all of the recursions. The parameter BinOpDepth is
+// incremented only when `promoteInstr32To64ForElimEXTSW` calls itself more
+// than once. This is done to prevent exponential recursion.
+void PPCInstrInfo::promoteInstr32To64ForElimEXTSW(const Register &Reg,
+ MachineRegisterInfo *MRI,
+ unsigned BinOpDepth,
+ LiveVariables *LV) const {
+ if (!Reg.isVirtual())
+ return;
+
+ MachineInstr *MI = MRI->getVRegDef(Reg);
+ if (!MI)
+ return;
+
+ unsigned Opcode = MI->getOpcode();
+ bool HasNonSignedExtInstrPromoted = false;
+ int NewOpcode = -1;
+
+ std::unordered_map<unsigned, unsigned> OpcodeMap = {
+ {PPC::OR, PPC::OR8}, {PPC::ISEL, PPC::ISEL8},
+ {PPC::ORI, PPC::ORI8}, {PPC::XORI, PPC::XORI8},
+ {PPC::ORIS, PPC::ORIS8}, {PPC::XORIS, PPC::XORIS8},
+ {PPC::AND, PPC::AND8}};
+
+ // Check if the Opcode is in the map.
----------------
diggerlin wrote:
I add the comment in above
+ // Map the opcode of instructions (which are not sign- or zero-extended
+ // themselves,but have operands that are destination registers of sign- or
+ // zero-extended instructions) to their 64-bit equivalents.
I think it is clear enough to explain it, I delete the comment here.
https://github.com/llvm/llvm-project/pull/85451
More information about the llvm-commits
mailing list