[llvm] [RISCV][WIP] Enable sink-and-fold for RISC-V. (PR #67602)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 2 10:33:54 PDT 2023


================
@@ -1907,6 +1907,76 @@ bool RISCVInstrInfo::verifyInstruction(const MachineInstr &MI,
   return true;
 }
 
+bool RISCVInstrInfo::canFoldIntoAddrMode(const MachineInstr &MemI, Register Reg,
+                                         const MachineInstr &AddrI,
+                                         ExtAddrMode &AM) const {
+  switch (MemI.getOpcode()) {
+  default:
+    return false;
+  case RISCV::LB:
+  case RISCV::LBU:
+  case RISCV::LH:
+  case RISCV::LHU:
+  case RISCV::LW:
+  case RISCV::LWU:
+  case RISCV::LD:
+  case RISCV::FLH:
+  case RISCV::FLW:
+  case RISCV::FLD:
+  case RISCV::SB:
+  case RISCV::SH:
+  case RISCV::SW:
+  case RISCV::SD:
+  case RISCV::FSH:
+  case RISCV::FSW:
+  case RISCV::FSD:
+    break;
+  }
+
+  // Check the fold operand is not the loaded/stored value.
+  const MachineOperand &BaseRegOp = MemI.getOperand(0);
----------------
topperc wrote:

The name of the variable is confusing but I think the operand number is correct. Operand 0 is the destination for load and the value to store for stores. We're exiting if Reg is equal. This should never be true for a load. So we're only concerned with store. If they are equal for store, it means that Reg isn't the pointer.

https://github.com/llvm/llvm-project/pull/67602


More information about the llvm-commits mailing list