Skip to content

Commit d337c50

Browse files
authored
[SLP][NFCI] Address issues seen in downstream Coverity scan. (#93757)
- Prevent null dereference: if the Mask given to `ShuffleInstructionBuilder::adjustExtracts()` is empty or all-poison, then `VecBase` will be `nullptr` and the call to `castToScalarTyElem(VecBase)` will dereference it. Add an assert to guard against this. - Prevent use of uninitialized scalar: in the unlikely event that `CandidateVFs` is empty, then `AnyProfitableGraph` will be uninitialized in `if` condition following the loop. (This seems like a false-positive, but I submitted this change anyways as initializing bools costs nothing and is generally good practice)
1 parent 1697030 commit d337c50

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11697,8 +11697,8 @@ class BoUpSLP::ShuffleInstructionBuilder final : public BaseShuffleAnalysis {
1169711697
R.eraseInstruction(EI);
1169811698
}
1169911699
if (NumParts == 1 || UniqueBases.size() == 1) {
11700-
VecBase = castToScalarTyElem(VecBase);
11701-
return VecBase;
11700+
assert(VecBase && "Expected vectorized value.");
11701+
return castToScalarTyElem(VecBase);
1170211702
}
1170311703
UseVecBaseAsInput = true;
1170411704
auto TransformToIdentity = [](MutableArrayRef<int> Mask) {
@@ -15844,7 +15844,7 @@ bool SLPVectorizerPass::vectorizeStores(
1584415844
while (true) {
1584515845
++Repeat;
1584615846
bool RepeatChanged = false;
15847-
bool AnyProfitableGraph;
15847+
bool AnyProfitableGraph = false;
1584815848
for (unsigned Size : CandidateVFs) {
1584915849
AnyProfitableGraph = false;
1585015850
unsigned StartIdx = std::distance(

0 commit comments

Comments
 (0)