[llvm] [RISCV] Cost legal interleaved memory ops correctly for code size (PR #207162)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 2 04:50:31 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: Luke Lau (lukel97)
<details>
<summary>Changes</summary>
This doesn't yet handle interleaved memory ops with a factor > 8 or with a gap mask, that still needs to be handled below.
---
Full diff: https://github.com/llvm/llvm-project/pull/207162.diff
2 Files Affected:
- (modified) llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp (+3)
- (modified) llvm/test/Transforms/LoopVectorize/RISCV/interleaved-cost.ll (+85)
``````````diff
diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index 07a962f7dd03d..b350ea1b9525e 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -1117,6 +1117,9 @@ InstructionCost RISCVTTIImpl::getInterleavedMemoryOpCost(
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(VTy);
// Need to make sure type has't been scalarized
if (LT.second.isVector()) {
+ if (CostKind == TTI::TCK_CodeSize)
+ return TTI::TCC_Basic;
+
auto *SubVecTy =
VectorType::get(VTy->getElementType(),
VTy->getElementCount().divideCoefficientBy(Factor));
diff --git a/llvm/test/Transforms/LoopVectorize/RISCV/interleaved-cost.ll b/llvm/test/Transforms/LoopVectorize/RISCV/interleaved-cost.ll
index 62c73635e419e..435882cee52f1 100644
--- a/llvm/test/Transforms/LoopVectorize/RISCV/interleaved-cost.ll
+++ b/llvm/test/Transforms/LoopVectorize/RISCV/interleaved-cost.ll
@@ -4,6 +4,7 @@
; RUN: opt -passes=loop-vectorize -mtriple=riscv64 -mattr=+v,+optimized-nf2-segment-load-store,+optimized-nf3-segment-load-store,+optimized-nf4-segment-load-store,+optimized-nf5-segment-load-store,+optimized-nf6-segment-load-store,+optimized-nf7-segment-load-store,+optimized-nf8-segment-load-store -debug-only=loop-vectorize -disable-output < %s 2>&1 | FileCheck %s --check-prefix=OPT
; RUN: opt -passes=loop-vectorize -mtriple=riscv64 -mattr=+v,-optimized-nf2-segment-load-store,-optimized-nf3-segment-load-store,-optimized-nf4-segment-load-store,-optimized-nf5-segment-load-store,-optimized-nf6-segment-load-store,-optimized-nf7-segment-load-store,-optimized-nf8-segment-load-store -scalable-vectorization=off -debug-only=loop-vectorize -disable-output < %s 2>&1 | FileCheck %s --check-prefix=FIXED-NO-OPT
; RUN: opt -passes=loop-vectorize -mtriple=riscv64 -mattr=+v,+optimized-nf2-segment-load-store,+optimized-nf3-segment-load-store,+optimized-nf4-segment-load-store,+optimized-nf5-segment-load-store,+optimized-nf6-segment-load-store,+optimized-nf7-segment-load-store,+optimized-nf8-segment-load-store -scalable-vectorization=off -debug-only=loop-vectorize -disable-output < %s 2>&1 | FileCheck %s --check-prefix=FIXED-OPT
+; RUN: opt -passes=forceattrs,loop-vectorize -mtriple=riscv64 -mattr=+v -force-attribute=minsize -debug-only=loop-vectorize -disable-output < %s 2>&1 | FileCheck %s --check-prefix=MINSIZE
%i8.2 = type {i8, i8}
define void @i8_factor_2(ptr %data, i64 %n) {
@@ -55,6 +56,18 @@ define void @i8_factor_2(ptr %data, i64 %n) {
; FIXED-OPT: Cost of 8 for VF 32: INTERLEAVE-GROUP with factor 2, ir<%p0>
; FIXED-OPT: Cost of 8 for VF 32: INTERLEAVE-GROUP with factor 2, ir<%p0>
;
+; MINSIZE-LABEL: 'i8_factor_2'
+; MINSIZE: Cost of 1 for VF vscale x 1: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 1: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 2: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 2: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 4: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 4: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 8: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 8: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 16: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 16: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
+;
entry:
br label %for.body
for.body:
@@ -125,6 +138,18 @@ define void @i8_factor_3(ptr %data, i64 %n) {
; FIXED-OPT: Cost of 14 for VF 32: INTERLEAVE-GROUP with factor 3, ir<%p0>
; FIXED-OPT: Cost of 14 for VF 32: INTERLEAVE-GROUP with factor 3, ir<%p0>
;
+; MINSIZE-LABEL: 'i8_factor_3'
+; MINSIZE: Cost of 1 for VF vscale x 1: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 1: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 2: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 2: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 4: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 4: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 8: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 8: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 16: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 16: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
+;
entry:
br label %for.body
for.body:
@@ -199,6 +224,18 @@ define void @i8_factor_4(ptr %data, i64 %n) {
; FIXED-OPT: Cost of 16 for VF 32: INTERLEAVE-GROUP with factor 4, ir<%p0>
; FIXED-OPT: Cost of 16 for VF 32: INTERLEAVE-GROUP with factor 4, ir<%p0>
;
+; MINSIZE-LABEL: 'i8_factor_4'
+; MINSIZE: Cost of 1 for VF vscale x 1: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 1: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 2: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 2: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 4: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 4: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 8: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 8: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 16: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 16: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
+;
entry:
br label %for.body
for.body:
@@ -269,6 +306,18 @@ define void @i8_factor_5(ptr %data, i64 %n) {
; FIXED-OPT: Cost of 13 for VF 16: INTERLEAVE-GROUP with factor 5, ir<%p0>
; FIXED-OPT: Cost of 13 for VF 16: INTERLEAVE-GROUP with factor 5, ir<%p0>
;
+; MINSIZE-LABEL: 'i8_factor_5'
+; MINSIZE: Cost of 1 for VF vscale x 1: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 1: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 2: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 2: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 4: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 4: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 8: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 8: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 16: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 16: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
+;
entry:
br label %for.body
for.body:
@@ -343,6 +392,18 @@ define void @i8_factor_6(ptr %data, i64 %n) {
; FIXED-OPT: Cost of 14 for VF 16: INTERLEAVE-GROUP with factor 6, ir<%p0>
; FIXED-OPT: Cost of 14 for VF 16: INTERLEAVE-GROUP with factor 6, ir<%p0>
;
+; MINSIZE-LABEL: 'i8_factor_6'
+; MINSIZE: Cost of 1 for VF vscale x 1: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 1: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 2: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 2: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 4: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 4: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 8: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 8: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 16: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 16: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
+;
entry:
br label %for.body
for.body:
@@ -421,6 +482,18 @@ define void @i8_factor_7(ptr %data, i64 %n) {
; FIXED-OPT: Cost of 15 for VF 16: INTERLEAVE-GROUP with factor 7, ir<%p0>
; FIXED-OPT: Cost of 15 for VF 16: INTERLEAVE-GROUP with factor 7, ir<%p0>
;
+; MINSIZE-LABEL: 'i8_factor_7'
+; MINSIZE: Cost of 1 for VF vscale x 1: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 1: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 2: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 2: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 4: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 4: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 8: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 8: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 16: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 16: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
+;
entry:
br label %for.body
for.body:
@@ -503,6 +576,18 @@ define void @i8_factor_8(ptr %data, i64 %n) {
; FIXED-OPT: Cost of 16 for VF 16: INTERLEAVE-GROUP with factor 8, ir<%p0>
; FIXED-OPT: Cost of 16 for VF 16: INTERLEAVE-GROUP with factor 8, ir<%p0>
;
+; MINSIZE-LABEL: 'i8_factor_8'
+; MINSIZE: Cost of 1 for VF vscale x 1: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 1: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 2: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 2: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 4: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 4: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 8: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 8: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 16: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 1 for VF vscale x 16: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
+;
entry:
br label %for.body
for.body:
``````````
</details>
https://github.com/llvm/llvm-project/pull/207162
More information about the llvm-commits
mailing list