[llvm] [VectorCombine] Fix foldBitcastOfVPLoad reordering loads (PR #218336)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 24 00:17:04 PDT 2026
https://github.com/lukel97 created https://github.com/llvm/llvm-project/pull/218336
We were inserting the new vp.load where the bitcast was, which would
reorder loads. This should hopefully fix RISC-V buildbot failures that
were exposed after 93ac788df8ff
>From ab36263bf4204632ce9058fa94d4ee5e2184d734 Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Mon, 24 Aug 2026 15:04:17 +0800
Subject: [PATCH 1/2] Precommit test
---
.../Transforms/VectorCombine/RISCV/fold-vp-load.ll | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/llvm/test/Transforms/VectorCombine/RISCV/fold-vp-load.ll b/llvm/test/Transforms/VectorCombine/RISCV/fold-vp-load.ll
index 066ce0484b737..02639e2f65dd1 100644
--- a/llvm/test/Transforms/VectorCombine/RISCV/fold-vp-load.ll
+++ b/llvm/test/Transforms/VectorCombine/RISCV/fold-vp-load.ll
@@ -84,3 +84,17 @@ define <vscale x 32 x i1> @bitcast_vp_load_i1(ptr %p) {
%r = bitcast <vscale x 4 x i8> %l to <vscale x 32 x i1>
ret <vscale x 32 x i1> %r
}
+
+; Make sure we create the new vp.load in the same place
+define <vscale x 8 x i16> @bitcast_vp_load_insertpoint(ptr %p) {
+; CHECK-LABEL: define <vscale x 8 x i16> @bitcast_vp_load_insertpoint(
+; CHECK-SAME: ptr [[P:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT: store i32 0, ptr [[P]], align 4
+; CHECK-NEXT: [[R:%.*]] = call <vscale x 8 x i16> @llvm.vp.load.nxv8i16.p0(ptr align 16 [[P]], <vscale x 8 x i1> splat (i1 true), i32 4)
+; CHECK-NEXT: ret <vscale x 8 x i16> [[R]]
+;
+ %l = call <vscale x 4 x i32> @llvm.vp.load(ptr %p, <vscale x 4 x i1> splat (i1 true), i32 2)
+ store i32 0, ptr %p
+ %r = bitcast <vscale x 4 x i32> %l to <vscale x 8 x i16>
+ ret <vscale x 8 x i16> %r
+}
>From c1c3d5dc77958e676429b541060ccde82e5cd4ab Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Mon, 24 Aug 2026 15:13:43 +0800
Subject: [PATCH 2/2] [VectorCombine] Fix foldBitcastOfVPLoad reordering loads
We were inserting the new vp.load where the bitcast was, which would
reorder loads. This should hopefully fix RISC-V buildbot failures that
were exposed after 93ac788df8ff
---
llvm/lib/Transforms/Vectorize/VectorCombine.cpp | 1 +
llvm/test/Transforms/VectorCombine/RISCV/fold-vp-load.ll | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index 6d1ee34d8be8b..6b9d8791ba35e 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -6473,6 +6473,7 @@ bool VectorCombine::foldBitcastOfVPLoad(Instruction &I) {
if (NewCost > OldCost || !NewCost.isValid())
return false;
+ Builder.SetInsertPoint(II);
unsigned Factor = NewVecCnt.getKnownScalarFactor(OrigVecCnt);
Value *NewEVL = Builder.CreateNUWMul(EVL, Builder.getInt32(Factor));
Value *NewMask = Builder.CreateVectorSplat(NewVecCnt, Builder.getTrue());
diff --git a/llvm/test/Transforms/VectorCombine/RISCV/fold-vp-load.ll b/llvm/test/Transforms/VectorCombine/RISCV/fold-vp-load.ll
index 02639e2f65dd1..f94501d179740 100644
--- a/llvm/test/Transforms/VectorCombine/RISCV/fold-vp-load.ll
+++ b/llvm/test/Transforms/VectorCombine/RISCV/fold-vp-load.ll
@@ -89,8 +89,8 @@ define <vscale x 32 x i1> @bitcast_vp_load_i1(ptr %p) {
define <vscale x 8 x i16> @bitcast_vp_load_insertpoint(ptr %p) {
; CHECK-LABEL: define <vscale x 8 x i16> @bitcast_vp_load_insertpoint(
; CHECK-SAME: ptr [[P:%.*]]) #[[ATTR0]] {
-; CHECK-NEXT: store i32 0, ptr [[P]], align 4
; CHECK-NEXT: [[R:%.*]] = call <vscale x 8 x i16> @llvm.vp.load.nxv8i16.p0(ptr align 16 [[P]], <vscale x 8 x i1> splat (i1 true), i32 4)
+; CHECK-NEXT: store i32 0, ptr [[P]], align 4
; CHECK-NEXT: ret <vscale x 8 x i16> [[R]]
;
%l = call <vscale x 4 x i32> @llvm.vp.load(ptr %p, <vscale x 4 x i1> splat (i1 true), i32 2)
More information about the llvm-commits
mailing list