[PATCH] D86989: [InstCombine] Fix a couple crahses with extractelement on a scalable vector.
Eli Friedman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 2 18:02:38 PDT 2020
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG96ef6998dfcc: [InstCombine] Fix a couple crashes with extractelement on a scalable vector. (authored by efriedma).
Changed prior to commit:
https://reviews.llvm.org/D86989?vs=289314&id=289613#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D86989/new/
https://reviews.llvm.org/D86989
Files:
llvm/lib/Analysis/ValueTracking.cpp
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/test/Transforms/InstCombine/vscale_extractelement.ll
Index: llvm/test/Transforms/InstCombine/vscale_extractelement.ll
===================================================================
--- llvm/test/Transforms/InstCombine/vscale_extractelement.ll
+++ llvm/test/Transforms/InstCombine/vscale_extractelement.ll
@@ -146,3 +146,25 @@
%4 = insertelement <vscale x 4 x i32> %3, i32 %vec.e3, i32 3
ret <vscale x 4 x i32> %4
}
+
+define i32 @bitcast_of_extractelement( <vscale x 2 x float> %d) {
+; CHECK-LABEL: @bitcast_of_extractelement(
+; CHECK-NEXT: [[BC:%.*]] = bitcast <vscale x 2 x float> [[D:%.*]] to <vscale x 2 x i32>
+; CHECK-NEXT: [[CAST:%.*]] = extractelement <vscale x 2 x i32> [[BC]], i32 0
+; CHECK-NEXT: ret i32 [[CAST]]
+;
+ %ext = extractelement <vscale x 2 x float> %d, i32 0
+ %cast = bitcast float %ext to i32
+ ret i32 %cast
+}
+
+define i1 @extractelement_is_zero(<vscale x 2 x i32> %d, i1 %b, i32 %z) {
+; CHECK-LABEL: @extractelement_is_zero(
+; CHECK-NEXT: [[EXT:%.*]] = extractelement <vscale x 2 x i32> [[D:%.*]], i32 0
+; CHECK-NEXT: [[BB:%.*]] = icmp eq i32 [[EXT]], 0
+; CHECK-NEXT: ret i1 [[BB]]
+;
+ %ext = extractelement <vscale x 2 x i32> %d, i32 0
+ %bb = icmp eq i32 %ext, 0
+ ret i1 %bb
+}
Index: llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -2224,9 +2224,7 @@
if (!VectorType::isValidElementType(DestType))
return nullptr;
- unsigned NumElts =
- cast<FixedVectorType>(ExtElt->getVectorOperandType())->getNumElements();
- auto *NewVecType = FixedVectorType::get(DestType, NumElts);
+ auto *NewVecType = VectorType::get(DestType, ExtElt->getVectorOperandType());
auto *NewBC = IC.Builder.CreateBitCast(ExtElt->getVectorOperand(),
NewVecType, "bc");
return ExtractElementInst::Create(NewBC, ExtElt->getIndexOperand());
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -2568,11 +2568,13 @@
const Value *Vec = EEI->getVectorOperand();
const Value *Idx = EEI->getIndexOperand();
auto *CIdx = dyn_cast<ConstantInt>(Idx);
- unsigned NumElts = cast<FixedVectorType>(Vec->getType())->getNumElements();
- APInt DemandedVecElts = APInt::getAllOnesValue(NumElts);
- if (CIdx && CIdx->getValue().ult(NumElts))
- DemandedVecElts = APInt::getOneBitSet(NumElts, CIdx->getZExtValue());
- return isKnownNonZero(Vec, DemandedVecElts, Depth, Q);
+ if (auto *VecTy = dyn_cast<FixedVectorType>(Vec->getType())) {
+ unsigned NumElts = VecTy->getNumElements();
+ APInt DemandedVecElts = APInt::getAllOnesValue(NumElts);
+ if (CIdx && CIdx->getValue().ult(NumElts))
+ DemandedVecElts = APInt::getOneBitSet(NumElts, CIdx->getZExtValue());
+ return isKnownNonZero(Vec, DemandedVecElts, Depth, Q);
+ }
}
KnownBits Known(BitWidth);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86989.289613.patch
Type: text/x-patch
Size: 3091 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200903/a44cf2cd/attachment.bin>
More information about the llvm-commits
mailing list