[llvm] [Analysis][RISCV] More accurately estimate the cost of strided vector loads (PR #175135)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 2 03:04:38 PST 2026


================
@@ -1274,6 +1274,25 @@ RISCVTTIImpl::getStridedMemoryOpCost(const MemIntrinsicCostAttributes &MICA,
       getMemoryOpCost(Opcode, VTy.getElementType(), Alignment, 0, CostKind,
                       {TTI::OK_AnyValue, TTI::OP_None}, I);
   unsigned NumLoads = getEstimatedVLFor(&VTy);
+  // Performant implementations of the vector extension will attempt to re-use
+  // elements if they fall on the same cache line
+  uint64_t CacheLineBytes = ST->getCacheLineSize();
+  if (!CacheLineBytes) // If no value, use default value of 64
+    CacheLineBytes = 64;
+  unsigned EltsPerCL = (CacheLineBytes * 8) / DataTy->getScalarSizeInBits();
+  if (const ConstantInt *StrideCI =
+          dyn_cast_or_null<ConstantInt>(MICA.getStrideVal())) {
+    uint64_t AbsStride = (uint64_t)std::abs(StrideCI->getSExtValue());
+    if (AbsStride < EltsPerCL) {
----------------
lukel97 wrote:

The stride is in terms of bytes, how come we're comparing it to the number of elements in a cache line? Should we be comparing it to the cache line size directly?

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


More information about the llvm-commits mailing list