Skip to content

Conversation

@gchaltas
Copy link
Contributor

Setting unitialized pointers to nullptr in InnerLoopVectorizer() constructor. These were noticed during a review of the code. Seems like a good idea to clean them up.

Setting unitialized pointers to nullptr in InnerLoopVectorizer() constructor
@llvmbot
Copy link
Member

llvmbot commented May 13, 2025

@llvm/pr-subscribers-llvm-transforms

Author: George Chaltas (gchaltas)

Changes

Setting unitialized pointers to nullptr in InnerLoopVectorizer() constructor. These were noticed during a review of the code. Seems like a good idea to clean them up.


Full diff: https://github.com/llvm/llvm-project/pull/139807.diff

1 Files Affected:

  • (modified) llvm/lib/Transforms/Vectorize/LoopVectorize.cpp (+3-3)
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index d04fea5d9b0ac..742ef585cb1f7 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -603,13 +603,13 @@ class InnerLoopVectorizer {
   // --- Vectorization state ---
 
   /// The vector-loop preheader.
-  BasicBlock *LoopVectorPreHeader;
+  BasicBlock *LoopVectorPreHeader = nullptr;
 
   /// The scalar-loop preheader.
-  BasicBlock *LoopScalarPreHeader;
+  BasicBlock *LoopScalarPreHeader = nullptr;
 
   /// Middle Block between the vector and the scalar.
-  BasicBlock *LoopMiddleBlock;
+  BasicBlock *LoopMiddleBlock = nullptr;
 
   /// A list of all bypass blocks. The first block is the entry of the loop.
   SmallVector<BasicBlock *, 4> LoopBypassBlocks;

@llvmbot
Copy link
Member

llvmbot commented May 13, 2025

@llvm/pr-subscribers-vectorizers

Author: George Chaltas (gchaltas)

Changes

Setting unitialized pointers to nullptr in InnerLoopVectorizer() constructor. These were noticed during a review of the code. Seems like a good idea to clean them up.


Full diff: https://github.com/llvm/llvm-project/pull/139807.diff

1 Files Affected:

  • (modified) llvm/lib/Transforms/Vectorize/LoopVectorize.cpp (+3-3)
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index d04fea5d9b0ac..742ef585cb1f7 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -603,13 +603,13 @@ class InnerLoopVectorizer {
   // --- Vectorization state ---
 
   /// The vector-loop preheader.
-  BasicBlock *LoopVectorPreHeader;
+  BasicBlock *LoopVectorPreHeader = nullptr;
 
   /// The scalar-loop preheader.
-  BasicBlock *LoopScalarPreHeader;
+  BasicBlock *LoopScalarPreHeader = nullptr;
 
   /// Middle Block between the vector and the scalar.
-  BasicBlock *LoopMiddleBlock;
+  BasicBlock *LoopMiddleBlock = nullptr;
 
   /// A list of all bypass blocks. The first block is the entry of the loop.
   SmallVector<BasicBlock *, 4> LoopBypassBlocks;

@gchaltas
Copy link
Contributor Author

gchaltas commented May 13, 2025

@fhahn would you please review this and merge if you find it appropriate?

Copy link
Contributor

@david-arm david-arm left a comment

Choose a reason for hiding this comment

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

LGTM!


/// Middle Block between the vector and the scalar.
BasicBlock *LoopMiddleBlock;
BasicBlock *LoopMiddleBlock = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a nice fix! An alternative might be to disable the default constructor by adding

  InnerLoopVectorizer() = delete;

and then forcing the existing InnerLoopVectorizer constructor to explicitly set LoopVectorPreHeader, etc. to nullptr, as well as others such as AddedSafetyChecks? That way all the sensible defaults are being set in the same place. Any thoughts @fhahn?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, the default constructor should not be used.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I was just wondering if it was worth enforcing this by explicitly removing the default constructor. At the moment it feels more like an unwritten rule, although in practice it's probably not the sort of class that's going to be used frequently elsewhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

For most it is probably not worth the trouble, as it isn't expose outside LoopVectorize.cpp, and things are going to get removed gradually.

Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

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

LGTM, thanks.

@gchaltas do you need help merging the PR?

Would be good to adjust the title to be a bit more descriptive, maybe something like [LV] Initialize IR block pointers in ILV. (NFC)


/// Middle Block between the vector and the scalar.
BasicBlock *LoopMiddleBlock;
BasicBlock *LoopMiddleBlock = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, the default constructor should not be used.

@gchaltas
Copy link
Contributor Author

@fhahn Yes please. I don't have privileges to merge. I adjusted the title per your suggestion - thank you!

@gchaltas gchaltas changed the title LoopVectorize ptr init [LV] Initialize IR block pointers in ILV. (NFC) May 14, 2025
@fhahn fhahn merged commit c4f7ab1 into llvm:main May 15, 2025
14 checks passed
@gchaltas gchaltas deleted the LoopVectorize_init_ptr_cleanup branch May 19, 2025 16:28
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