[llvm-branch-commits] [llvm] release/23.x: [VectorCombine] Fix foldBitcastOfVPLoad reordering loads (#218336) (PR #218343)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Aug 24 01:15:28 PDT 2026
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/218343
Backport 2eda652e5cd7d70de8dd4f33a7cece6b70465163
Requested by: @lukel97
>From 0ad2233b176bc3961ab57ae88b92198b6c5902de Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Mon, 24 Aug 2026 16:07:49 +0800
Subject: [PATCH] [VectorCombine] Fix foldBitcastOfVPLoad reordering loads
(#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
(cherry picked from commit 2eda652e5cd7d70de8dd4f33a7cece6b70465163)
---
llvm/lib/Transforms/Vectorize/VectorCombine.cpp | 1 +
.../Transforms/VectorCombine/RISCV/fold-vp-load.ll | 14 ++++++++++++++
2 files changed, 15 insertions(+)
diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index 8648125222e2a..a1dc1b4e954c8 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -6099,6 +6099,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 066ce0484b737..f94501d179740 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: [[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)
+ 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
+}
More information about the llvm-branch-commits
mailing list