Skip to content

Commit 38b098b

Browse files
committed
[VectorCombine] Limit scalarization known non-poison indices.
We can only trust the range of the index if it is guaranteed non-poison. Fixes PR50949. Reviewed By: lebedev.ri Differential Revision: https://reviews.llvm.org/D107364
1 parent 06206a8 commit 38b098b

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,9 @@ static bool canScalarizeAccess(FixedVectorType *VecTy, Value *Idx,
781781
if (auto *C = dyn_cast<ConstantInt>(Idx))
782782
return C->getValue().ult(VecTy->getNumElements());
783783

784+
if (!isGuaranteedNotToBePoison(Idx, &AC))
785+
return false;
786+
784787
APInt Zero(Idx->getType()->getScalarSizeInBits(), 0);
785788
APInt MaxElts(Idx->getType()->getScalarSizeInBits(), VecTy->getNumElements());
786789
ConstantRange ValidIndices(Zero, MaxElts);

llvm/test/Transforms/VectorCombine/load-insert-store.ll

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,10 @@ entry:
310310
define void @insert_store_nonconst_index_known_valid_by_and_but_may_be_poison(<16 x i8>* %q, i8 zeroext %s, i32 %idx) {
311311
; CHECK-LABEL: @insert_store_nonconst_index_known_valid_by_and_but_may_be_poison(
312312
; CHECK-NEXT: entry:
313+
; CHECK-NEXT: [[TMP0:%.*]] = load <16 x i8>, <16 x i8>* [[Q:%.*]], align 16
313314
; CHECK-NEXT: [[IDX_CLAMPED:%.*]] = and i32 [[IDX:%.*]], 7
314-
; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds <16 x i8>, <16 x i8>* [[Q:%.*]], i32 0, i32 [[IDX_CLAMPED]]
315-
; CHECK-NEXT: store i8 [[S:%.*]], i8* [[TMP0]], align 1
315+
; CHECK-NEXT: [[VECINS:%.*]] = insertelement <16 x i8> [[TMP0]], i8 [[S:%.*]], i32 [[IDX_CLAMPED]]
316+
; CHECK-NEXT: store <16 x i8> [[VECINS]], <16 x i8>* [[Q]], align 16
316317
; CHECK-NEXT: ret void
317318
;
318319
entry:
@@ -412,9 +413,10 @@ entry:
412413
define void @insert_store_nonconst_index_known_valid_by_urem_but_may_be_poison(<16 x i8>* %q, i8 zeroext %s, i32 %idx) {
413414
; CHECK-LABEL: @insert_store_nonconst_index_known_valid_by_urem_but_may_be_poison(
414415
; CHECK-NEXT: entry:
416+
; CHECK-NEXT: [[TMP0:%.*]] = load <16 x i8>, <16 x i8>* [[Q:%.*]], align 16
415417
; CHECK-NEXT: [[IDX_CLAMPED:%.*]] = urem i32 [[IDX:%.*]], 16
416-
; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds <16 x i8>, <16 x i8>* [[Q:%.*]], i32 0, i32 [[IDX_CLAMPED]]
417-
; CHECK-NEXT: store i8 [[S:%.*]], i8* [[TMP0]], align 1
418+
; CHECK-NEXT: [[VECINS:%.*]] = insertelement <16 x i8> [[TMP0]], i8 [[S:%.*]], i32 [[IDX_CLAMPED]]
419+
; CHECK-NEXT: store <16 x i8> [[VECINS]], <16 x i8>* [[Q]], align 16
418420
; CHECK-NEXT: ret void
419421
;
420422
entry:

0 commit comments

Comments
 (0)