[llvm] 958e37c - [VectorCombine] scalarizeBinopOrCmp - check for out of bounds element indices
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 9 08:02:33 PST 2024
Author: Simon Pilgrim
Date: 2024-11-09T16:00:03Z
New Revision: 958e37cd1feabf29fb1cc3fb5ac82051ad8d43eb
URL: https://github.com/llvm/llvm-project/commit/958e37cd1feabf29fb1cc3fb5ac82051ad8d43eb
DIFF: https://github.com/llvm/llvm-project/commit/958e37cd1feabf29fb1cc3fb5ac82051ad8d43eb.diff
LOG: [VectorCombine] scalarizeBinopOrCmp - check for out of bounds element indices
Fixes #115575
Added:
Modified:
llvm/lib/Transforms/Vectorize/VectorCombine.cpp
llvm/test/Transforms/VectorCombine/X86/pr115575.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index 04ea12ef0f1221..b8754b03c2ebc6 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -952,6 +952,12 @@ bool VectorCombine::scalarizeBinopOrCmp(Instruction &I) {
if (!IsConst0 && !IsConst1 && Index0 != Index1)
return false;
+ auto *VecTy0 = cast<VectorType>(Ins0->getType());
+ auto *VecTy1 = cast<VectorType>(Ins1->getType());
+ if (VecTy0->getElementCount().getKnownMinValue() <= Index0 ||
+ VecTy1->getElementCount().getKnownMinValue() <= Index1)
+ return false;
+
// Bail for single insertion if it is a load.
// TODO: Handle this once getVectorInstrCost can cost for load/stores.
auto *I0 = dyn_cast_or_null<Instruction>(V0);
diff --git a/llvm/test/Transforms/VectorCombine/X86/pr115575.ll b/llvm/test/Transforms/VectorCombine/X86/pr115575.ll
index 8e8bb808324e12..dd8e27727dd3c0 100644
--- a/llvm/test/Transforms/VectorCombine/X86/pr115575.ll
+++ b/llvm/test/Transforms/VectorCombine/X86/pr115575.ll
@@ -4,8 +4,8 @@
define <2 x i8> @PR115575(i8 %x) {
; CHECK-LABEL: define <2 x i8> @PR115575(
; CHECK-SAME: i8 [[X:%.*]]) {
-; CHECK-NEXT: [[BO_SCALAR:%.*]] = sdiv i8 [[X]], poison
-; CHECK-NEXT: [[BO:%.*]] = insertelement <2 x i8> poison, i8 [[BO_SCALAR]], i64 3
+; CHECK-NEXT: [[INS:%.*]] = insertelement <2 x i8> poison, i8 [[X]], i32 3
+; CHECK-NEXT: [[BO:%.*]] = sdiv <2 x i8> [[INS]], <i8 5, i8 2>
; CHECK-NEXT: ret <2 x i8> [[BO]]
;
%ins = insertelement <2 x i8> poison, i8 %x, i32 3
More information about the llvm-commits
mailing list