Skip to content

[SLP][NFCI] Address issues seen in downstream Coverity scan. #93757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 1, 2024

Conversation

tylanphear
Copy link
Contributor

@tylanphear tylanphear commented May 30, 2024

  • 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)

- 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)
@llvmbot
Copy link
Member

llvmbot commented May 30, 2024

@llvm/pr-subscribers-llvm-transforms

Author: Tyler Lanphear (tylanphear)

Changes
  • 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 --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(

Copy link
Member

@alexey-bataev alexey-bataev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

@tylanphear tylanphear merged commit d337c50 into llvm:main Jun 1, 2024
7 checks passed
@tylanphear tylanphear deleted the minor_slp_coverity_fixes branch June 1, 2024 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants