[llvm] [SLP][NFCI] Address issues seen in downstream Coverity scan. (PR #93757)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 29 17:46:11 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Tyler Lanphear (tylanphear)
<details>
<summary>Changes</summary>
- 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)
---
Full diff: https://github.com/llvm/llvm-project/pull/93757.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp (+2-3)
``````````diff
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(
``````````
</details>
https://github.com/llvm/llvm-project/pull/93757
More information about the llvm-commits
mailing list