Skip to content

Commit 926ccfe

Browse files
committed
[SLP] ScalarizationOverheadBuilder - demand all elements for scalarization if the extraction index is unknown / out of bounds
Workaround for a chromium bug reported on D134605 - test case will be added later
1 parent 4f4c44c commit 926ccfe

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5805,24 +5805,32 @@ class ScalarizationOverheadBuilder {
58055805
public:
58065806
/// Add an extraction from a specific source and element index.
58075807
void addExtract(Value *Src, unsigned Idx) {
5808+
auto *Ty = cast<FixedVectorType>(Src->getType());
5809+
unsigned NumElts = Ty->getNumElements();
58085810
if (m_ExtractsByClass.count(Src)) {
5809-
m_ExtractsByClass[Src].setBit(Idx);
5811+
if (Idx < NumElts)
5812+
m_ExtractsByClass[Src].setBit(Idx);
5813+
else
5814+
m_ExtractsByClass[Src].setAllBits();
58105815
return;
58115816
}
5812-
auto *Ty = cast<FixedVectorType>(Src->getType());
5813-
unsigned NumElts = Ty->getNumElements();
5814-
m_ExtractsByClass[Src] = APInt::getOneBitSet(NumElts, Idx);
5817+
m_ExtractsByClass[Src] = Idx < NumElts ? APInt::getOneBitSet(NumElts, Idx)
5818+
: APInt::getAllOnes(NumElts);
58155819
}
58165820

58175821
/// Add an extraction from a vector type and specific element index.
58185822
/// We assume that all extractions from a given type are from the same source.
58195823
void addExtract(FixedVectorType *VecTy, unsigned Idx) {
5824+
unsigned NumElts = VecTy->getNumElements();
58205825
if (m_ExtractsByType.count(VecTy)) {
5821-
m_ExtractsByType[VecTy].setBit(Idx);
5826+
if (Idx < NumElts)
5827+
m_ExtractsByType[VecTy].setBit(Idx);
5828+
else
5829+
m_ExtractsByType[VecTy].setAllBits();
58225830
return;
58235831
}
5824-
unsigned NumElts = VecTy->getNumElements();
5825-
m_ExtractsByType[VecTy] = APInt::getOneBitSet(NumElts, Idx);
5832+
m_ExtractsByType[VecTy] = Idx < NumElts ? APInt::getOneBitSet(NumElts, Idx)
5833+
: APInt::getAllOnes(NumElts);
58265834
}
58275835

58285836
/// Add an extended extraction from a specific source and element index.

0 commit comments

Comments
 (0)