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

Mikhail Gudim via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 2 11:59:20 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);
----------------
mgudim wrote:

Oh, ok. I read the context from `MachineSink.cpp`  - the `Reg` is known to be a use in `MemI` and we're still in SSA form. Could we rename the variable to something else? How about `ValueOp`?

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


More information about the llvm-commits mailing list