[llvm] [SLP][NFCI] Address issues seen in downstream Coverity scan. (PR #93757)
Tyler Lanphear via llvm-commits
llvm-commits at lists.llvm.org
Wed May 29 17:45:20 PDT 2024
https://github.com/tylanphear created https://github.com/llvm/llvm-project/pull/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 explicit
null check.
- 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)
>From 5c14ed1f229ef5a6827a64107b0119c9d1a07b2a Mon Sep 17 00:00:00 2001
From: Tyler Lanphear <tyler.lanphear at intel.com>
Date: Wed, 29 May 2024 17:34:41 -0700
Subject: [PATCH] [SLP][NFCI] Address issues seen in downstream Coverity scan.
- 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 explicit
null check.
- 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)
---
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 2e0a39c4b4fdc..e8db98a991845 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -11700,8 +11700,7 @@ class BoUpSLP::ShuffleInstructionBuilder final : public BaseShuffleAnalysis {
R.eraseInstruction(EI);
}
if (NumParts == 1 || UniqueBases.size() == 1) {
- VecBase = castToScalarTyElem(VecBase);
- return VecBase;
+ return VecBase ? castToScalarTyElem(VecBase) : nullptr;
}
UseVecBaseAsInput = true;
auto TransformToIdentity = [](MutableArrayRef<int> Mask) {
@@ -15837,7 +15836,7 @@ bool SLPVectorizerPass::vectorizeStores(
while (true) {
++Repeat;
bool RepeatChanged = false;
- bool AnyProfitableGraph;
+ bool AnyProfitableGraph = false;
for (unsigned Size : CandidateVFs) {
AnyProfitableGraph = false;
unsigned StartIdx = std::distance(
More information about the llvm-commits
mailing list