[llvm] 38b098b - [VectorCombine] Limit scalarization known non-poison indices.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 5 07:39:52 PDT 2021
Author: Florian Hahn
Date: 2021-08-05T15:36:31+01:00
New Revision: 38b098be6605494cc7308ea9b08f920c4c3fe4ce
URL: https://github.com/llvm/llvm-project/commit/38b098be6605494cc7308ea9b08f920c4c3fe4ce
DIFF: https://github.com/llvm/llvm-project/commit/38b098be6605494cc7308ea9b08f920c4c3fe4ce.diff
LOG: [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
Added:
Modified:
llvm/lib/Transforms/Vectorize/VectorCombine.cpp
llvm/test/Transforms/VectorCombine/load-insert-store.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index d18bcd34620c..e138e890acb2 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -781,6 +781,9 @@ static bool canScalarizeAccess(FixedVectorType *VecTy, Value *Idx,
if (auto *C = dyn_cast<ConstantInt>(Idx))
return C->getValue().ult(VecTy->getNumElements());
+ if (!isGuaranteedNotToBePoison(Idx, &AC))
+ return false;
+
APInt Zero(Idx->getType()->getScalarSizeInBits(), 0);
APInt MaxElts(Idx->getType()->getScalarSizeInBits(), VecTy->getNumElements());
ConstantRange ValidIndices(Zero, MaxElts);
diff --git a/llvm/test/Transforms/VectorCombine/load-insert-store.ll b/llvm/test/Transforms/VectorCombine/load-insert-store.ll
index 93ad6e7a4a86..5c3f1659e35f 100644
--- a/llvm/test/Transforms/VectorCombine/load-insert-store.ll
+++ b/llvm/test/Transforms/VectorCombine/load-insert-store.ll
@@ -310,9 +310,10 @@ entry:
define void @insert_store_nonconst_index_known_valid_by_and_but_may_be_poison(<16 x i8>* %q, i8 zeroext %s, i32 %idx) {
; CHECK-LABEL: @insert_store_nonconst_index_known_valid_by_and_but_may_be_poison(
; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP0:%.*]] = load <16 x i8>, <16 x i8>* [[Q:%.*]], align 16
; CHECK-NEXT: [[IDX_CLAMPED:%.*]] = and i32 [[IDX:%.*]], 7
-; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds <16 x i8>, <16 x i8>* [[Q:%.*]], i32 0, i32 [[IDX_CLAMPED]]
-; CHECK-NEXT: store i8 [[S:%.*]], i8* [[TMP0]], align 1
+; CHECK-NEXT: [[VECINS:%.*]] = insertelement <16 x i8> [[TMP0]], i8 [[S:%.*]], i32 [[IDX_CLAMPED]]
+; CHECK-NEXT: store <16 x i8> [[VECINS]], <16 x i8>* [[Q]], align 16
; CHECK-NEXT: ret void
;
entry:
@@ -412,9 +413,10 @@ entry:
define void @insert_store_nonconst_index_known_valid_by_urem_but_may_be_poison(<16 x i8>* %q, i8 zeroext %s, i32 %idx) {
; CHECK-LABEL: @insert_store_nonconst_index_known_valid_by_urem_but_may_be_poison(
; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP0:%.*]] = load <16 x i8>, <16 x i8>* [[Q:%.*]], align 16
; CHECK-NEXT: [[IDX_CLAMPED:%.*]] = urem i32 [[IDX:%.*]], 16
-; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds <16 x i8>, <16 x i8>* [[Q:%.*]], i32 0, i32 [[IDX_CLAMPED]]
-; CHECK-NEXT: store i8 [[S:%.*]], i8* [[TMP0]], align 1
+; CHECK-NEXT: [[VECINS:%.*]] = insertelement <16 x i8> [[TMP0]], i8 [[S:%.*]], i32 [[IDX_CLAMPED]]
+; CHECK-NEXT: store <16 x i8> [[VECINS]], <16 x i8>* [[Q]], align 16
; CHECK-NEXT: ret void
;
entry:
More information about the llvm-commits
mailing list