[llvm] [RISCV] Fold `addi` into load / store even if they are in different BBs. (PR #67024)

Mikhail Gudim via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 22 08:10:01 PDT 2023


================
@@ -2278,6 +2279,81 @@ bool RISCVTargetLowering::isLegalElementTypeForRVV(EVT ScalarTy) const {
   }
 }
 
+static bool tryToFoldInstIntoUse(MachineInstr &UseMI, MachineInstr &MI) {
+
+  if (MI.getOpcode() != RISCV::ADDI)
+    return false;
+  if (!(MI.getOperand(0).isReg() && MI.getOperand(1).isReg()))
+    return false;
+
+  switch (UseMI.getOpcode()) {
+  default:
+    return false;
+  case RISCV::LB:
+  case RISCV::LH:
+  case RISCV::LW:
+  case RISCV::LD:
+  case RISCV::LBU:
+  case RISCV::LHU:
+  case RISCV::SB:
+  case RISCV::SH:
+  case RISCV::SW:
+  case RISCV::SD:
----------------
mgudim wrote:

I just realized I should also include FP loads and stores.

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


More information about the llvm-commits mailing list