[llvm] [LV] Trim VFs that cause vector splitting when tail-folding with EVL (PR #222836)
Elvis Wang via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 20 23:56:27 PDT 2026
https://github.com/ElvisWang123 updated https://github.com/llvm/llvm-project/pull/222836
>From 159fb80c8be71bc4d64176b29ce6427c02495e13 Mon Sep 17 00:00:00 2001
From: Elvis Wang <elvis.wang at sifive.com>
Date: Sun, 20 Sep 2026 21:39:27 -0700
Subject: [PATCH 1/3] Precommit tests.
---
.../LoopVectorize/RISCV/partial-reduce.ll | 202 ++++++++++++++-
.../RISCV/reg-usage-maxbandwidth.ll | 235 +++++++++++++++++-
2 files changed, 428 insertions(+), 9 deletions(-)
diff --git a/llvm/test/Transforms/LoopVectorize/RISCV/partial-reduce.ll b/llvm/test/Transforms/LoopVectorize/RISCV/partial-reduce.ll
index 73b204a715a94..8bc65d1b8add3 100644
--- a/llvm/test/Transforms/LoopVectorize/RISCV/partial-reduce.ll
+++ b/llvm/test/Transforms/LoopVectorize/RISCV/partial-reduce.ll
@@ -1,5 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals none --version 6
; RUN: opt -passes=loop-vectorize -mtriple riscv64 -mattr=+v,+experimental-zvdot4a8i -S %s | FileCheck %s
+; RUN: opt -passes=loop-vectorize -vectorizer-maximize-bandwidth=true -mtriple riscv64 -mattr=+v,+experimental-zvdot4a8i -S %s | FileCheck %s --check-prefix=MAXBW
define i32 @partial_reduce_dotprod(ptr %a, ptr %b, ptr %c, ptr %d, i64 %N) #0 {
; CHECK-LABEL: define i32 @partial_reduce_dotprod(
@@ -33,6 +34,37 @@ define i32 @partial_reduce_dotprod(ptr %a, ptr %b, ptr %c, ptr %d, i64 %N) #0 {
; CHECK: [[EXIT]]:
; CHECK-NEXT: ret i32 [[TMP10]]
;
+; MAXBW-LABEL: define i32 @partial_reduce_dotprod(
+; MAXBW-SAME: ptr [[A:%.*]], ptr [[B:%.*]], ptr [[C:%.*]], ptr [[D:%.*]], i64 [[N:%.*]]) #[[ATTR0:[0-9]+]] {
+; MAXBW-NEXT: [[ENTRY:.*:]]
+; MAXBW-NEXT: br label %[[VECTOR_PH:.*]]
+; MAXBW: [[VECTOR_PH]]:
+; MAXBW-NEXT: br label %[[VECTOR_BODY:.*]]
+; MAXBW: [[VECTOR_BODY]]:
+; MAXBW-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[CURRENT_ITERATION_NEXT:%.*]], %[[VECTOR_BODY]] ]
+; MAXBW-NEXT: [[VEC_PHI:%.*]] = phi <vscale x 4 x i32> [ zeroinitializer, %[[VECTOR_PH]] ], [ [[PARTIAL_REDUCE:%.*]], %[[VECTOR_BODY]] ]
+; MAXBW-NEXT: [[AVL:%.*]] = phi i64 [ [[N]], %[[VECTOR_PH]] ], [ [[AVL_NEXT:%.*]], %[[VECTOR_BODY]] ]
+; MAXBW-NEXT: [[TMP0:%.*]] = call i32 @llvm.experimental.get.vector.length.i64(i64 [[AVL]], i32 16, i1 true)
+; MAXBW-NEXT: [[TMP1:%.*]] = getelementptr inbounds nuw i8, ptr [[A]], i64 [[INDEX]]
+; MAXBW-NEXT: [[VP_OP_LOAD:%.*]] = call <vscale x 16 x i8> @llvm.vp.load.nxv16i8.p0(ptr align 1 [[TMP1]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP0]])
+; MAXBW-NEXT: [[TMP2:%.*]] = getelementptr inbounds nuw i8, ptr [[B]], i64 [[INDEX]]
+; MAXBW-NEXT: [[VP_OP_LOAD1:%.*]] = call <vscale x 16 x i8> @llvm.vp.load.nxv16i8.p0(ptr align 1 [[TMP2]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP0]])
+; MAXBW-NEXT: [[TMP3:%.*]] = sext <vscale x 16 x i8> [[VP_OP_LOAD]] to <vscale x 16 x i32>
+; MAXBW-NEXT: [[TMP4:%.*]] = sext <vscale x 16 x i8> [[VP_OP_LOAD1]] to <vscale x 16 x i32>
+; MAXBW-NEXT: [[TMP5:%.*]] = mul <vscale x 16 x i32> [[TMP3]], [[TMP4]]
+; MAXBW-NEXT: [[TMP6:%.*]] = call <vscale x 16 x i32> @llvm.vp.merge.nxv16i32(<vscale x 16 x i1> splat (i1 true), <vscale x 16 x i32> [[TMP5]], <vscale x 16 x i32> zeroinitializer, i32 [[TMP0]])
+; MAXBW-NEXT: [[PARTIAL_REDUCE]] = call <vscale x 4 x i32> @llvm.vector.partial.reduce.add.nxv4i32.nxv16i32(<vscale x 4 x i32> [[VEC_PHI]], <vscale x 16 x i32> [[TMP6]])
+; MAXBW-NEXT: [[TMP7:%.*]] = zext i32 [[TMP0]] to i64
+; MAXBW-NEXT: [[CURRENT_ITERATION_NEXT]] = add i64 [[TMP7]], [[INDEX]]
+; MAXBW-NEXT: [[AVL_NEXT]] = sub nuw i64 [[AVL]], [[TMP7]]
+; MAXBW-NEXT: [[TMP8:%.*]] = icmp eq i64 [[AVL_NEXT]], 0
+; MAXBW-NEXT: br i1 [[TMP8]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
+; MAXBW: [[MIDDLE_BLOCK]]:
+; MAXBW-NEXT: [[TMP9:%.*]] = call i32 @llvm.vector.reduce.add.nxv4i32(<vscale x 4 x i32> [[PARTIAL_REDUCE]])
+; MAXBW-NEXT: br label %[[EXIT:.*]]
+; MAXBW: [[EXIT]]:
+; MAXBW-NEXT: ret i32 [[TMP9]]
+;
entry:
br label %loop
@@ -55,6 +87,91 @@ exit:
ret i32 %add.1
}
+define i64 @partial_reduce_dotprod_i64(ptr %a, ptr %b, ptr %c, ptr %d, i64 %N) #0 {
+; CHECK-LABEL: define i64 @partial_reduce_dotprod_i64(
+; CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]], ptr [[C:%.*]], ptr [[D:%.*]], i64 [[N:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: br label %[[VECTOR_PH:.*]]
+; CHECK: [[VECTOR_PH]]:
+; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
+; CHECK: [[VECTOR_BODY]]:
+; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[CURRENT_ITERATION_NEXT:%.*]], %[[VECTOR_BODY]] ]
+; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <vscale x 2 x i64> [ zeroinitializer, %[[VECTOR_PH]] ], [ [[TMP7:%.*]], %[[VECTOR_BODY]] ]
+; CHECK-NEXT: [[AVL:%.*]] = phi i64 [ [[N]], %[[VECTOR_PH]] ], [ [[AVL_NEXT:%.*]], %[[VECTOR_BODY]] ]
+; CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.experimental.get.vector.length.i64(i64 [[AVL]], i32 2, i1 true)
+; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds nuw i8, ptr [[A]], i64 [[INDEX]]
+; CHECK-NEXT: [[VP_OP_LOAD:%.*]] = call <vscale x 2 x i8> @llvm.vp.load.nxv2i8.p0(ptr align 1 [[TMP1]], <vscale x 2 x i1> splat (i1 true), i32 [[TMP0]])
+; CHECK-NEXT: [[TMP2:%.*]] = sext <vscale x 2 x i8> [[VP_OP_LOAD]] to <vscale x 2 x i64>
+; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds nuw i8, ptr [[B]], i64 [[INDEX]]
+; CHECK-NEXT: [[VP_OP_LOAD1:%.*]] = call <vscale x 2 x i8> @llvm.vp.load.nxv2i8.p0(ptr align 1 [[TMP3]], <vscale x 2 x i1> splat (i1 true), i32 [[TMP0]])
+; CHECK-NEXT: [[TMP4:%.*]] = sext <vscale x 2 x i8> [[VP_OP_LOAD1]] to <vscale x 2 x i64>
+; CHECK-NEXT: [[TMP5:%.*]] = mul <vscale x 2 x i64> [[TMP2]], [[TMP4]]
+; CHECK-NEXT: [[TMP6:%.*]] = add <vscale x 2 x i64> [[TMP5]], [[VEC_PHI]]
+; CHECK-NEXT: [[TMP7]] = call <vscale x 2 x i64> @llvm.vp.merge.nxv2i64(<vscale x 2 x i1> splat (i1 true), <vscale x 2 x i64> [[TMP6]], <vscale x 2 x i64> [[VEC_PHI]], i32 [[TMP0]])
+; CHECK-NEXT: [[TMP8:%.*]] = zext i32 [[TMP0]] to i64
+; CHECK-NEXT: [[CURRENT_ITERATION_NEXT]] = add i64 [[TMP8]], [[INDEX]]
+; CHECK-NEXT: [[AVL_NEXT]] = sub nuw i64 [[AVL]], [[TMP8]]
+; CHECK-NEXT: [[TMP9:%.*]] = icmp eq i64 [[AVL_NEXT]], 0
+; CHECK-NEXT: br i1 [[TMP9]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]
+; CHECK: [[MIDDLE_BLOCK]]:
+; CHECK-NEXT: [[TMP10:%.*]] = call i64 @llvm.vector.reduce.add.nxv2i64(<vscale x 2 x i64> [[TMP7]])
+; CHECK-NEXT: br label %[[EXIT:.*]]
+; CHECK: [[EXIT]]:
+; CHECK-NEXT: ret i64 [[TMP10]]
+;
+; MAXBW-LABEL: define i64 @partial_reduce_dotprod_i64(
+; MAXBW-SAME: ptr [[A:%.*]], ptr [[B:%.*]], ptr [[C:%.*]], ptr [[D:%.*]], i64 [[N:%.*]]) #[[ATTR0]] {
+; MAXBW-NEXT: [[ENTRY:.*:]]
+; MAXBW-NEXT: br label %[[VECTOR_PH:.*]]
+; MAXBW: [[VECTOR_PH]]:
+; MAXBW-NEXT: br label %[[VECTOR_BODY:.*]]
+; MAXBW: [[VECTOR_BODY]]:
+; MAXBW-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[CURRENT_ITERATION_NEXT:%.*]], %[[VECTOR_BODY]] ]
+; MAXBW-NEXT: [[VEC_PHI:%.*]] = phi <vscale x 2 x i64> [ zeroinitializer, %[[VECTOR_PH]] ], [ [[PARTIAL_REDUCE:%.*]], %[[VECTOR_BODY]] ]
+; MAXBW-NEXT: [[AVL:%.*]] = phi i64 [ [[N]], %[[VECTOR_PH]] ], [ [[AVL_NEXT:%.*]], %[[VECTOR_BODY]] ]
+; MAXBW-NEXT: [[TMP0:%.*]] = call i32 @llvm.experimental.get.vector.length.i64(i64 [[AVL]], i32 16, i1 true)
+; MAXBW-NEXT: [[TMP1:%.*]] = getelementptr inbounds nuw i8, ptr [[A]], i64 [[INDEX]]
+; MAXBW-NEXT: [[VP_OP_LOAD:%.*]] = call <vscale x 16 x i8> @llvm.vp.load.nxv16i8.p0(ptr align 1 [[TMP1]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP0]])
+; MAXBW-NEXT: [[TMP2:%.*]] = getelementptr inbounds nuw i8, ptr [[B]], i64 [[INDEX]]
+; MAXBW-NEXT: [[VP_OP_LOAD1:%.*]] = call <vscale x 16 x i8> @llvm.vp.load.nxv16i8.p0(ptr align 1 [[TMP2]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP0]])
+; MAXBW-NEXT: [[TMP3:%.*]] = sext <vscale x 16 x i8> [[VP_OP_LOAD]] to <vscale x 16 x i64>
+; MAXBW-NEXT: [[TMP4:%.*]] = sext <vscale x 16 x i8> [[VP_OP_LOAD1]] to <vscale x 16 x i64>
+; MAXBW-NEXT: [[TMP5:%.*]] = mul <vscale x 16 x i64> [[TMP3]], [[TMP4]]
+; MAXBW-NEXT: [[TMP6:%.*]] = call <vscale x 16 x i64> @llvm.vp.merge.nxv16i64(<vscale x 16 x i1> splat (i1 true), <vscale x 16 x i64> [[TMP5]], <vscale x 16 x i64> zeroinitializer, i32 [[TMP0]])
+; MAXBW-NEXT: [[PARTIAL_REDUCE]] = call <vscale x 2 x i64> @llvm.vector.partial.reduce.add.nxv2i64.nxv16i64(<vscale x 2 x i64> [[VEC_PHI]], <vscale x 16 x i64> [[TMP6]])
+; MAXBW-NEXT: [[TMP7:%.*]] = zext i32 [[TMP0]] to i64
+; MAXBW-NEXT: [[CURRENT_ITERATION_NEXT]] = add i64 [[TMP7]], [[INDEX]]
+; MAXBW-NEXT: [[AVL_NEXT]] = sub nuw i64 [[AVL]], [[TMP7]]
+; MAXBW-NEXT: [[TMP8:%.*]] = icmp eq i64 [[AVL_NEXT]], 0
+; MAXBW-NEXT: br i1 [[TMP8]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]
+; MAXBW: [[MIDDLE_BLOCK]]:
+; MAXBW-NEXT: [[TMP9:%.*]] = call i64 @llvm.vector.reduce.add.nxv2i64(<vscale x 2 x i64> [[PARTIAL_REDUCE]])
+; MAXBW-NEXT: br label %[[EXIT:.*]]
+; MAXBW: [[EXIT]]:
+; MAXBW-NEXT: ret i64 [[TMP9]]
+;
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+ %accum = phi i64 [ 0, %entry ], [ %add.1, %loop ]
+ %gep.a = getelementptr inbounds nuw i8, ptr %a, i64 %iv
+ %load.a = load i8, ptr %gep.a, align 1
+ %ext.a = sext i8 %load.a to i64
+ %gep.b = getelementptr inbounds nuw i8, ptr %b, i64 %iv
+ %load.b = load i8, ptr %gep.b, align 1
+ %ext.b = sext i8 %load.b to i64
+ %mul.1 = mul i64 %ext.a, %ext.b
+ %add.1 = add i64 %mul.1, %accum
+ %iv.next = add nuw nsw i64 %iv, 1
+ %exitcond.not = icmp eq i64 %iv.next, %N
+ br i1 %exitcond.not, label %exit, label %loop
+
+exit:
+ ret i64 %add.1
+}
+
define i32 @chained_partial_reduce_dotprod(ptr %a, ptr %b, ptr %c, ptr %d, i64 %N) #0 {
; CHECK-LABEL: define i32 @chained_partial_reduce_dotprod(
; CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]], ptr [[C:%.*]], ptr [[D:%.*]], i64 [[N:%.*]]) #[[ATTR0]] {
@@ -89,13 +206,53 @@ define i32 @chained_partial_reduce_dotprod(ptr %a, ptr %b, ptr %c, ptr %d, i64 %
; CHECK-NEXT: [[CURRENT_ITERATION_NEXT]] = add i64 [[TMP14]], [[INDEX]]
; CHECK-NEXT: [[AVL_NEXT]] = sub nuw i64 [[AVL]], [[TMP14]]
; CHECK-NEXT: [[TMP16:%.*]] = icmp eq i64 [[AVL_NEXT]], 0
-; CHECK-NEXT: br i1 [[TMP16]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]
+; CHECK-NEXT: br i1 [[TMP16]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
; CHECK: [[MIDDLE_BLOCK]]:
; CHECK-NEXT: [[TMP15:%.*]] = call i32 @llvm.vector.reduce.add.nxv1i32(<vscale x 1 x i32> [[PARTIAL_REDUCE4]])
; CHECK-NEXT: br label %[[EXIT:.*]]
; CHECK: [[EXIT]]:
; CHECK-NEXT: ret i32 [[TMP15]]
;
+; MAXBW-LABEL: define i32 @chained_partial_reduce_dotprod(
+; MAXBW-SAME: ptr [[A:%.*]], ptr [[B:%.*]], ptr [[C:%.*]], ptr [[D:%.*]], i64 [[N:%.*]]) #[[ATTR0]] {
+; MAXBW-NEXT: [[ENTRY:.*:]]
+; MAXBW-NEXT: br label %[[VECTOR_PH:.*]]
+; MAXBW: [[VECTOR_PH]]:
+; MAXBW-NEXT: br label %[[VECTOR_BODY:.*]]
+; MAXBW: [[VECTOR_BODY]]:
+; MAXBW-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[CURRENT_ITERATION_NEXT:%.*]], %[[VECTOR_BODY]] ]
+; MAXBW-NEXT: [[VEC_PHI:%.*]] = phi <vscale x 4 x i32> [ zeroinitializer, %[[VECTOR_PH]] ], [ [[PARTIAL_REDUCE4:%.*]], %[[VECTOR_BODY]] ]
+; MAXBW-NEXT: [[AVL:%.*]] = phi i64 [ [[N]], %[[VECTOR_PH]] ], [ [[AVL_NEXT:%.*]], %[[VECTOR_BODY]] ]
+; MAXBW-NEXT: [[TMP0:%.*]] = call i32 @llvm.experimental.get.vector.length.i64(i64 [[AVL]], i32 16, i1 true)
+; MAXBW-NEXT: [[TMP1:%.*]] = getelementptr inbounds nuw i8, ptr [[A]], i64 [[INDEX]]
+; MAXBW-NEXT: [[VP_OP_LOAD:%.*]] = call <vscale x 16 x i8> @llvm.vp.load.nxv16i8.p0(ptr align 1 [[TMP1]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP0]])
+; MAXBW-NEXT: [[TMP2:%.*]] = getelementptr inbounds nuw i8, ptr [[B]], i64 [[INDEX]]
+; MAXBW-NEXT: [[VP_OP_LOAD1:%.*]] = call <vscale x 16 x i8> @llvm.vp.load.nxv16i8.p0(ptr align 1 [[TMP2]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP0]])
+; MAXBW-NEXT: [[TMP3:%.*]] = sext <vscale x 16 x i8> [[VP_OP_LOAD]] to <vscale x 16 x i32>
+; MAXBW-NEXT: [[TMP4:%.*]] = sext <vscale x 16 x i8> [[VP_OP_LOAD1]] to <vscale x 16 x i32>
+; MAXBW-NEXT: [[TMP5:%.*]] = mul <vscale x 16 x i32> [[TMP3]], [[TMP4]]
+; MAXBW-NEXT: [[TMP6:%.*]] = call <vscale x 16 x i32> @llvm.vp.merge.nxv16i32(<vscale x 16 x i1> splat (i1 true), <vscale x 16 x i32> [[TMP5]], <vscale x 16 x i32> zeroinitializer, i32 [[TMP0]])
+; MAXBW-NEXT: [[PARTIAL_REDUCE:%.*]] = call <vscale x 4 x i32> @llvm.vector.partial.reduce.add.nxv4i32.nxv16i32(<vscale x 4 x i32> [[VEC_PHI]], <vscale x 16 x i32> [[TMP6]])
+; MAXBW-NEXT: [[TMP7:%.*]] = getelementptr inbounds nuw i8, ptr [[C]], i64 [[INDEX]]
+; MAXBW-NEXT: [[VP_OP_LOAD2:%.*]] = call <vscale x 16 x i8> @llvm.vp.load.nxv16i8.p0(ptr align 1 [[TMP7]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP0]])
+; MAXBW-NEXT: [[TMP8:%.*]] = getelementptr inbounds nuw i8, ptr [[D]], i64 [[INDEX]]
+; MAXBW-NEXT: [[VP_OP_LOAD3:%.*]] = call <vscale x 16 x i8> @llvm.vp.load.nxv16i8.p0(ptr align 1 [[TMP8]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP0]])
+; MAXBW-NEXT: [[TMP9:%.*]] = sext <vscale x 16 x i8> [[VP_OP_LOAD2]] to <vscale x 16 x i32>
+; MAXBW-NEXT: [[TMP10:%.*]] = sext <vscale x 16 x i8> [[VP_OP_LOAD3]] to <vscale x 16 x i32>
+; MAXBW-NEXT: [[TMP11:%.*]] = mul <vscale x 16 x i32> [[TMP9]], [[TMP10]]
+; MAXBW-NEXT: [[TMP12:%.*]] = call <vscale x 16 x i32> @llvm.vp.merge.nxv16i32(<vscale x 16 x i1> splat (i1 true), <vscale x 16 x i32> [[TMP11]], <vscale x 16 x i32> zeroinitializer, i32 [[TMP0]])
+; MAXBW-NEXT: [[PARTIAL_REDUCE4]] = call <vscale x 4 x i32> @llvm.vector.partial.reduce.add.nxv4i32.nxv16i32(<vscale x 4 x i32> [[PARTIAL_REDUCE]], <vscale x 16 x i32> [[TMP12]])
+; MAXBW-NEXT: [[TMP13:%.*]] = zext i32 [[TMP0]] to i64
+; MAXBW-NEXT: [[CURRENT_ITERATION_NEXT]] = add i64 [[TMP13]], [[INDEX]]
+; MAXBW-NEXT: [[AVL_NEXT]] = sub nuw i64 [[AVL]], [[TMP13]]
+; MAXBW-NEXT: [[TMP14:%.*]] = icmp eq i64 [[AVL_NEXT]], 0
+; MAXBW-NEXT: br i1 [[TMP14]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
+; MAXBW: [[MIDDLE_BLOCK]]:
+; MAXBW-NEXT: [[TMP15:%.*]] = call i32 @llvm.vector.reduce.add.nxv4i32(<vscale x 4 x i32> [[PARTIAL_REDUCE4]])
+; MAXBW-NEXT: br label %[[EXIT:.*]]
+; MAXBW: [[EXIT]]:
+; MAXBW-NEXT: ret i32 [[TMP15]]
+;
entry:
br label %loop
@@ -163,13 +320,54 @@ define i32 @chained_reduce_iv_derived_first_link(ptr %c, ptr %d, i64 %N) #0 {
; CHECK-NEXT: [[AVL_NEXT]] = sub nuw i64 [[AVL]], [[TMP2]]
; CHECK-NEXT: [[VEC_IND_NEXT]] = add <vscale x 4 x i8> [[VEC_IND]], [[BROADCAST_SPLAT]]
; CHECK-NEXT: [[TMP15:%.*]] = icmp eq i64 [[AVL_NEXT]], 0
-; CHECK-NEXT: br i1 [[TMP15]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
+; CHECK-NEXT: br i1 [[TMP15]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP5:![0-9]+]]
; CHECK: [[MIDDLE_BLOCK]]:
; CHECK-NEXT: [[TMP14:%.*]] = call i32 @llvm.vector.reduce.add.nxv1i32(<vscale x 1 x i32> [[PARTIAL_REDUCE2]])
; CHECK-NEXT: br label %[[EXIT:.*]]
; CHECK: [[EXIT]]:
; CHECK-NEXT: ret i32 [[TMP14]]
;
+; MAXBW-LABEL: define i32 @chained_reduce_iv_derived_first_link(
+; MAXBW-SAME: ptr [[C:%.*]], ptr [[D:%.*]], i64 [[N:%.*]]) #[[ATTR0]] {
+; MAXBW-NEXT: [[ENTRY:.*:]]
+; MAXBW-NEXT: br label %[[VECTOR_PH:.*]]
+; MAXBW: [[VECTOR_PH]]:
+; MAXBW-NEXT: [[TMP0:%.*]] = call <vscale x 16 x i8> @llvm.stepvector.nxv16i8()
+; MAXBW-NEXT: br label %[[VECTOR_BODY:.*]]
+; MAXBW: [[VECTOR_BODY]]:
+; MAXBW-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[CURRENT_ITERATION_NEXT:%.*]], %[[VECTOR_BODY]] ]
+; MAXBW-NEXT: [[VEC_PHI:%.*]] = phi <vscale x 4 x i32> [ zeroinitializer, %[[VECTOR_PH]] ], [ [[PARTIAL_REDUCE2:%.*]], %[[VECTOR_BODY]] ]
+; MAXBW-NEXT: [[VEC_IND:%.*]] = phi <vscale x 16 x i8> [ [[TMP0]], %[[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], %[[VECTOR_BODY]] ]
+; MAXBW-NEXT: [[AVL:%.*]] = phi i64 [ [[N]], %[[VECTOR_PH]] ], [ [[AVL_NEXT:%.*]], %[[VECTOR_BODY]] ]
+; MAXBW-NEXT: [[TMP1:%.*]] = call i32 @llvm.experimental.get.vector.length.i64(i64 [[AVL]], i32 16, i1 true)
+; MAXBW-NEXT: [[TMP2:%.*]] = zext i32 [[TMP1]] to i64
+; MAXBW-NEXT: [[TMP3:%.*]] = trunc i64 [[TMP2]] to i8
+; MAXBW-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 16 x i8> poison, i8 [[TMP3]], i64 0
+; MAXBW-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 16 x i8> [[BROADCAST_SPLATINSERT]], <vscale x 16 x i8> poison, <vscale x 16 x i32> zeroinitializer
+; MAXBW-NEXT: [[TMP4:%.*]] = sext <vscale x 16 x i8> [[VEC_IND]] to <vscale x 16 x i32>
+; MAXBW-NEXT: [[TMP5:%.*]] = mul <vscale x 16 x i32> [[TMP4]], [[TMP4]]
+; MAXBW-NEXT: [[TMP6:%.*]] = call <vscale x 16 x i32> @llvm.vp.merge.nxv16i32(<vscale x 16 x i1> splat (i1 true), <vscale x 16 x i32> [[TMP5]], <vscale x 16 x i32> zeroinitializer, i32 [[TMP1]])
+; MAXBW-NEXT: [[PARTIAL_REDUCE:%.*]] = call <vscale x 4 x i32> @llvm.vector.partial.reduce.add.nxv4i32.nxv16i32(<vscale x 4 x i32> [[VEC_PHI]], <vscale x 16 x i32> [[TMP6]])
+; MAXBW-NEXT: [[TMP7:%.*]] = getelementptr inbounds nuw i8, ptr [[C]], i64 [[INDEX]]
+; MAXBW-NEXT: [[VP_OP_LOAD:%.*]] = call <vscale x 16 x i8> @llvm.vp.load.nxv16i8.p0(ptr align 1 [[TMP7]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP1]])
+; MAXBW-NEXT: [[TMP8:%.*]] = getelementptr inbounds nuw i8, ptr [[D]], i64 [[INDEX]]
+; MAXBW-NEXT: [[VP_OP_LOAD1:%.*]] = call <vscale x 16 x i8> @llvm.vp.load.nxv16i8.p0(ptr align 1 [[TMP8]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP1]])
+; MAXBW-NEXT: [[TMP9:%.*]] = sext <vscale x 16 x i8> [[VP_OP_LOAD]] to <vscale x 16 x i32>
+; MAXBW-NEXT: [[TMP10:%.*]] = sext <vscale x 16 x i8> [[VP_OP_LOAD1]] to <vscale x 16 x i32>
+; MAXBW-NEXT: [[TMP11:%.*]] = mul <vscale x 16 x i32> [[TMP9]], [[TMP10]]
+; MAXBW-NEXT: [[TMP12:%.*]] = call <vscale x 16 x i32> @llvm.vp.merge.nxv16i32(<vscale x 16 x i1> splat (i1 true), <vscale x 16 x i32> [[TMP11]], <vscale x 16 x i32> zeroinitializer, i32 [[TMP1]])
+; MAXBW-NEXT: [[PARTIAL_REDUCE2]] = call <vscale x 4 x i32> @llvm.vector.partial.reduce.add.nxv4i32.nxv16i32(<vscale x 4 x i32> [[PARTIAL_REDUCE]], <vscale x 16 x i32> [[TMP12]])
+; MAXBW-NEXT: [[CURRENT_ITERATION_NEXT]] = add i64 [[TMP2]], [[INDEX]]
+; MAXBW-NEXT: [[AVL_NEXT]] = sub nuw i64 [[AVL]], [[TMP2]]
+; MAXBW-NEXT: [[VEC_IND_NEXT]] = add <vscale x 16 x i8> [[VEC_IND]], [[BROADCAST_SPLAT]]
+; MAXBW-NEXT: [[TMP13:%.*]] = icmp eq i64 [[AVL_NEXT]], 0
+; MAXBW-NEXT: br i1 [[TMP13]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP5:![0-9]+]]
+; MAXBW: [[MIDDLE_BLOCK]]:
+; MAXBW-NEXT: [[TMP14:%.*]] = call i32 @llvm.vector.reduce.add.nxv4i32(<vscale x 4 x i32> [[PARTIAL_REDUCE2]])
+; MAXBW-NEXT: br label %[[EXIT:.*]]
+; MAXBW: [[EXIT]]:
+; MAXBW-NEXT: ret i32 [[TMP14]]
+;
entry:
br label %for.body
diff --git a/llvm/test/Transforms/LoopVectorize/RISCV/reg-usage-maxbandwidth.ll b/llvm/test/Transforms/LoopVectorize/RISCV/reg-usage-maxbandwidth.ll
index 41f1a9b45b7ff..a0667eb811a52 100644
--- a/llvm/test/Transforms/LoopVectorize/RISCV/reg-usage-maxbandwidth.ll
+++ b/llvm/test/Transforms/LoopVectorize/RISCV/reg-usage-maxbandwidth.ll
@@ -2,14 +2,49 @@
; REQUIRES: asserts
; RUN: opt -passes=loop-vectorize -mtriple riscv64 -mattr=+v -vectorizer-maximize-bandwidth -debug-only=loop-vectorize,vplan -disable-output -S < %s 2>&1 | FileCheck %s --check-prefixes=CHECK-REGS-VP
+; Check LV doesn't choose VF that needs to split.
+
define i32 @dotp(ptr %a, ptr %b) {
-; CHECK-REGS-VP: LV(REG): VF = vscale x 16
-; CHECK-REGS-VP-NEXT: LV(REG): Found max usage: 2 item
-; CHECK-REGS-VP-NEXT: LV(REG): RegisterClass: RISCV::GPRRC, 6 registers
-; CHECK-REGS-VP-NEXT: LV(REG): RegisterClass: RISCV::VRRC, 24 registers
-; CHECK-REGS-VP-NEXT: LV(REG): Found invariant usage: 1 item
-; CHECK-REGS-VP-NEXT: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
-; CHECK-REGS-VP: LV: Selecting VF: vscale x 16.
+; CHECK-REGS-VP-LABEL: 'dotp'
+; CHECK-REGS-VP: LV(REG): Calculating max register usage:
+; CHECK-REGS-VP: LV(REG): VF = 1
+; CHECK-REGS-VP: LV(REG): Found max usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 5 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): Calculating max register usage:
+; CHECK-REGS-VP: LV(REG): VF = vscale x 1
+; CHECK-REGS-VP: LV(REG): Found max usage: 2 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 6 registers
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::VRRC, 3 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): VF = vscale x 2
+; CHECK-REGS-VP: LV(REG): Found max usage: 2 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 6 registers
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::VRRC, 3 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): VF = vscale x 4
+; CHECK-REGS-VP: LV(REG): Found max usage: 2 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 6 registers
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::VRRC, 6 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): VF = vscale x 8
+; CHECK-REGS-VP: LV(REG): Found max usage: 2 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 6 registers
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::VRRC, 12 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): VF = vscale x 16
+; CHECK-REGS-VP: LV(REG): Found max usage: 2 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 6 registers
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::VRRC, 24 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV: Selecting VF: vscale x 16.
+;
entry:
br label %for.body
@@ -32,3 +67,189 @@ for.body:
for.exit:
ret i32 %add
}
+
+define void @mix_type_i8_i16(ptr %a, ptr %b, ptr %c, ptr %d) {
+; CHECK-REGS-VP-LABEL: 'mix_type_i8_i16'
+; CHECK-REGS-VP: LV(REG): Calculating max register usage:
+; CHECK-REGS-VP: LV(REG): VF = 1
+; CHECK-REGS-VP: LV(REG): Found max usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 4 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): Calculating max register usage:
+; CHECK-REGS-VP: LV(REG): VF = vscale x 1
+; CHECK-REGS-VP: LV(REG): Found max usage: 2 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 6 registers
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::VRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): VF = vscale x 2
+; CHECK-REGS-VP: LV(REG): Found max usage: 2 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 6 registers
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::VRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): VF = vscale x 4
+; CHECK-REGS-VP: LV(REG): Found max usage: 2 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 6 registers
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::VRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): VF = vscale x 8
+; CHECK-REGS-VP: LV(REG): Found max usage: 2 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 6 registers
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::VRRC, 2 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): VF = vscale x 16
+; CHECK-REGS-VP: LV(REG): Found max usage: 2 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 6 registers
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::VRRC, 4 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV: Selecting VF: vscale x 16.
+;
+entry:
+ br label %for.body
+
+for.body:
+ %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
+ %gep.a = getelementptr i8, ptr %a, i64 %iv
+ %load.a = load i8, ptr %gep.a, align 1
+ %gep.b = getelementptr i8, ptr %b, i64 %iv
+ store i8 %load.a ,ptr %gep.b, align 1
+ %gep.c = getelementptr i16, ptr %c, i64 %iv
+ %load.c = load i16, ptr %gep.c, align 2
+ %gep.d = getelementptr i16, ptr %d, i64 %iv
+ store i16 %load.c, ptr %gep.d, align 2
+ %iv.next = add i64 %iv, 1
+ %exitcond.not = icmp eq i64 %iv.next, 1024
+ br i1 %exitcond.not, label %for.exit, label %for.body
+
+for.exit:
+ ret void
+}
+
+define void @mix_type_i8_i32(ptr %a, ptr %b, ptr %c, ptr %d) {
+; CHECK-REGS-VP-LABEL: 'mix_type_i8_i32'
+; CHECK-REGS-VP: LV(REG): Calculating max register usage:
+; CHECK-REGS-VP: LV(REG): VF = 1
+; CHECK-REGS-VP: LV(REG): Found max usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 4 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): Calculating max register usage:
+; CHECK-REGS-VP: LV(REG): VF = vscale x 1
+; CHECK-REGS-VP: LV(REG): Found max usage: 2 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 6 registers
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::VRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): VF = vscale x 2
+; CHECK-REGS-VP: LV(REG): Found max usage: 2 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 6 registers
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::VRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): VF = vscale x 4
+; CHECK-REGS-VP: LV(REG): Found max usage: 2 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 6 registers
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::VRRC, 2 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): VF = vscale x 8
+; CHECK-REGS-VP: LV(REG): Found max usage: 2 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 6 registers
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::VRRC, 4 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): VF = vscale x 16
+; CHECK-REGS-VP: LV(REG): Found max usage: 2 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 6 registers
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::VRRC, 8 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV: Selecting VF: vscale x 16.
+;
+entry:
+ br label %for.body
+
+for.body:
+ %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
+ %gep.a = getelementptr i8, ptr %a, i64 %iv
+ %load.a = load i8, ptr %gep.a, align 1
+ %gep.b = getelementptr i8, ptr %b, i64 %iv
+ store i8 %load.a ,ptr %gep.b, align 1
+ %gep.c = getelementptr i32, ptr %c, i64 %iv
+ %load.c = load i32, ptr %gep.c, align 4
+ %gep.d = getelementptr i32, ptr %d, i64 %iv
+ store i32 %load.c, ptr %gep.d, align 4
+ %iv.next = add i64 %iv, 1
+ %exitcond.not = icmp eq i64 %iv.next, 1024
+ br i1 %exitcond.not, label %for.exit, label %for.body
+
+for.exit:
+ ret void
+}
+
+define void @mix_type_i8_i64(ptr %a, ptr %b, ptr %c, ptr %d) {
+; CHECK-REGS-VP-LABEL: 'mix_type_i8_i64'
+; CHECK-REGS-VP: LV(REG): Calculating max register usage:
+; CHECK-REGS-VP: LV(REG): VF = 1
+; CHECK-REGS-VP: LV(REG): Found max usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 4 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): Calculating max register usage:
+; CHECK-REGS-VP: LV(REG): VF = vscale x 1
+; CHECK-REGS-VP: LV(REG): Found max usage: 2 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 6 registers
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::VRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): VF = vscale x 2
+; CHECK-REGS-VP: LV(REG): Found max usage: 2 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 6 registers
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::VRRC, 2 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): VF = vscale x 4
+; CHECK-REGS-VP: LV(REG): Found max usage: 2 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 6 registers
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::VRRC, 4 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): VF = vscale x 8
+; CHECK-REGS-VP: LV(REG): Found max usage: 2 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 6 registers
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::VRRC, 8 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV(REG): VF = vscale x 16
+; CHECK-REGS-VP: LV(REG): Found max usage: 2 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 6 registers
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::VRRC, 16 registers
+; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
+; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
+; CHECK-REGS-VP: LV: Selecting VF: vscale x 16.
+;
+entry:
+ br label %for.body
+
+for.body:
+ %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
+ %gep.a = getelementptr i8, ptr %a, i64 %iv
+ %load.a = load i8, ptr %gep.a, align 1
+ %gep.b = getelementptr i8, ptr %b, i64 %iv
+ store i8 %load.a ,ptr %gep.b, align 1
+ %gep.c = getelementptr i64, ptr %c, i64 %iv
+ %load.c = load i64, ptr %gep.c, align 8
+ %gep.d = getelementptr i64, ptr %d, i64 %iv
+ store i64 %load.c, ptr %gep.d, align 8
+ %iv.next = add i64 %iv, 1
+ %exitcond.not = icmp eq i64 %iv.next, 1024
+ br i1 %exitcond.not, label %for.exit, label %for.body
+
+for.exit:
+ ret void
+}
>From 41848e71ea0a8497f1d75b3c02fe78fcd68e636d Mon Sep 17 00:00:00 2001
From: Elvis Wang <elvis.wang at sifive.com>
Date: Thu, 10 Sep 2026 20:22:06 -0700
Subject: [PATCH 2/3] [LV] Trim VFs that cause vector splitting when
tail-folding with EVL
When using EVL vectorization, LV only generates VP intrinsics with EVL for loads, stores, and reductions. The VL for other vector instructions is inferred from the def-use chain by VLOptimizer. However, VLOptimizer has some limitations that make it hard to infer the VL through split vectors, which causes bad performance (always using VLMax).
This patch trims VFs that would generate vectors requiring splitting by collecting the widest type in the vector region. If the widest type in the loop region at the VF would exceed the maximum legal register grouping (8), remove the VF from the plan.
---
.../Transforms/Vectorize/LoopVectorize.cpp | 5 ++
llvm/lib/Transforms/Vectorize/VPlan.h | 3 ++
.../Vectorize/VPlanEVLTailFolding.cpp | 32 ++++++++++++
.../Transforms/Vectorize/VPlanTransforms.h | 3 ++
.../RISCV/strided-access-wide-stride.ll | 32 ++++++------
.../RISCV/strided-accesses-narrow-iv.ll | 52 +++++++++----------
.../RISCV/tail-folding-reduction-cost.ll | 6 +--
7 files changed, 88 insertions(+), 45 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 5c4e20ee66b65..e034b5e6a6c28 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -6484,6 +6484,11 @@ void LoopVectorizationPlanner::buildVPlans(VPlan &VPlan1, ElementCount MinVF,
RUN_VPLAN_PASS(VPlanTransforms::addExplicitVectorLength, *Plan,
Config.getMaxSafeElements());
RUN_VPLAN_PASS(VPlanTransforms::optimizeEVLMasks, *Plan);
+ VPCostContext CostCtx(*TLI, *Plan, *CM, Config);
+ RUN_VPLAN_PASS(VPlanTransforms::trimVFsCausingSplits, *Plan, CostCtx);
+ // Skip the plan if all VFs are removed.
+ if (!Plan->hasAnyVF())
+ continue;
}
if (auto P =
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index daabca902724b..e9da4f764174e 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -5060,6 +5060,9 @@ class VPlan {
}
bool hasVF(ElementCount VF) const { return VFs.count(VF); }
+
+ /// Returns true if the plan contains at least one VF.
+ bool hasAnyVF() const { return !VFs.empty(); }
bool hasScalableVF() const {
return any_of(VFs, [](ElementCount VF) { return VF.isScalable(); });
}
diff --git a/llvm/lib/Transforms/Vectorize/VPlanEVLTailFolding.cpp b/llvm/lib/Transforms/Vectorize/VPlanEVLTailFolding.cpp
index c9d4b3425f72f..8846ccb7c886c 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanEVLTailFolding.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanEVLTailFolding.cpp
@@ -653,3 +653,35 @@ void VPlanTransforms::convertEVLExitCond(VPlan &Plan) {
LatchBr->setOperand(
0, Builder.createICmp(CmpInst::ICMP_EQ, AVLNext, Plan.getZero(AVLTy)));
}
+
+void VPlanTransforms::trimVFsCausingSplits(VPlan &Plan,
+ VPCostContext &CostCtx) {
+ if (!Plan.hasScalableVF())
+ return;
+
+ // Get the widest type in the vector region.
+ unsigned WidestType = 8;
+ VPRegionBlock *VectorLoop = Plan.getVectorLoopRegion();
+ for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
+ vp_depth_first_deep(VectorLoop->getEntry())))
+ for (VPRecipeBase &BaseR : make_range(VPBB->getFirstNonPhi(), VPBB->end()))
+ if (auto *R = dyn_cast<VPSingleDefRecipe>(&BaseR);
+ R && !vputils::onlyScalarValuesUsed(R)) {
+ // Skip the partial reduction since its VF is scaled down and can
+ // be calculated by its operands.
+ if (isa<VPExpressionRecipe>(R))
+ continue;
+ WidestType =
+ std::max(WidestType, R->getScalarType()->getScalarSizeInBits());
+ }
+
+ // Trim the VF that will generate vectors need to split.
+ SmallVector<ElementCount, 4> VFs = to_vector(Plan.vectorFactors());
+ for (auto VF : reverse(VFs)) {
+ if (CostCtx.TTI.getRegUsageForType(VectorType::get(
+ Type::getIntNTy(Plan.getContext(), WidestType), VF)) <= 8)
+ break;
+ Plan.removeVF(VF);
+ }
+ return;
+}
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
index 1c7b17942b795..ee849b19a9033 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
@@ -624,6 +624,9 @@ struct VPlanTransforms {
static void makeCallWideningDecisions(VPlan &Plan, VFRange &Range,
VPRecipeBuilder &RecipeBuilder,
VPCostContext &CostCtx);
+
+ /// Trim the VFs in \p Plan that will generate vectors requiring splitting.
+ static void trimVFsCausingSplits(VPlan &Plan, VPCostContext &CostCtx);
};
} // namespace llvm
diff --git a/llvm/test/Transforms/LoopVectorize/RISCV/strided-access-wide-stride.ll b/llvm/test/Transforms/LoopVectorize/RISCV/strided-access-wide-stride.ll
index 0b9617479b0de..10be5a644aee5 100644
--- a/llvm/test/Transforms/LoopVectorize/RISCV/strided-access-wide-stride.ll
+++ b/llvm/test/Transforms/LoopVectorize/RISCV/strided-access-wide-stride.ll
@@ -15,27 +15,27 @@ define void @stride_sext_exceeds_i32_max(ptr noalias readonly %src, ptr noalias
; CHECK-NEXT: [[TMP2:%.*]] = add nuw nsw i32 [[TMP1]], 1
; CHECK-NEXT: br label %[[VECTOR_PH:.*]]
; CHECK: [[VECTOR_PH]]:
-; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 16 x ptr> poison, ptr [[DST]], i64 0
-; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 16 x ptr> [[BROADCAST_SPLATINSERT]], <vscale x 16 x ptr> poison, <vscale x 16 x i32> zeroinitializer
-; CHECK-NEXT: [[TMP3:%.*]] = call <vscale x 16 x i16> @llvm.stepvector.nxv16i16()
-; CHECK-NEXT: [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <vscale x 16 x i16> poison, i16 [[START]], i64 0
-; CHECK-NEXT: [[BROADCAST_SPLAT2:%.*]] = shufflevector <vscale x 16 x i16> [[BROADCAST_SPLATINSERT1]], <vscale x 16 x i16> poison, <vscale x 16 x i32> zeroinitializer
-; CHECK-NEXT: [[INDUCTION:%.*]] = add <vscale x 16 x i16> [[BROADCAST_SPLAT2]], [[TMP3]]
+; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 8 x ptr> poison, ptr [[DST]], i64 0
+; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 8 x ptr> [[BROADCAST_SPLATINSERT]], <vscale x 8 x ptr> poison, <vscale x 8 x i32> zeroinitializer
+; CHECK-NEXT: [[TMP3:%.*]] = call <vscale x 8 x i16> @llvm.stepvector.nxv8i16()
+; CHECK-NEXT: [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <vscale x 8 x i16> poison, i16 [[START]], i64 0
+; CHECK-NEXT: [[BROADCAST_SPLAT2:%.*]] = shufflevector <vscale x 8 x i16> [[BROADCAST_SPLATINSERT1]], <vscale x 8 x i16> poison, <vscale x 8 x i32> zeroinitializer
+; CHECK-NEXT: [[INDUCTION:%.*]] = add <vscale x 8 x i16> [[BROADCAST_SPLAT2]], [[TMP3]]
; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
; CHECK: [[VECTOR_BODY]]:
-; CHECK-NEXT: [[VEC_IND:%.*]] = phi <vscale x 16 x i16> [ [[INDUCTION]], %[[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], %[[VECTOR_BODY]] ]
+; CHECK-NEXT: [[VEC_IND:%.*]] = phi <vscale x 8 x i16> [ [[INDUCTION]], %[[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], %[[VECTOR_BODY]] ]
; CHECK-NEXT: [[AVL:%.*]] = phi i32 [ [[TMP2]], %[[VECTOR_PH]] ], [ [[AVL_NEXT:%.*]], %[[VECTOR_BODY]] ]
-; CHECK-NEXT: [[TMP4:%.*]] = call i32 @llvm.experimental.get.vector.length.i32(i32 [[AVL]], i32 16, i1 true)
+; CHECK-NEXT: [[TMP4:%.*]] = call i32 @llvm.experimental.get.vector.length.i32(i32 [[AVL]], i32 8, i1 true)
; CHECK-NEXT: [[TMP5:%.*]] = trunc i32 [[TMP4]] to i16
-; CHECK-NEXT: [[BROADCAST_SPLATINSERT3:%.*]] = insertelement <vscale x 16 x i16> poison, i16 [[TMP5]], i64 0
-; CHECK-NEXT: [[BROADCAST_SPLAT4:%.*]] = shufflevector <vscale x 16 x i16> [[BROADCAST_SPLATINSERT3]], <vscale x 16 x i16> poison, <vscale x 16 x i32> zeroinitializer
-; CHECK-NEXT: [[TMP6:%.*]] = sext <vscale x 16 x i16> [[VEC_IND]] to <vscale x 16 x i64>
-; CHECK-NEXT: [[TMP7:%.*]] = mul nsw <vscale x 16 x i64> [[TMP6]], splat (i64 3000000000)
-; CHECK-NEXT: [[WIDE_GEP:%.*]] = getelementptr i8, ptr [[SRC]], <vscale x 16 x i64> [[TMP7]]
-; CHECK-NEXT: [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 16 x i8> @llvm.vp.gather.nxv16i8.nxv16p0(<vscale x 16 x ptr> align 1 [[WIDE_GEP]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP4]])
-; CHECK-NEXT: call void @llvm.vp.scatter.nxv16i8.nxv16p0(<vscale x 16 x i8> [[WIDE_MASKED_GATHER]], <vscale x 16 x ptr> align 1 [[BROADCAST_SPLAT]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP4]])
+; CHECK-NEXT: [[BROADCAST_SPLATINSERT3:%.*]] = insertelement <vscale x 8 x i16> poison, i16 [[TMP5]], i64 0
+; CHECK-NEXT: [[BROADCAST_SPLAT4:%.*]] = shufflevector <vscale x 8 x i16> [[BROADCAST_SPLATINSERT3]], <vscale x 8 x i16> poison, <vscale x 8 x i32> zeroinitializer
+; CHECK-NEXT: [[TMP6:%.*]] = sext <vscale x 8 x i16> [[VEC_IND]] to <vscale x 8 x i64>
+; CHECK-NEXT: [[TMP7:%.*]] = mul nsw <vscale x 8 x i64> [[TMP6]], splat (i64 3000000000)
+; CHECK-NEXT: [[WIDE_GEP:%.*]] = getelementptr i8, ptr [[SRC]], <vscale x 8 x i64> [[TMP7]]
+; CHECK-NEXT: [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 8 x i8> @llvm.vp.gather.nxv8i8.nxv8p0(<vscale x 8 x ptr> align 1 [[WIDE_GEP]], <vscale x 8 x i1> splat (i1 true), i32 [[TMP4]])
+; CHECK-NEXT: call void @llvm.vp.scatter.nxv8i8.nxv8p0(<vscale x 8 x i8> [[WIDE_MASKED_GATHER]], <vscale x 8 x ptr> align 1 [[BROADCAST_SPLAT]], <vscale x 8 x i1> splat (i1 true), i32 [[TMP4]])
; CHECK-NEXT: [[AVL_NEXT]] = sub nuw i32 [[AVL]], [[TMP4]]
-; CHECK-NEXT: [[VEC_IND_NEXT]] = add <vscale x 16 x i16> [[VEC_IND]], [[BROADCAST_SPLAT4]]
+; CHECK-NEXT: [[VEC_IND_NEXT]] = add <vscale x 8 x i16> [[VEC_IND]], [[BROADCAST_SPLAT4]]
; CHECK-NEXT: [[TMP8:%.*]] = icmp eq i32 [[AVL_NEXT]], 0
; CHECK-NEXT: br i1 [[TMP8]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
; CHECK: [[MIDDLE_BLOCK]]:
diff --git a/llvm/test/Transforms/LoopVectorize/RISCV/strided-accesses-narrow-iv.ll b/llvm/test/Transforms/LoopVectorize/RISCV/strided-accesses-narrow-iv.ll
index 1a1d3a4d16d42..8db7a2f54c095 100644
--- a/llvm/test/Transforms/LoopVectorize/RISCV/strided-accesses-narrow-iv.ll
+++ b/llvm/test/Transforms/LoopVectorize/RISCV/strided-accesses-narrow-iv.ll
@@ -285,25 +285,25 @@ define void @narrow_iv_i8_sext_i64_wrapping(ptr noalias %arr, ptr noalias %out)
; RV64-NEXT: [[ENTRY:.*:]]
; RV64-NEXT: br label %[[LOOP:.*]]
; RV64: [[LOOP]]:
-; RV64-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 16 x ptr> poison, ptr [[OUT]], i64 0
-; RV64-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 16 x ptr> [[BROADCAST_SPLATINSERT]], <vscale x 16 x ptr> poison, <vscale x 16 x i32> zeroinitializer
-; RV64-NEXT: [[TMP0:%.*]] = call <vscale x 16 x i8> @llvm.stepvector.nxv16i8()
-; RV64-NEXT: [[TMP1:%.*]] = mul <vscale x 16 x i8> [[TMP0]], splat (i8 4)
+; RV64-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 8 x ptr> poison, ptr [[OUT]], i64 0
+; RV64-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 8 x ptr> [[BROADCAST_SPLATINSERT]], <vscale x 8 x ptr> poison, <vscale x 8 x i32> zeroinitializer
+; RV64-NEXT: [[TMP0:%.*]] = call <vscale x 8 x i8> @llvm.stepvector.nxv8i8()
+; RV64-NEXT: [[TMP1:%.*]] = mul <vscale x 8 x i8> [[TMP0]], splat (i8 4)
; RV64-NEXT: br label %[[EXIT:.*]]
; RV64: [[EXIT]]:
-; RV64-NEXT: [[VEC_IND:%.*]] = phi <vscale x 16 x i8> [ [[TMP1]], %[[LOOP]] ], [ [[VEC_IND_NEXT:%.*]], %[[EXIT]] ]
+; RV64-NEXT: [[VEC_IND:%.*]] = phi <vscale x 8 x i8> [ [[TMP1]], %[[LOOP]] ], [ [[VEC_IND_NEXT:%.*]], %[[EXIT]] ]
; RV64-NEXT: [[AVL:%.*]] = phi i32 [ 64, %[[LOOP]] ], [ [[AVL_NEXT:%.*]], %[[EXIT]] ]
-; RV64-NEXT: [[TMP2:%.*]] = call i32 @llvm.experimental.get.vector.length.i32(i32 [[AVL]], i32 16, i1 true)
+; RV64-NEXT: [[TMP2:%.*]] = call i32 @llvm.experimental.get.vector.length.i32(i32 [[AVL]], i32 8, i1 true)
; RV64-NEXT: [[TMP3:%.*]] = trunc i32 [[TMP2]] to i8
; RV64-NEXT: [[TMP4:%.*]] = shl i8 [[TMP3]], 2
-; RV64-NEXT: [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <vscale x 16 x i8> poison, i8 [[TMP4]], i64 0
-; RV64-NEXT: [[BROADCAST_SPLAT2:%.*]] = shufflevector <vscale x 16 x i8> [[BROADCAST_SPLATINSERT1]], <vscale x 16 x i8> poison, <vscale x 16 x i32> zeroinitializer
-; RV64-NEXT: [[TMP5:%.*]] = sext <vscale x 16 x i8> [[VEC_IND]] to <vscale x 16 x i64>
-; RV64-NEXT: [[WIDE_GEP:%.*]] = getelementptr [1024 x i8], ptr [[ARR]], <vscale x 16 x i64> [[TMP5]]
-; RV64-NEXT: [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 16 x i8> @llvm.vp.gather.nxv16i8.nxv16p0(<vscale x 16 x ptr> align 1 [[WIDE_GEP]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP2]])
-; RV64-NEXT: call void @llvm.vp.scatter.nxv16i8.nxv16p0(<vscale x 16 x i8> [[WIDE_MASKED_GATHER]], <vscale x 16 x ptr> align 1 [[BROADCAST_SPLAT]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP2]])
+; RV64-NEXT: [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <vscale x 8 x i8> poison, i8 [[TMP4]], i64 0
+; RV64-NEXT: [[BROADCAST_SPLAT2:%.*]] = shufflevector <vscale x 8 x i8> [[BROADCAST_SPLATINSERT1]], <vscale x 8 x i8> poison, <vscale x 8 x i32> zeroinitializer
+; RV64-NEXT: [[TMP5:%.*]] = sext <vscale x 8 x i8> [[VEC_IND]] to <vscale x 8 x i64>
+; RV64-NEXT: [[WIDE_GEP:%.*]] = getelementptr [1024 x i8], ptr [[ARR]], <vscale x 8 x i64> [[TMP5]]
+; RV64-NEXT: [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 8 x i8> @llvm.vp.gather.nxv8i8.nxv8p0(<vscale x 8 x ptr> align 1 [[WIDE_GEP]], <vscale x 8 x i1> splat (i1 true), i32 [[TMP2]])
+; RV64-NEXT: call void @llvm.vp.scatter.nxv8i8.nxv8p0(<vscale x 8 x i8> [[WIDE_MASKED_GATHER]], <vscale x 8 x ptr> align 1 [[BROADCAST_SPLAT]], <vscale x 8 x i1> splat (i1 true), i32 [[TMP2]])
; RV64-NEXT: [[AVL_NEXT]] = sub nuw i32 [[AVL]], [[TMP2]]
-; RV64-NEXT: [[VEC_IND_NEXT]] = add <vscale x 16 x i8> [[VEC_IND]], [[BROADCAST_SPLAT2]]
+; RV64-NEXT: [[VEC_IND_NEXT]] = add <vscale x 8 x i8> [[VEC_IND]], [[BROADCAST_SPLAT2]]
; RV64-NEXT: [[TMP6:%.*]] = icmp eq i32 [[AVL_NEXT]], 0
; RV64-NEXT: br i1 [[TMP6]], label %[[MIDDLE_BLOCK:.*]], label %[[EXIT]], !llvm.loop [[LOOP6:![0-9]+]]
; RV64: [[MIDDLE_BLOCK]]:
@@ -316,25 +316,25 @@ define void @narrow_iv_i8_sext_i64_wrapping(ptr noalias %arr, ptr noalias %out)
; RV32-NEXT: [[ENTRY:.*:]]
; RV32-NEXT: br label %[[LOOP:.*]]
; RV32: [[LOOP]]:
-; RV32-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 16 x ptr> poison, ptr [[OUT]], i64 0
-; RV32-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 16 x ptr> [[BROADCAST_SPLATINSERT]], <vscale x 16 x ptr> poison, <vscale x 16 x i32> zeroinitializer
-; RV32-NEXT: [[TMP0:%.*]] = call <vscale x 16 x i8> @llvm.stepvector.nxv16i8()
-; RV32-NEXT: [[TMP1:%.*]] = mul <vscale x 16 x i8> [[TMP0]], splat (i8 4)
+; RV32-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 8 x ptr> poison, ptr [[OUT]], i64 0
+; RV32-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 8 x ptr> [[BROADCAST_SPLATINSERT]], <vscale x 8 x ptr> poison, <vscale x 8 x i32> zeroinitializer
+; RV32-NEXT: [[TMP0:%.*]] = call <vscale x 8 x i8> @llvm.stepvector.nxv8i8()
+; RV32-NEXT: [[TMP1:%.*]] = mul <vscale x 8 x i8> [[TMP0]], splat (i8 4)
; RV32-NEXT: br label %[[EXIT:.*]]
; RV32: [[EXIT]]:
-; RV32-NEXT: [[VEC_IND:%.*]] = phi <vscale x 16 x i8> [ [[TMP1]], %[[LOOP]] ], [ [[VEC_IND_NEXT:%.*]], %[[EXIT]] ]
+; RV32-NEXT: [[VEC_IND:%.*]] = phi <vscale x 8 x i8> [ [[TMP1]], %[[LOOP]] ], [ [[VEC_IND_NEXT:%.*]], %[[EXIT]] ]
; RV32-NEXT: [[AVL:%.*]] = phi i32 [ 64, %[[LOOP]] ], [ [[AVL_NEXT:%.*]], %[[EXIT]] ]
-; RV32-NEXT: [[TMP2:%.*]] = call i32 @llvm.experimental.get.vector.length.i32(i32 [[AVL]], i32 16, i1 true)
+; RV32-NEXT: [[TMP2:%.*]] = call i32 @llvm.experimental.get.vector.length.i32(i32 [[AVL]], i32 8, i1 true)
; RV32-NEXT: [[TMP3:%.*]] = trunc i32 [[TMP2]] to i8
; RV32-NEXT: [[TMP4:%.*]] = shl i8 [[TMP3]], 2
-; RV32-NEXT: [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <vscale x 16 x i8> poison, i8 [[TMP4]], i64 0
-; RV32-NEXT: [[BROADCAST_SPLAT2:%.*]] = shufflevector <vscale x 16 x i8> [[BROADCAST_SPLATINSERT1]], <vscale x 16 x i8> poison, <vscale x 16 x i32> zeroinitializer
-; RV32-NEXT: [[TMP5:%.*]] = sext <vscale x 16 x i8> [[VEC_IND]] to <vscale x 16 x i64>
-; RV32-NEXT: [[WIDE_GEP:%.*]] = getelementptr [1024 x i8], ptr [[ARR]], <vscale x 16 x i64> [[TMP5]]
-; RV32-NEXT: [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 16 x i8> @llvm.vp.gather.nxv16i8.nxv16p0(<vscale x 16 x ptr> align 1 [[WIDE_GEP]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP2]])
-; RV32-NEXT: call void @llvm.vp.scatter.nxv16i8.nxv16p0(<vscale x 16 x i8> [[WIDE_MASKED_GATHER]], <vscale x 16 x ptr> align 1 [[BROADCAST_SPLAT]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP2]])
+; RV32-NEXT: [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <vscale x 8 x i8> poison, i8 [[TMP4]], i64 0
+; RV32-NEXT: [[BROADCAST_SPLAT2:%.*]] = shufflevector <vscale x 8 x i8> [[BROADCAST_SPLATINSERT1]], <vscale x 8 x i8> poison, <vscale x 8 x i32> zeroinitializer
+; RV32-NEXT: [[TMP5:%.*]] = sext <vscale x 8 x i8> [[VEC_IND]] to <vscale x 8 x i64>
+; RV32-NEXT: [[WIDE_GEP:%.*]] = getelementptr [1024 x i8], ptr [[ARR]], <vscale x 8 x i64> [[TMP5]]
+; RV32-NEXT: [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 8 x i8> @llvm.vp.gather.nxv8i8.nxv8p0(<vscale x 8 x ptr> align 1 [[WIDE_GEP]], <vscale x 8 x i1> splat (i1 true), i32 [[TMP2]])
+; RV32-NEXT: call void @llvm.vp.scatter.nxv8i8.nxv8p0(<vscale x 8 x i8> [[WIDE_MASKED_GATHER]], <vscale x 8 x ptr> align 1 [[BROADCAST_SPLAT]], <vscale x 8 x i1> splat (i1 true), i32 [[TMP2]])
; RV32-NEXT: [[AVL_NEXT]] = sub nuw i32 [[AVL]], [[TMP2]]
-; RV32-NEXT: [[VEC_IND_NEXT]] = add <vscale x 16 x i8> [[VEC_IND]], [[BROADCAST_SPLAT2]]
+; RV32-NEXT: [[VEC_IND_NEXT]] = add <vscale x 8 x i8> [[VEC_IND]], [[BROADCAST_SPLAT2]]
; RV32-NEXT: [[TMP6:%.*]] = icmp eq i32 [[AVL_NEXT]], 0
; RV32-NEXT: br i1 [[TMP6]], label %[[MIDDLE_BLOCK:.*]], label %[[EXIT]], !llvm.loop [[LOOP6:![0-9]+]]
; RV32: [[MIDDLE_BLOCK]]:
diff --git a/llvm/test/Transforms/LoopVectorize/RISCV/tail-folding-reduction-cost.ll b/llvm/test/Transforms/LoopVectorize/RISCV/tail-folding-reduction-cost.ll
index 1c644aadfd8ad..94a59e0229361 100644
--- a/llvm/test/Transforms/LoopVectorize/RISCV/tail-folding-reduction-cost.ll
+++ b/llvm/test/Transforms/LoopVectorize/RISCV/tail-folding-reduction-cost.ll
@@ -4,7 +4,7 @@
; RUN: -tail-folding-policy=prefer-fold-tail -vectorizer-maximize-bandwidth \
; RUN: -mtriple=riscv64 -mattr=+v -S < %s 2>&1 | FileCheck %s
-; When the type needs split, vp.merge won't be folded.
+; Check that LV won't generate vectors requiring splitting.
define i64 @add(ptr %a, i64 %n, i64 %start) {
; CHECK-LABEL: 'add'
; CHECK: Cost of 0 for VF vscale x 1: WIDEN-REDUCTION-PHI ir<%rdx> = phi (add) vp<[[VP2:%[0-9]+]]>, vp<[[VP9:%[0-9]+]]>
@@ -15,8 +15,8 @@ define i64 @add(ptr %a, i64 %n, i64 %start) {
; CHECK: Cost of 0 for VF vscale x 4: WIDEN-INTRINSIC vp<[[VP9]]> = call llvm.vp.merge(ir<true>, ir<%add>, ir<%rdx>, vp<%evl>)
; CHECK: Cost of 0 for VF vscale x 8: WIDEN-REDUCTION-PHI ir<%rdx> = phi (add) vp<[[VP2]]>, vp<[[VP9]]>
; CHECK: Cost of 0 for VF vscale x 8: WIDEN-INTRINSIC vp<[[VP9]]> = call llvm.vp.merge(ir<true>, ir<%add>, ir<%rdx>, vp<%evl>)
-; CHECK: Cost of 0 for VF vscale x 16: WIDEN-REDUCTION-PHI ir<%rdx> = phi (add) vp<[[VP2]]>, vp<[[VP9]]>
-; CHECK: Cost of 16 for VF vscale x 16: WIDEN-INTRINSIC vp<[[VP9]]> = call llvm.vp.merge(ir<true>, ir<%add>, ir<%rdx>, vp<%evl>)
+; CHECK-NOT: Cost of {{.*}} for VF vscale x 16: WIDEN-REDUCTION-PHI ir<%rdx> = phi (add) vp<[[VP2]]>, vp<[[VP9]]>
+; CHECK-NOT: Cost of {{.*}} for VF vscale x 16: WIDEN-INTRINSIC vp<[[VP9]]> = call llvm.vp.merge(ir<true>, ir<%add>, ir<%rdx>, vp<%evl>)
;
entry:
br label %loop
>From f339c3b2fe8823936ff6736d3bc141f7a2b44cc7 Mon Sep 17 00:00:00 2001
From: Elvis Wang <elvis.wang at sifive.com>
Date: Sun, 13 Sep 2026 20:25:39 -0700
Subject: [PATCH 3/3] Address comments.
---
.../Transforms/Vectorize/LoopVectorize.cpp | 3 +-
.../Vectorize/VPlanEVLTailFolding.cpp | 46 +++++++++++++------
.../Transforms/Vectorize/VPlanTransforms.h | 2 +-
.../LoopVectorize/RISCV/partial-reduce.ll | 38 +++++++--------
.../RISCV/reg-usage-maxbandwidth.ll | 8 +---
.../RISCV/tail-folding-reduction-cost.ll | 3 +-
.../RISCV/tail-folding-reverse-load-store.ll | 16 +++----
7 files changed, 63 insertions(+), 53 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index e034b5e6a6c28..0e254b33e5fef 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -6484,8 +6484,7 @@ void LoopVectorizationPlanner::buildVPlans(VPlan &VPlan1, ElementCount MinVF,
RUN_VPLAN_PASS(VPlanTransforms::addExplicitVectorLength, *Plan,
Config.getMaxSafeElements());
RUN_VPLAN_PASS(VPlanTransforms::optimizeEVLMasks, *Plan);
- VPCostContext CostCtx(*TLI, *Plan, *CM, Config);
- RUN_VPLAN_PASS(VPlanTransforms::trimVFsCausingSplits, *Plan, CostCtx);
+ RUN_VPLAN_PASS(VPlanTransforms::trimVFsCausingSplits, *Plan, TTI);
// Skip the plan if all VFs are removed.
if (!Plan->hasAnyVF())
continue;
diff --git a/llvm/lib/Transforms/Vectorize/VPlanEVLTailFolding.cpp b/llvm/lib/Transforms/Vectorize/VPlanEVLTailFolding.cpp
index 8846ccb7c886c..37d65dfd6c914 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanEVLTailFolding.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanEVLTailFolding.cpp
@@ -655,30 +655,48 @@ void VPlanTransforms::convertEVLExitCond(VPlan &Plan) {
}
void VPlanTransforms::trimVFsCausingSplits(VPlan &Plan,
- VPCostContext &CostCtx) {
+ const TargetTransformInfo &TTI) {
if (!Plan.hasScalableVF())
return;
// Get the widest type in the vector region.
- unsigned WidestType = 8;
- VPRegionBlock *VectorLoop = Plan.getVectorLoopRegion();
+ unsigned WidestType = 1;
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
- vp_depth_first_deep(VectorLoop->getEntry())))
- for (VPRecipeBase &BaseR : make_range(VPBB->getFirstNonPhi(), VPBB->end()))
- if (auto *R = dyn_cast<VPSingleDefRecipe>(&BaseR);
- R && !vputils::onlyScalarValuesUsed(R)) {
- // Skip the partial reduction since its VF is scaled down and can
- // be calculated by its operands.
- if (isa<VPExpressionRecipe>(R))
- continue;
- WidestType =
- std::max(WidestType, R->getScalarType()->getScalarSizeInBits());
+ vp_depth_first_deep(Plan.getEntry())))
+ for (VPRecipeBase &BaseR :
+ make_range(VPBB->getFirstNonPhi(), VPBB->end())) {
+ auto GetTypeSizeInBits = [&](Type *T) {
+ return isa<PointerType>(T) ? Plan.getDataLayout().getPointerSizeInBits(
+ T->getPointerAddressSpace())
+ : T->getScalarSizeInBits();
+ };
+ if (auto *Store = dyn_cast<VPWidenStoreEVLRecipe>(&BaseR)) {
+ WidestType = std::max(
+ WidestType,
+ GetTypeSizeInBits(Store->getStoredValue()->getScalarType()));
+ continue;
}
+ for (auto *V : BaseR.definedValues()) {
+ if (!vputils::onlyScalarValuesUsed(V)) {
+ // Skip the partial reduction since its VF is scaled down and can
+ // be calculated by its operands.
+ if (isa<VPExpressionRecipe>(V))
+ continue;
+ uint64_t Scale;
+ if (match(V, m_VPInstruction<VPInstruction::ReductionStartVector>(
+ m_VPValue(), m_VPValue(), m_ConstantInt(Scale))) &&
+ Scale != 1)
+ continue;
+ WidestType =
+ std::max(WidestType, GetTypeSizeInBits(V->getScalarType()));
+ }
+ }
+ }
// Trim the VF that will generate vectors need to split.
SmallVector<ElementCount, 4> VFs = to_vector(Plan.vectorFactors());
for (auto VF : reverse(VFs)) {
- if (CostCtx.TTI.getRegUsageForType(VectorType::get(
+ if (TTI.getRegUsageForType(VectorType::get(
Type::getIntNTy(Plan.getContext(), WidestType), VF)) <= 8)
break;
Plan.removeVF(VF);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
index ee849b19a9033..c7dd8d28a58d9 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
@@ -626,7 +626,7 @@ struct VPlanTransforms {
VPCostContext &CostCtx);
/// Trim the VFs in \p Plan that will generate vectors requiring splitting.
- static void trimVFsCausingSplits(VPlan &Plan, VPCostContext &CostCtx);
+ static void trimVFsCausingSplits(VPlan &Plan, const TargetTransformInfo &TTI);
};
} // namespace llvm
diff --git a/llvm/test/Transforms/LoopVectorize/RISCV/partial-reduce.ll b/llvm/test/Transforms/LoopVectorize/RISCV/partial-reduce.ll
index 8bc65d1b8add3..8d9a8383f3bde 100644
--- a/llvm/test/Transforms/LoopVectorize/RISCV/partial-reduce.ll
+++ b/llvm/test/Transforms/LoopVectorize/RISCV/partial-reduce.ll
@@ -332,38 +332,38 @@ define i32 @chained_reduce_iv_derived_first_link(ptr %c, ptr %d, i64 %N) #0 {
; MAXBW-NEXT: [[ENTRY:.*:]]
; MAXBW-NEXT: br label %[[VECTOR_PH:.*]]
; MAXBW: [[VECTOR_PH]]:
-; MAXBW-NEXT: [[TMP0:%.*]] = call <vscale x 16 x i8> @llvm.stepvector.nxv16i8()
+; MAXBW-NEXT: [[TMP0:%.*]] = call <vscale x 8 x i8> @llvm.stepvector.nxv8i8()
; MAXBW-NEXT: br label %[[VECTOR_BODY:.*]]
; MAXBW: [[VECTOR_BODY]]:
; MAXBW-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[CURRENT_ITERATION_NEXT:%.*]], %[[VECTOR_BODY]] ]
-; MAXBW-NEXT: [[VEC_PHI:%.*]] = phi <vscale x 4 x i32> [ zeroinitializer, %[[VECTOR_PH]] ], [ [[PARTIAL_REDUCE2:%.*]], %[[VECTOR_BODY]] ]
-; MAXBW-NEXT: [[VEC_IND:%.*]] = phi <vscale x 16 x i8> [ [[TMP0]], %[[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], %[[VECTOR_BODY]] ]
+; MAXBW-NEXT: [[VEC_PHI:%.*]] = phi <vscale x 2 x i32> [ zeroinitializer, %[[VECTOR_PH]] ], [ [[PARTIAL_REDUCE2:%.*]], %[[VECTOR_BODY]] ]
+; MAXBW-NEXT: [[VEC_IND:%.*]] = phi <vscale x 8 x i8> [ [[TMP0]], %[[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], %[[VECTOR_BODY]] ]
; MAXBW-NEXT: [[AVL:%.*]] = phi i64 [ [[N]], %[[VECTOR_PH]] ], [ [[AVL_NEXT:%.*]], %[[VECTOR_BODY]] ]
-; MAXBW-NEXT: [[TMP1:%.*]] = call i32 @llvm.experimental.get.vector.length.i64(i64 [[AVL]], i32 16, i1 true)
+; MAXBW-NEXT: [[TMP1:%.*]] = call i32 @llvm.experimental.get.vector.length.i64(i64 [[AVL]], i32 8, i1 true)
; MAXBW-NEXT: [[TMP2:%.*]] = zext i32 [[TMP1]] to i64
; MAXBW-NEXT: [[TMP3:%.*]] = trunc i64 [[TMP2]] to i8
-; MAXBW-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 16 x i8> poison, i8 [[TMP3]], i64 0
-; MAXBW-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 16 x i8> [[BROADCAST_SPLATINSERT]], <vscale x 16 x i8> poison, <vscale x 16 x i32> zeroinitializer
-; MAXBW-NEXT: [[TMP4:%.*]] = sext <vscale x 16 x i8> [[VEC_IND]] to <vscale x 16 x i32>
-; MAXBW-NEXT: [[TMP5:%.*]] = mul <vscale x 16 x i32> [[TMP4]], [[TMP4]]
-; MAXBW-NEXT: [[TMP6:%.*]] = call <vscale x 16 x i32> @llvm.vp.merge.nxv16i32(<vscale x 16 x i1> splat (i1 true), <vscale x 16 x i32> [[TMP5]], <vscale x 16 x i32> zeroinitializer, i32 [[TMP1]])
-; MAXBW-NEXT: [[PARTIAL_REDUCE:%.*]] = call <vscale x 4 x i32> @llvm.vector.partial.reduce.add.nxv4i32.nxv16i32(<vscale x 4 x i32> [[VEC_PHI]], <vscale x 16 x i32> [[TMP6]])
+; MAXBW-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 8 x i8> poison, i8 [[TMP3]], i64 0
+; MAXBW-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 8 x i8> [[BROADCAST_SPLATINSERT]], <vscale x 8 x i8> poison, <vscale x 8 x i32> zeroinitializer
+; MAXBW-NEXT: [[TMP4:%.*]] = sext <vscale x 8 x i8> [[VEC_IND]] to <vscale x 8 x i32>
+; MAXBW-NEXT: [[TMP5:%.*]] = mul <vscale x 8 x i32> [[TMP4]], [[TMP4]]
+; MAXBW-NEXT: [[TMP6:%.*]] = call <vscale x 8 x i32> @llvm.vp.merge.nxv8i32(<vscale x 8 x i1> splat (i1 true), <vscale x 8 x i32> [[TMP5]], <vscale x 8 x i32> zeroinitializer, i32 [[TMP1]])
+; MAXBW-NEXT: [[PARTIAL_REDUCE:%.*]] = call <vscale x 2 x i32> @llvm.vector.partial.reduce.add.nxv2i32.nxv8i32(<vscale x 2 x i32> [[VEC_PHI]], <vscale x 8 x i32> [[TMP6]])
; MAXBW-NEXT: [[TMP7:%.*]] = getelementptr inbounds nuw i8, ptr [[C]], i64 [[INDEX]]
-; MAXBW-NEXT: [[VP_OP_LOAD:%.*]] = call <vscale x 16 x i8> @llvm.vp.load.nxv16i8.p0(ptr align 1 [[TMP7]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP1]])
+; MAXBW-NEXT: [[VP_OP_LOAD:%.*]] = call <vscale x 8 x i8> @llvm.vp.load.nxv8i8.p0(ptr align 1 [[TMP7]], <vscale x 8 x i1> splat (i1 true), i32 [[TMP1]])
; MAXBW-NEXT: [[TMP8:%.*]] = getelementptr inbounds nuw i8, ptr [[D]], i64 [[INDEX]]
-; MAXBW-NEXT: [[VP_OP_LOAD1:%.*]] = call <vscale x 16 x i8> @llvm.vp.load.nxv16i8.p0(ptr align 1 [[TMP8]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP1]])
-; MAXBW-NEXT: [[TMP9:%.*]] = sext <vscale x 16 x i8> [[VP_OP_LOAD]] to <vscale x 16 x i32>
-; MAXBW-NEXT: [[TMP10:%.*]] = sext <vscale x 16 x i8> [[VP_OP_LOAD1]] to <vscale x 16 x i32>
-; MAXBW-NEXT: [[TMP11:%.*]] = mul <vscale x 16 x i32> [[TMP9]], [[TMP10]]
-; MAXBW-NEXT: [[TMP12:%.*]] = call <vscale x 16 x i32> @llvm.vp.merge.nxv16i32(<vscale x 16 x i1> splat (i1 true), <vscale x 16 x i32> [[TMP11]], <vscale x 16 x i32> zeroinitializer, i32 [[TMP1]])
-; MAXBW-NEXT: [[PARTIAL_REDUCE2]] = call <vscale x 4 x i32> @llvm.vector.partial.reduce.add.nxv4i32.nxv16i32(<vscale x 4 x i32> [[PARTIAL_REDUCE]], <vscale x 16 x i32> [[TMP12]])
+; MAXBW-NEXT: [[VP_OP_LOAD1:%.*]] = call <vscale x 8 x i8> @llvm.vp.load.nxv8i8.p0(ptr align 1 [[TMP8]], <vscale x 8 x i1> splat (i1 true), i32 [[TMP1]])
+; MAXBW-NEXT: [[TMP9:%.*]] = sext <vscale x 8 x i8> [[VP_OP_LOAD]] to <vscale x 8 x i32>
+; MAXBW-NEXT: [[TMP10:%.*]] = sext <vscale x 8 x i8> [[VP_OP_LOAD1]] to <vscale x 8 x i32>
+; MAXBW-NEXT: [[TMP11:%.*]] = mul <vscale x 8 x i32> [[TMP9]], [[TMP10]]
+; MAXBW-NEXT: [[TMP12:%.*]] = call <vscale x 8 x i32> @llvm.vp.merge.nxv8i32(<vscale x 8 x i1> splat (i1 true), <vscale x 8 x i32> [[TMP11]], <vscale x 8 x i32> zeroinitializer, i32 [[TMP1]])
+; MAXBW-NEXT: [[PARTIAL_REDUCE2]] = call <vscale x 2 x i32> @llvm.vector.partial.reduce.add.nxv2i32.nxv8i32(<vscale x 2 x i32> [[PARTIAL_REDUCE]], <vscale x 8 x i32> [[TMP12]])
; MAXBW-NEXT: [[CURRENT_ITERATION_NEXT]] = add i64 [[TMP2]], [[INDEX]]
; MAXBW-NEXT: [[AVL_NEXT]] = sub nuw i64 [[AVL]], [[TMP2]]
-; MAXBW-NEXT: [[VEC_IND_NEXT]] = add <vscale x 16 x i8> [[VEC_IND]], [[BROADCAST_SPLAT]]
+; MAXBW-NEXT: [[VEC_IND_NEXT]] = add <vscale x 8 x i8> [[VEC_IND]], [[BROADCAST_SPLAT]]
; MAXBW-NEXT: [[TMP13:%.*]] = icmp eq i64 [[AVL_NEXT]], 0
; MAXBW-NEXT: br i1 [[TMP13]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP5:![0-9]+]]
; MAXBW: [[MIDDLE_BLOCK]]:
-; MAXBW-NEXT: [[TMP14:%.*]] = call i32 @llvm.vector.reduce.add.nxv4i32(<vscale x 4 x i32> [[PARTIAL_REDUCE2]])
+; MAXBW-NEXT: [[TMP14:%.*]] = call i32 @llvm.vector.reduce.add.nxv2i32(<vscale x 2 x i32> [[PARTIAL_REDUCE2]])
; MAXBW-NEXT: br label %[[EXIT:.*]]
; MAXBW: [[EXIT]]:
; MAXBW-NEXT: ret i32 [[TMP14]]
diff --git a/llvm/test/Transforms/LoopVectorize/RISCV/reg-usage-maxbandwidth.ll b/llvm/test/Transforms/LoopVectorize/RISCV/reg-usage-maxbandwidth.ll
index a0667eb811a52..ec5724b7acc02 100644
--- a/llvm/test/Transforms/LoopVectorize/RISCV/reg-usage-maxbandwidth.ll
+++ b/llvm/test/Transforms/LoopVectorize/RISCV/reg-usage-maxbandwidth.ll
@@ -225,13 +225,7 @@ define void @mix_type_i8_i64(ptr %a, ptr %b, ptr %c, ptr %d) {
; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::VRRC, 8 registers
; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
-; CHECK-REGS-VP: LV(REG): VF = vscale x 16
-; CHECK-REGS-VP: LV(REG): Found max usage: 2 item
-; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 6 registers
-; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::VRRC, 16 registers
-; CHECK-REGS-VP: LV(REG): Found invariant usage: 1 item
-; CHECK-REGS-VP: LV(REG): RegisterClass: RISCV::GPRRC, 1 registers
-; CHECK-REGS-VP: LV: Selecting VF: vscale x 16.
+; CHECK-REGS-VP: LV: Selecting VF: vscale x 8.
;
entry:
br label %for.body
diff --git a/llvm/test/Transforms/LoopVectorize/RISCV/tail-folding-reduction-cost.ll b/llvm/test/Transforms/LoopVectorize/RISCV/tail-folding-reduction-cost.ll
index 94a59e0229361..a475b90ddfd7b 100644
--- a/llvm/test/Transforms/LoopVectorize/RISCV/tail-folding-reduction-cost.ll
+++ b/llvm/test/Transforms/LoopVectorize/RISCV/tail-folding-reduction-cost.ll
@@ -15,8 +15,7 @@ define i64 @add(ptr %a, i64 %n, i64 %start) {
; CHECK: Cost of 0 for VF vscale x 4: WIDEN-INTRINSIC vp<[[VP9]]> = call llvm.vp.merge(ir<true>, ir<%add>, ir<%rdx>, vp<%evl>)
; CHECK: Cost of 0 for VF vscale x 8: WIDEN-REDUCTION-PHI ir<%rdx> = phi (add) vp<[[VP2]]>, vp<[[VP9]]>
; CHECK: Cost of 0 for VF vscale x 8: WIDEN-INTRINSIC vp<[[VP9]]> = call llvm.vp.merge(ir<true>, ir<%add>, ir<%rdx>, vp<%evl>)
-; CHECK-NOT: Cost of {{.*}} for VF vscale x 16: WIDEN-REDUCTION-PHI ir<%rdx> = phi (add) vp<[[VP2]]>, vp<[[VP9]]>
-; CHECK-NOT: Cost of {{.*}} for VF vscale x 16: WIDEN-INTRINSIC vp<[[VP9]]> = call llvm.vp.merge(ir<true>, ir<%add>, ir<%rdx>, vp<%evl>)
+; CHECK-NOT: Cost of {{.*}} for VF vscale x 16
;
entry:
br label %loop
diff --git a/llvm/test/Transforms/LoopVectorize/RISCV/tail-folding-reverse-load-store.ll b/llvm/test/Transforms/LoopVectorize/RISCV/tail-folding-reverse-load-store.ll
index b9dceefde871b..b46b2ced4dc28 100644
--- a/llvm/test/Transforms/LoopVectorize/RISCV/tail-folding-reverse-load-store.ll
+++ b/llvm/test/Transforms/LoopVectorize/RISCV/tail-folding-reverse-load-store.ll
@@ -239,24 +239,24 @@ define void @multiple_reverse_vector_pointer(ptr noalias %a, ptr noalias %b, ptr
; IF-EVL: vector.body:
; IF-EVL-NEXT: [[EVL_BASED_IV:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_EVL_NEXT:%.*]], [[VECTOR_BODY]] ]
; IF-EVL-NEXT: [[AVL:%.*]] = phi i64 [ 1025, [[VECTOR_PH]] ], [ [[AVL_NEXT:%.*]], [[VECTOR_BODY]] ]
-; IF-EVL-NEXT: [[TMP6:%.*]] = call i32 @llvm.experimental.get.vector.length.i64(i64 [[AVL]], i32 16, i1 true)
+; IF-EVL-NEXT: [[TMP6:%.*]] = call i32 @llvm.experimental.get.vector.length.i64(i64 [[AVL]], i32 8, i1 true)
; IF-EVL-NEXT: [[TMP10:%.*]] = sub i64 1024, [[EVL_BASED_IV]]
; IF-EVL-NEXT: [[TMP12:%.*]] = getelementptr i8, ptr [[TMP8:%.*]], i64 [[TMP10]]
; IF-EVL-NEXT: [[TMP9:%.*]] = zext i32 [[TMP6]] to i64
; IF-EVL-NEXT: [[TMP3:%.*]] = sub nuw nsw i64 [[TMP9]], 1
; IF-EVL-NEXT: [[TMP11:%.*]] = sub i64 0, [[TMP3]]
; IF-EVL-NEXT: [[TMP13:%.*]] = getelementptr i8, ptr [[TMP12]], i64 [[TMP11]]
-; IF-EVL-NEXT: [[VP_OP_LOAD:%.*]] = call <vscale x 16 x i8> @llvm.vp.load.nxv16i8.p0(ptr align 1 [[TMP13]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP6]])
-; IF-EVL-NEXT: [[VP_REVERSE:%.*]] = call <vscale x 16 x i8> @llvm.experimental.vp.reverse.nxv16i8(<vscale x 16 x i8> [[VP_OP_LOAD]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP6]])
-; IF-EVL-NEXT: [[TMP14:%.*]] = getelementptr i8, ptr [[B:%.*]], <vscale x 16 x i8> [[VP_REVERSE]]
-; IF-EVL-NEXT: [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 16 x i8> @llvm.vp.gather.nxv16i8.nxv16p0(<vscale x 16 x ptr> align 1 [[TMP14]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP6]])
+; IF-EVL-NEXT: [[VP_OP_LOAD:%.*]] = call <vscale x 8 x i8> @llvm.vp.load.nxv8i8.p0(ptr align 1 [[TMP13]], <vscale x 8 x i1> splat (i1 true), i32 [[TMP6]])
+; IF-EVL-NEXT: [[TMP7:%.*]] = call <vscale x 8 x i8> @llvm.experimental.vp.reverse.nxv8i8(<vscale x 8 x i8> [[VP_OP_LOAD]], <vscale x 8 x i1> splat (i1 true), i32 [[TMP6]])
+; IF-EVL-NEXT: [[WIDE_GEP:%.*]] = getelementptr i8, ptr [[B:%.*]], <vscale x 8 x i8> [[TMP7]]
+; IF-EVL-NEXT: [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 8 x i8> @llvm.vp.gather.nxv8i8.nxv8p0(<vscale x 8 x ptr> align 1 [[WIDE_GEP]], <vscale x 8 x i1> splat (i1 true), i32 [[TMP6]])
; IF-EVL-NEXT: [[TMP15:%.*]] = getelementptr i8, ptr [[C:%.*]], i64 [[TMP10]]
; IF-EVL-NEXT: [[TMP20:%.*]] = getelementptr i8, ptr [[TMP15]], i64 [[TMP11]]
-; IF-EVL-NEXT: [[VP_REVERSE1:%.*]] = call <vscale x 16 x i8> @llvm.experimental.vp.reverse.nxv16i8(<vscale x 16 x i8> [[WIDE_MASKED_GATHER]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP6]])
-; IF-EVL-NEXT: call void @llvm.vp.store.nxv16i8.p0(<vscale x 16 x i8> [[VP_REVERSE1]], ptr align 1 [[TMP20]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP6]])
+; IF-EVL-NEXT: [[TMP14:%.*]] = call <vscale x 8 x i8> @llvm.experimental.vp.reverse.nxv8i8(<vscale x 8 x i8> [[WIDE_MASKED_GATHER]], <vscale x 8 x i1> splat (i1 true), i32 [[TMP6]])
+; IF-EVL-NEXT: call void @llvm.vp.store.nxv8i8.p0(<vscale x 8 x i8> [[TMP14]], ptr align 1 [[TMP20]], <vscale x 8 x i1> splat (i1 true), i32 [[TMP6]])
; IF-EVL-NEXT: [[TMP16:%.*]] = getelementptr i8, ptr [[D:%.*]], i64 [[TMP10]]
; IF-EVL-NEXT: [[TMP26:%.*]] = getelementptr i8, ptr [[TMP16]], i64 [[TMP11]]
-; IF-EVL-NEXT: call void @llvm.vp.store.nxv16i8.p0(<vscale x 16 x i8> [[VP_REVERSE1]], ptr align 1 [[TMP26]], <vscale x 16 x i1> splat (i1 true), i32 [[TMP6]])
+; IF-EVL-NEXT: call void @llvm.vp.store.nxv8i8.p0(<vscale x 8 x i8> [[TMP14]], ptr align 1 [[TMP26]], <vscale x 8 x i1> splat (i1 true), i32 [[TMP6]])
; IF-EVL-NEXT: [[INDEX_EVL_NEXT]] = add nuw i64 [[TMP9]], [[EVL_BASED_IV]]
; IF-EVL-NEXT: [[AVL_NEXT]] = sub nuw i64 [[AVL]], [[TMP9]]
; IF-EVL-NEXT: [[TMP32:%.*]] = icmp eq i64 [[AVL_NEXT]], 0
More information about the llvm-commits
mailing list