Skip to content

[SLPVectorizer] Clear TreeEntryToStridedPtrInfoMap.#160544

Merged
mgudim merged 6 commits into
llvm:mainfrom
mgudim:clear_map
Sep 30, 2025
Merged

[SLPVectorizer] Clear TreeEntryToStridedPtrInfoMap.#160544
mgudim merged 6 commits into
llvm:mainfrom
mgudim:clear_map

Conversation

@mgudim

@mgudim mgudim commented Sep 24, 2025

Copy link
Copy Markdown
Contributor

We need to clear TreeEntryToStridedPtrInfoMap in deleteTree.

@llvmbot

llvmbot commented Sep 24, 2025

Copy link
Copy Markdown
Member

@llvm/pr-subscribers-backend-risc-v
@llvm/pr-subscribers-vectorizers

@llvm/pr-subscribers-llvm-transforms

Author: Mikhail Gudim (mgudim)

Changes

We need to clear TreeEntryToStridedPtrInfoMap in deleteTree.


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

1 Files Affected:

  • (modified) llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp (+1)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 1814d9a6811c0..39530e92e692d 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -2099,6 +2099,7 @@ class BoUpSLP {
     UserIgnoreList = nullptr;
     PostponedGathers.clear();
     ValueToGatherNodes.clear();
+    TreeEntryToStridedPtrInfoMap.clear();
   }
 
   unsigned getTreeSize() const { return VectorizableTree.size(); }

@alexey-bataev alexey-bataev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The test is required. Or revert the original commit and fix it there

@mgudim

mgudim commented Sep 25, 2025

Copy link
Copy Markdown
Contributor Author

The test is required. Or revert the original commit and fix it there

What kind of test should it be?

Reverting seems more complicated because several other merged commits were based on this one.

@alexey-bataev

Copy link
Copy Markdown
Member

The one that reveals the issue with not clearing the map

@mgudim

mgudim commented Sep 25, 2025

Copy link
Copy Markdown
Contributor Author

The one that reveals the issue with not clearing the map

The issue would be revealed only if we use the same BoUpSLP and when building a tree some memory is reused for a TreeNode. I don't see a way to set this up except a unit test and even that would be non-trivial. There is no test for any of lines is deleteTree as far as I see.

Should I start a new test in unittests to test SLPVectrorizer?

@alexey-bataev

Copy link
Copy Markdown
Member

The one that reveals the issue with not clearing the map

The issue would be revealed only if we use the same BoUpSLP and when building a tree some memory is reused for a TreeNode. I don't see a way to set this up except a unit test and even that would be non-trivial. There is no test for any of lines is deleteTree as far as I see.

Should I start a new test in unittests to test SLPVectrorizer?

Up to you, it can be a unittest or a lit test, that crashes for you.

@mgudim

mgudim commented Sep 25, 2025

Copy link
Copy Markdown
Contributor Author

Up to you, it can be a unittest or a lit test, that crashes for you.

Would it be ok that in a different commit I'll add asserts in "buildTree" that make sure everything from deleteTree is empty except TreeEntryToStridedPtrInfoMap. In this commit I'll add the assert and clear for the TreeEntryToStridedPtrInfoMap. This way it's a test every time buildTree is called!

@alexey-bataev

Copy link
Copy Markdown
Member

Ok, but still need a test

@mgudim

mgudim commented Sep 26, 2025

Copy link
Copy Markdown
Contributor Author

Why do we need a test if we have asserts? Don't asserts make it self-evident that the map is cleared? The test would essentially be the same this as an assert, just much more effort to set up.

@alexey-bataev

Copy link
Copy Markdown
Member

Each non-nfc patch requires a test

@mgudim

mgudim commented Sep 26, 2025

Copy link
Copy Markdown
Contributor Author

I am out of ideas.

I don't see how to add asserts to the code so it doesn't look stupid. Current code is like this:

"buildTree(...) {
deleteTree(...);
...
buildTreeRec(...)
}
"
adding asserts after deleteTree is like this code:

int x = 2;
assert (x == 2);

I thought that maybe I can set up a unit test. There is no public header to include which would contain BoUpSLP.

Constructing test by hand to try to make SLP crash is very hard.

There won't be a memory leak because the map gets deleted automatically with BoUpSLP object so setting up some kind of valgrind - based test is also not an option.

I can measure the size of BoUpSLP object right after it's created and right after deleteTree and assert that they are equal. Test would check that the assert is not hit. Will this be acceptable?

Can you suggest something else?

@mgudim

mgudim commented Sep 26, 2025

Copy link
Copy Markdown
Contributor Author

Each non-nfc patch requires a test

Is this an official rule written somewhere? I'm pretty sure that any reasonable guidelines would allow merging something like this without a test.

@mgudim mgudim requested a review from HanKuanChen September 29, 2025 15:46
@mgudim

mgudim commented Sep 29, 2025

Copy link
Copy Markdown
Contributor Author

I can measure the size of BoUpSLP object right after it's created and right after deleteTree and assert that they are equal. Test would check that the assert is not hit. Will this be acceptable?

ping

@alexey-bataev

Copy link
Copy Markdown
Member

Just add a test that crahes

@mgudim

mgudim commented Sep 29, 2025

Copy link
Copy Markdown
Contributor Author

I can't come up with a test that crashes

@alexey-bataev

Copy link
Copy Markdown
Member

Simple test that crashes with the assertion but without clearing the map

@mgudim

mgudim commented Sep 29, 2025

Copy link
Copy Markdown
Contributor Author

sorry, I don't understand what you mean. If I add an assertion somewhere that map is not cleared, it will break llvm for everyone until the commit which clears the map is merged

@alexey-bataev

Copy link
Copy Markdown
Member

I understand it. Just add a new test, that will crash with assertion but without clearing.

@mgudim

mgudim commented Sep 29, 2025

Copy link
Copy Markdown
Contributor Author

I understand it. Just add a new test, that will crash with assertion but without clearing.

Is this what you mean:

#161227

@github-actions

github-actions Bot commented Sep 29, 2025

Copy link
Copy Markdown

✅ With the latest revision this PR passed the C/C++ code formatter.

Comment thread llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp Outdated
@@ -0,0 +1,74 @@
; RUN: opt -S --passes=slp-vectorizer < %s | FileCheck %s

; CHECK-NOT: TreeEntryToStridedPtrInfoMap is not cleared

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add real checks here

Mikhail Gudim added 3 commits September 29, 2025 10:59
@mgudim mgudim merged commit e485d5e into llvm:main Sep 30, 2025
9 checks passed
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Oct 3, 2025
We need to clear `TreeEntryToStridedPtrInfoMap` in `deleteTree`.
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.

3 participants