[llvm] [RISCV] Hoist immediate addresses from loads/stores (PR #83644)

Wang Pengcheng via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 4 19:10:32 PST 2024


================
@@ -162,6 +162,14 @@ InstructionCost RISCVTTIImpl::getIntImmCostInst(unsigned Opcode, unsigned Idx,
     // split up large offsets in GEP into better parts than ConstantHoisting
     // can.
     return TTI::TCC_Free;
+  case Instruction::Store:
+    // If the address is a constant, use the materialization cost.
+    if (Idx == 1)
+      return getIntImmCost(Imm, Ty, CostKind);
----------------
wangpc-pp wrote:

There are more things we should care about after diving into the code of `RISCVMatInt::getIntMatCost`:
* What if RVC exists?
* What about immediates that can be materialized via a single `LUI/SLLI/BSETI/...` like `0x80000000` (w/ or w/o RVC)? These immediates can't be folded into load/store offsets.
* Why we return the size of inst sequence as the cost w/o RVC, but the cost scales by 100 w/ RVC?

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


More information about the llvm-commits mailing list