[llvm-branch-commits] [llvm] 910bfcd - [VectorCombine] Fix foldBitcastOfVPLoad reordering loads (#218336)

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Aug 28 02:05:35 PDT 2026


Author: Luke Lau
Date: 2026-08-28T11:05:08+02:00
New Revision: 910bfcd7324d90b20adc2ba843d3fd661f662003

URL: https://github.com/llvm/llvm-project/commit/910bfcd7324d90b20adc2ba843d3fd661f662003
DIFF: https://github.com/llvm/llvm-project/commit/910bfcd7324d90b20adc2ba843d3fd661f662003.diff

LOG: [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)

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/VectorCombine.cpp
    llvm/test/Transforms/VectorCombine/RISCV/fold-vp-load.ll

Removed: 
    


################################################################################
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