[llvm] 19a31b2 - [VectorCombine] Fixing bitcast processing in VectorCombine (#185075)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 9 12:48:00 PDT 2026
Author: V.Rybalov
Date: 2026-03-09T12:47:56-07:00
New Revision: 19a31b27b0381d27de4d950bb1ea0a7c8c1e66e5
URL: https://github.com/llvm/llvm-project/commit/19a31b27b0381d27de4d950bb1ea0a7c8c1e66e5
DIFF: https://github.com/llvm/llvm-project/commit/19a31b27b0381d27de4d950bb1ea0a7c8c1e66e5.diff
LOG: [VectorCombine] Fixing bitcast processing in VectorCombine (#185075)
Fixing bitcast instruction processing in VectorCombine pass
that operates: arbitrary precision integer types.
Added:
llvm/test/Transforms/VectorCombine/arbitrary-precision-int.ll
Modified:
llvm/lib/Transforms/Vectorize/VectorCombine.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index 3d95fdaa9eb6d..56b40d05de9e0 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -1105,13 +1105,15 @@ bool VectorCombine::foldBitcastShuffle(Instruction &I) {
if (DestEltSize <= SrcEltSize) {
// The bitcast is from wide to narrow/equal elements. The shuffle mask can
// always be expanded to the equivalent form choosing narrower elements.
- assert(SrcEltSize % DestEltSize == 0 && "Unexpected shuffle mask");
+ if (SrcEltSize % DestEltSize != 0)
+ return false;
unsigned ScaleFactor = SrcEltSize / DestEltSize;
narrowShuffleMaskElts(ScaleFactor, Mask, NewMask);
} else {
// The bitcast is from narrow elements to wide elements. The shuffle mask
// must choose consecutive elements to allow casting first.
- assert(DestEltSize % SrcEltSize == 0 && "Unexpected shuffle mask");
+ if (DestEltSize % SrcEltSize != 0)
+ return false;
unsigned ScaleFactor = DestEltSize / SrcEltSize;
if (!widenShuffleMaskElts(ScaleFactor, Mask, NewMask))
return false;
diff --git a/llvm/test/Transforms/VectorCombine/arbitrary-precision-int.ll b/llvm/test/Transforms/VectorCombine/arbitrary-precision-int.ll
new file mode 100644
index 0000000000000..752607279cfac
--- /dev/null
+++ b/llvm/test/Transforms/VectorCombine/arbitrary-precision-int.ll
@@ -0,0 +1,19 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt < %s -passes=vector-combine -S | FileCheck %s --check-prefixes=CHECK
+; The test verifies that the optimization accepts and does not modify the instructions.
+define void @test() #0 {
+; CHECK-LABEL: define void @test() #0 {
+; CHECK-NEXT: [[V1:%.*]] = shufflevector <5 x i16> zeroinitializer, <5 x i16> poison, <10 x i32> zeroinitializer
+; CHECK-NEXT: [[V2:%.*]] = bitcast <10 x i16> [[V1]] to <4 x i40>
+; CHECK-NEXT: call void @use.vec(<4 x i40> [[V2]])
+; CHECK-NEXT: ret void
+;
+ %S = shufflevector <5 x i16> zeroinitializer, <5 x i16> poison, <10 x i32> zeroinitializer
+ %bc = bitcast <10 x i16> %S to <4 x i40>
+ call void @use.vec(<4 x i40> %bc)
+ ret void
+}
+
+declare void @use.vec(<4 x i40>)
+
+attributes #0 = { strictfp }
More information about the llvm-commits
mailing list