[PATCH] D40554: [PowerPC] Fix bugs in sign-/zero-extension elimination

Amy Kwan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 30 20:48:20 PDT 2022


amyk added inline comments.


================
Comment at: llvm/lib/Target/PowerPC/PPCInstrFormats.td:48
+  
+  // Indicate that this insturction produces a result that is sign extended from
+  // 32 bits to 64 bits.
----------------



================
Comment at: llvm/lib/Target/PowerPC/PPCInstrFormats.td:53
+
+  // Indicate that this insturction produces a result that is zero extended from
+  // 32 bits to 64 bits.
----------------



================
Comment at: llvm/lib/Target/PowerPC/PPCInstrInfo.cpp:5139
 
-// This function returns true if the machine instruction
-// always outputs zeros in higher 32 bits.
-static bool isZeroExtendingOp(const MachineInstr &MI) {
-  int Opcode = MI.getOpcode();
+// This function checks the machine instruction that defines the input regsiter
+// Reg. If that machine instruction always outputs a value that has only zeros
----------------
A minor nit on this comment.


================
Comment at: llvm/lib/Target/PowerPC/PPCInstrInfo.cpp:5180
 
-  // There are other instructions that clear higher 32-bits.
-  if (Opcode == PPC::CNTLZW || Opcode == PPC::CNTLZW_rec ||
-      Opcode == PPC::CNTTZW || Opcode == PPC::CNTTZW_rec ||
-      Opcode == PPC::CNTLZW8 || Opcode == PPC::CNTTZW8 ||
-      Opcode == PPC::CNTLZD || Opcode == PPC::CNTLZD_rec ||
-      Opcode == PPC::CNTTZD || Opcode == PPC::CNTTZD_rec ||
-      Opcode == PPC::POPCNTD || Opcode == PPC::POPCNTW || Opcode == PPC::SLW ||
-      Opcode == PPC::SLW_rec || Opcode == PPC::SRW || Opcode == PPC::SRW_rec ||
-      Opcode == PPC::SLW8 || Opcode == PPC::SRW8 || Opcode == PPC::SLWI ||
-      Opcode == PPC::SLWI_rec || Opcode == PPC::SRWI ||
-      Opcode == PPC::SRWI_rec || Opcode == PPC::LWZ || Opcode == PPC::LWZX ||
-      Opcode == PPC::LWZU || Opcode == PPC::LWZUX || Opcode == PPC::LWBRX ||
-      Opcode == PPC::LHBRX || Opcode == PPC::LHZ || Opcode == PPC::LHZX ||
-      Opcode == PPC::LHZU || Opcode == PPC::LHZUX || Opcode == PPC::LBZ ||
-      Opcode == PPC::LBZX || Opcode == PPC::LBZU || Opcode == PPC::LBZUX ||
-      Opcode == PPC::LWZ8 || Opcode == PPC::LWZX8 || Opcode == PPC::LWZU8 ||
-      Opcode == PPC::LWZUX8 || Opcode == PPC::LWBRX8 || Opcode == PPC::LHBRX8 ||
-      Opcode == PPC::LHZ8 || Opcode == PPC::LHZX8 || Opcode == PPC::LHZU8 ||
-      Opcode == PPC::LHZUX8 || Opcode == PPC::LBZ8 || Opcode == PPC::LBZX8 ||
-      Opcode == PPC::LBZU8 || Opcode == PPC::LBZUX8 ||
-      Opcode == PPC::ANDI_rec || Opcode == PPC::ANDIS_rec ||
-      Opcode == PPC::ROTRWI || Opcode == PPC::ROTRWI_rec ||
-      Opcode == PPC::EXTLWI || Opcode == PPC::EXTLWI_rec ||
-      Opcode == PPC::MFVSRWZ)
+  const PPCInstrInfo *TII =
+      MI->getMF()->getSubtarget<PPCSubtarget>().getInstrInfo();
----------------
Question: This is something super minor, but is it better to put the check for `isZExt32To64()` earlier in the function? 

I know it may not matter, but I am just wondering in case it may be better to do this prior to all of the different opcode checks, and since the `definedBySignExtendingOp` also put it's `isSExt32To64()` pretty early in the function.

In any case, this is just a question so if it's not applicable, you can feel free to disregard this.


================
Comment at: llvm/lib/Target/PowerPC/PPCInstrInfo.cpp:5139
 
-// This function returns true if the machine instruction
-// always outputs zeros in higher 32 bits.
-static bool isZeroExtendingOp(const MachineInstr &MI) {
-  int Opcode = MI.getOpcode();
+// This function checks the machine instruction that defines the input regsiter
+// Reg. If that machine instruction always outputs a value that has only zeros
----------------



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D40554/new/

https://reviews.llvm.org/D40554



More information about the llvm-commits mailing list