[llvm] [RISCV] Cost legal interleaved memory ops correctly for code size (PR #207162)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 2 04:58:54 PDT 2026
https://github.com/lukel97 updated https://github.com/llvm/llvm-project/pull/207162
>From bc931aa869cf381afb27ab4ebc1e5c31163024b0 Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Thu, 2 Jul 2026 17:44:57 +0800
Subject: [PATCH 1/3] Precommit tests
---
.../LoopVectorize/RISCV/interleaved-cost.ll | 77 +++++++++++++++++++
1 file changed, 77 insertions(+)
diff --git a/llvm/test/Transforms/LoopVectorize/RISCV/interleaved-cost.ll b/llvm/test/Transforms/LoopVectorize/RISCV/interleaved-cost.ll
index 62c73635e419e..cd65bf9e777ff 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 3 for VF vscale x 1: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 3 for VF vscale x 1: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 3 for VF vscale x 2: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 3 for VF vscale x 2: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 3 for VF vscale x 4: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 3 for VF vscale x 4: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 3 for VF vscale x 8: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 3 for VF vscale x 8: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 5 for VF vscale x 16: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 5 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 6 for VF vscale x 1: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 6 for VF vscale x 1: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 12 for VF vscale x 2: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 12 for VF vscale x 2: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 24 for VF vscale x 4: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 24 for VF vscale x 4: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 48 for VF vscale x 8: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 48 for VF vscale x 8: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 96 for VF vscale x 16: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 96 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 8 for VF vscale x 1: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 8 for VF vscale x 1: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 16 for VF vscale x 2: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 16 for VF vscale x 2: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 32 for VF vscale x 4: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 32 for VF vscale x 4: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 64 for VF vscale x 8: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 64 for VF vscale x 8: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 128 for VF vscale x 16: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 128 for VF vscale x 16: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
+;
entry:
br label %for.body
for.body:
@@ -269,6 +306,16 @@ 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 10 for VF vscale x 1: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 10 for VF vscale x 1: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 20 for VF vscale x 2: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 20 for VF vscale x 2: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 40 for VF vscale x 4: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 40 for VF vscale x 4: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 80 for VF vscale x 8: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 80 for VF vscale x 8: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
+;
entry:
br label %for.body
for.body:
@@ -343,6 +390,16 @@ 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 12 for VF vscale x 1: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 12 for VF vscale x 1: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 24 for VF vscale x 2: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 24 for VF vscale x 2: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 48 for VF vscale x 4: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 48 for VF vscale x 4: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 96 for VF vscale x 8: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 96 for VF vscale x 8: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
+;
entry:
br label %for.body
for.body:
@@ -421,6 +478,16 @@ 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 14 for VF vscale x 1: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 14 for VF vscale x 1: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 28 for VF vscale x 2: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 28 for VF vscale x 2: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 56 for VF vscale x 4: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 56 for VF vscale x 4: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 112 for VF vscale x 8: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 112 for VF vscale x 8: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
+;
entry:
br label %for.body
for.body:
@@ -503,6 +570,16 @@ 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 16 for VF vscale x 1: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 16 for VF vscale x 1: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 32 for VF vscale x 2: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 32 for VF vscale x 2: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 64 for VF vscale x 4: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 64 for VF vscale x 4: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 128 for VF vscale x 8: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 128 for VF vscale x 8: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
+;
entry:
br label %for.body
for.body:
>From d1260772a199b155aac05e21e0eaa1946780c516 Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Thu, 2 Jul 2026 17:46:14 +0800
Subject: [PATCH 2/3] [RISCV] Cost legal interleaved memory ops correctly for
code size
This doesn't yet handle interleaved memory ops with a factor > 8 or with a gap mask, that still needs to be handled below.
---
.../Target/RISCV/RISCVTargetTransformInfo.cpp | 3 +
.../LoopVectorize/RISCV/interleaved-cost.ll | 132 ++++++++++--------
2 files changed, 73 insertions(+), 62 deletions(-)
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 cd65bf9e777ff..435882cee52f1 100644
--- a/llvm/test/Transforms/LoopVectorize/RISCV/interleaved-cost.ll
+++ b/llvm/test/Transforms/LoopVectorize/RISCV/interleaved-cost.ll
@@ -57,16 +57,16 @@ define void @i8_factor_2(ptr %data, i64 %n) {
; FIXED-OPT: Cost of 8 for VF 32: INTERLEAVE-GROUP with factor 2, ir<%p0>
;
; MINSIZE-LABEL: 'i8_factor_2'
-; MINSIZE: Cost of 3 for VF vscale x 1: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 3 for VF vscale x 1: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 3 for VF vscale x 2: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 3 for VF vscale x 2: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 3 for VF vscale x 4: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 3 for VF vscale x 4: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 3 for VF vscale x 8: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 3 for VF vscale x 8: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 5 for VF vscale x 16: INTERLEAVE-GROUP with factor 2, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 5 for VF vscale x 16: 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 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
@@ -139,16 +139,16 @@ define void @i8_factor_3(ptr %data, i64 %n) {
; FIXED-OPT: Cost of 14 for VF 32: INTERLEAVE-GROUP with factor 3, ir<%p0>
;
; MINSIZE-LABEL: 'i8_factor_3'
-; MINSIZE: Cost of 6 for VF vscale x 1: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 6 for VF vscale x 1: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 12 for VF vscale x 2: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 12 for VF vscale x 2: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 24 for VF vscale x 4: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 24 for VF vscale x 4: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 48 for VF vscale x 8: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 48 for VF vscale x 8: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 96 for VF vscale x 16: INTERLEAVE-GROUP with factor 3, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 96 for VF vscale x 16: 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 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
@@ -225,16 +225,16 @@ define void @i8_factor_4(ptr %data, i64 %n) {
; FIXED-OPT: Cost of 16 for VF 32: INTERLEAVE-GROUP with factor 4, ir<%p0>
;
; MINSIZE-LABEL: 'i8_factor_4'
-; MINSIZE: Cost of 8 for VF vscale x 1: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 8 for VF vscale x 1: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 16 for VF vscale x 2: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 16 for VF vscale x 2: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 32 for VF vscale x 4: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 32 for VF vscale x 4: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 64 for VF vscale x 8: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 64 for VF vscale x 8: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 128 for VF vscale x 16: INTERLEAVE-GROUP with factor 4, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 128 for VF vscale x 16: 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 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
@@ -307,14 +307,16 @@ define void @i8_factor_5(ptr %data, i64 %n) {
; FIXED-OPT: Cost of 13 for VF 16: INTERLEAVE-GROUP with factor 5, ir<%p0>
;
; MINSIZE-LABEL: 'i8_factor_5'
-; MINSIZE: Cost of 10 for VF vscale x 1: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 10 for VF vscale x 1: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 20 for VF vscale x 2: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 20 for VF vscale x 2: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 40 for VF vscale x 4: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 40 for VF vscale x 4: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 80 for VF vscale x 8: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 80 for VF vscale x 8: 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 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
@@ -391,14 +393,16 @@ define void @i8_factor_6(ptr %data, i64 %n) {
; FIXED-OPT: Cost of 14 for VF 16: INTERLEAVE-GROUP with factor 6, ir<%p0>
;
; MINSIZE-LABEL: 'i8_factor_6'
-; MINSIZE: Cost of 12 for VF vscale x 1: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 12 for VF vscale x 1: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 24 for VF vscale x 2: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 24 for VF vscale x 2: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 48 for VF vscale x 4: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 48 for VF vscale x 4: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 96 for VF vscale x 8: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 96 for VF vscale x 8: 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 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
@@ -479,14 +483,16 @@ define void @i8_factor_7(ptr %data, i64 %n) {
; FIXED-OPT: Cost of 15 for VF 16: INTERLEAVE-GROUP with factor 7, ir<%p0>
;
; MINSIZE-LABEL: 'i8_factor_7'
-; MINSIZE: Cost of 14 for VF vscale x 1: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 14 for VF vscale x 1: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 28 for VF vscale x 2: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 28 for VF vscale x 2: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 56 for VF vscale x 4: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 56 for VF vscale x 4: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 112 for VF vscale x 8: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 112 for VF vscale x 8: 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 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
@@ -571,14 +577,16 @@ define void @i8_factor_8(ptr %data, i64 %n) {
; FIXED-OPT: Cost of 16 for VF 16: INTERLEAVE-GROUP with factor 8, ir<%p0>
;
; MINSIZE-LABEL: 'i8_factor_8'
-; MINSIZE: Cost of 16 for VF vscale x 1: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 16 for VF vscale x 1: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 32 for VF vscale x 2: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 32 for VF vscale x 2: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 64 for VF vscale x 4: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 64 for VF vscale x 4: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 128 for VF vscale x 8: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
-; MINSIZE: Cost of 128 for VF vscale x 8: 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 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
>From 2cea8453a8c3100d19ff6b8895ffedf7c395ad6d Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Thu, 2 Jul 2026 19:58:26 +0800
Subject: [PATCH 3/3] Multiply by legalization cost, in case of splitting
---
.../Target/RISCV/RISCVTargetTransformInfo.cpp | 2 +-
.../LoopVectorize/RISCV/interleaved-cost.ll | 16 ++++++++--------
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index b350ea1b9525e..888923fd1471b 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -1118,7 +1118,7 @@ InstructionCost RISCVTTIImpl::getInterleavedMemoryOpCost(
// Need to make sure type has't been scalarized
if (LT.second.isVector()) {
if (CostKind == TTI::TCK_CodeSize)
- return TTI::TCC_Basic;
+ return LT.first * TTI::TCC_Basic;
auto *SubVecTy =
VectorType::get(VTy->getElementType(),
diff --git a/llvm/test/Transforms/LoopVectorize/RISCV/interleaved-cost.ll b/llvm/test/Transforms/LoopVectorize/RISCV/interleaved-cost.ll
index 435882cee52f1..e8f98e6ead8b4 100644
--- a/llvm/test/Transforms/LoopVectorize/RISCV/interleaved-cost.ll
+++ b/llvm/test/Transforms/LoopVectorize/RISCV/interleaved-cost.ll
@@ -315,8 +315,8 @@ define void @i8_factor_5(ptr %data, i64 %n) {
; 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>
+; MINSIZE: Cost of 2 for VF vscale x 16: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 2 for VF vscale x 16: INTERLEAVE-GROUP with factor 5, ir<%p0>, vp<%evl>
;
entry:
br label %for.body
@@ -401,8 +401,8 @@ define void @i8_factor_6(ptr %data, i64 %n) {
; 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>
+; MINSIZE: Cost of 2 for VF vscale x 16: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 2 for VF vscale x 16: INTERLEAVE-GROUP with factor 6, ir<%p0>, vp<%evl>
;
entry:
br label %for.body
@@ -491,8 +491,8 @@ define void @i8_factor_7(ptr %data, i64 %n) {
; 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>
+; MINSIZE: Cost of 2 for VF vscale x 16: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 2 for VF vscale x 16: INTERLEAVE-GROUP with factor 7, ir<%p0>, vp<%evl>
;
entry:
br label %for.body
@@ -585,8 +585,8 @@ define void @i8_factor_8(ptr %data, i64 %n) {
; 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>
+; MINSIZE: Cost of 2 for VF vscale x 16: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
+; MINSIZE: Cost of 2 for VF vscale x 16: INTERLEAVE-GROUP with factor 8, ir<%p0>, vp<%evl>
;
entry:
br label %for.body
More information about the llvm-commits
mailing list