Skip to content

Commit 958e37c

Browse files
committed
[VectorCombine] scalarizeBinopOrCmp - check for out of bounds element indices
Fixes #115575
1 parent 6fb2a60 commit 958e37c

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,12 @@ bool VectorCombine::scalarizeBinopOrCmp(Instruction &I) {
952952
if (!IsConst0 && !IsConst1 && Index0 != Index1)
953953
return false;
954954

955+
auto *VecTy0 = cast<VectorType>(Ins0->getType());
956+
auto *VecTy1 = cast<VectorType>(Ins1->getType());
957+
if (VecTy0->getElementCount().getKnownMinValue() <= Index0 ||
958+
VecTy1->getElementCount().getKnownMinValue() <= Index1)
959+
return false;
960+
955961
// Bail for single insertion if it is a load.
956962
// TODO: Handle this once getVectorInstrCost can cost for load/stores.
957963
auto *I0 = dyn_cast_or_null<Instruction>(V0);

llvm/test/Transforms/VectorCombine/X86/pr115575.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
define <2 x i8> @PR115575(i8 %x) {
55
; CHECK-LABEL: define <2 x i8> @PR115575(
66
; CHECK-SAME: i8 [[X:%.*]]) {
7-
; CHECK-NEXT: [[BO_SCALAR:%.*]] = sdiv i8 [[X]], poison
8-
; CHECK-NEXT: [[BO:%.*]] = insertelement <2 x i8> poison, i8 [[BO_SCALAR]], i64 3
7+
; CHECK-NEXT: [[INS:%.*]] = insertelement <2 x i8> poison, i8 [[X]], i32 3
8+
; CHECK-NEXT: [[BO:%.*]] = sdiv <2 x i8> [[INS]], <i8 5, i8 2>
99
; CHECK-NEXT: ret <2 x i8> [[BO]]
1010
;
1111
%ins = insertelement <2 x i8> poison, i8 %x, i32 3

0 commit comments

Comments
 (0)