[llvm] [RISCV] Add optimization for memset inline (PR #146673)

Boyao Wang via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 25 01:39:11 PST 2025


================
@@ -1799,7 +1799,11 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
   PredictableSelectIsExpensive = Subtarget.predictableSelectIsExpensive();
 
   MaxStoresPerMemsetOptSize = Subtarget.getMaxStoresPerMemset(/*OptSize=*/true);
-  MaxStoresPerMemset = Subtarget.getMaxStoresPerMemset(/*OptSize=*/false);
+  MaxStoresPerMemset = Subtarget.hasVInstructions()
+                           ? (Subtarget.getRealMinVLen() / 8 *
+                              Subtarget.getMaxLMULForFixedLengthVectors() /
+                              (Subtarget.is64Bit() ? 8 : 4))
----------------
BoyaoWang430 wrote:

If Op.size() exceeds Subtarget.getMaxLMULForFixedLengthVectors() * MinVLenInBytes, the memset should not be inlined. To determine whether inlining is profitable, llvm checks how many scalar stores would be required when using the widest scalar store type available on the target. On RV64, the widest scalar store type is i64, while on RV32 it is i32. Therefore, MaxStoresPerMemset should be computed differently depending on the target’s XLEN.

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


More information about the llvm-commits mailing list