-
Couldn't load subscription status.
- Fork 6.1k
8312332: C2: Refactor SWPointer out from SuperWord #15013
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
Conversation
As discussed in JDK-8308994, we should first do some refactoring work before proceeding with the new post loop vectorization. In this patch, we have done the following. 1) We have created new C2 source files `vectorization.[cpp|hpp]` for shared logics and utilities for C2's auto-vectorization. So far we have moved class `SWPointer` and `VectorElementSizeStats` here from `superword.[cpp|hpp]`. 2) We have decoupled `SWPointer` from class `SuperWord` and renamed it to `VPointer` as it will be used by vectorizers other than SuperWord. The original class `SWPointer` and its inner class `Tracer` both have a `_slp` field initialized in their constructors. In this patch, we have replaced them by other fields and re-written the constructors for the same functionality. Original `SWPointer::invariant()` calls function `SuperWord::find_pre_loop_end()` for loop invariant checks. To help decoupling, we moved function `find_pre_loop_end()` to class `CountedLoopNode`. As function `SWPointer::Tracer::invariant_1()` is tightly coupled with `SuperWord` but only prints some debug messages, we temporarily removed it in this patch. We will consider adding it back after later refactoring of `SuperWord` so we added a `TODO` at its call site in this patch. 3) We have a lot of memory phi node checks in loop optimizations. So we added a utility function `is_memory_phi()` in `node.hpp`. Tested tier1~3 on x86 and AArch64. Also manually verified that option `VectorizeDebug` in compiler directives still works well.
|
👋 Welcome back pli! A progress list of the required criteria for merging this PR into |
Webrevs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pfustc Thanks a lot for moving this code, and especially for untangling it from SuperWord. This will be helpful for many future vectorization projects.
I left a few comments, but otherwise this looks straight-forward and good to me.
|
|
||
| bool VPointer::invariant(Node* n) const { | ||
| NOT_PRODUCT(Tracer::Depth dd;) | ||
| // TODO: Add more trace output for invariant check after later refactoring |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We generally don't like TODOs in the code. Best is to just drop it in the code and file an RFE if you think it is really important.
When did this even trace anything?
_slp->_lpt->is_member(_slp->_phase->get_loop(n_c)) != (int)_slp->in_bb(n)
Do you think this tracing is relevant enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it should never happen: can we add an assert somewhere instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know when this can happen. This was added in jdk9 without a test case. If this can happen, it should be in some real corner cases. But definitely, the trace message is not important and it's safe to drop that. TODO is removed in my latest commit.
| if (pre_loop_end != nullptr) { | ||
| Node* n_c = phase()->get_ctrl(n); | ||
| return phase()->is_dominator(n_c, pre_loop_end->loopnode()); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is pre_loop_end != nullptr possible here? Before your patch we always found _slp->pre_loop_head().
I'm just worried that if we do not find it, then we still return is_not_member, but n is still located in the space between pre and post loop.
What do you think about this?
And: would it make sense to cache the pre_loop_head in the VPointer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I have found that pre_loop_end could be null when we construct VPointer in SuperWord::output() - see the code in superword.cpp (L2574, L2580). It's null because CountedLoopNode::is_canonical_loop_entry() returns null at this time. Before my patch, it cannot be null as we cached _pre_loop_end in the SuperWord class. To address your concern, my latest commit moves the cache of _pre_loop_end from SuperWord to CountedLoopNode. Some more asserts are also added to make sure it's used for main loops only. (Caching it in VPointer doesn't help).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain a bit more why CountedLoopNode::is_canonical_loop_entry() returned null at the time, and why you did move the caching?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the comment before function CountedLoopNode::is_canonical_loop_entry() explains that. I quote it below.
// Check the shape of the graph at the loop entry. In some cases,
// the shape of the graph does not match the shape outlined below.
// That is caused by the Opaque1 node "protecting" the shape of
// the graph being removed by, for example, the IGVN performed
// in PhaseIdealLoop::build_and_optimize().
//
// After the Opaque1 node has been removed, optimizations (e.g., split-if,
// loop unswitching, and IGVN, or a combination of them) can freely change
// the graph's shape. As a result, the graph shape outlined below cannot
// be guaranteed anymore.
Node* CountedLoopNode::is_canonical_loop_entry() {
Moving the caching is just to address your above concern that we still return is_not_member when pre_loop_end is null. Before my patch, it cannot be null as we cached _pre_loop_end in the SuperWord class. But after decoupling, we cannot access the cache in the SuperWord class anymore.
| #endif | ||
| _nstack(nstack), _analyze_only(analyze_only), _stack_idx(0) | ||
| #ifndef PRODUCT | ||
| , _tracer((phase->C->directive()->VectorizeDebugOption & 2) > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also refactor the accessors for VectorizeDebugOption. I would move it from SuperWord to vectorization.hpp/cpp somehow. We should only do the "masking" & 2 in one single place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but doing this requires moving more handles including phase to vectorization.hpp/cpp. Perhaps we need to create a new class there first. I have created another task (https://bugs.openjdk.org/browse/JDK-8315361) and would like to do more refactoring later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, we can do that refactoring later.
| int VPointer::Tracer::_depth = 0; | ||
| #endif | ||
|
|
||
| VPointer::VPointer(MemNode* mem, PhaseIdealLoop* phase, IdealLoopTree* lpt, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also call it LPointer or LoopPointer. VPointer sounds like VectorPointer - but it is not a pointer of a vector but a scalar memop. That could be confusing. But you could also argue it is a VectorizationPointer, and hence VPointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea is keeping the name as short as possible. I think it should be VectorizationPointer so VPointer. In my opinion, LoopPointer also sounds like a pointer to a loop but it isn't. I'd like to have more suggestions from other reviewers about the name.
BTW: VPointer is also used for vector memop in SuperWord::output().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, I can live with VPointer.
|
Hi @pfustc sorry for the delay. I am still out of the office, and I have not yet had time to look at it. It will be one of the first things I'll have a look at when I get back. Looking forward to this refactoring :) FYI: @TobiHartmann just launched testing for the 3rd commit (web rev 02) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this now looks good. I only have some questions about the caching of _pre_loop_end.
Thanks for doing this work, and sorry for the delay with the review.
| // The eventual count of vectorizable packs in slp | ||
| int _slp_vector_pack_count; | ||
| // Cached CountedLoopEndNode of pre loop for main loops | ||
| CountedLoopEndNode* _pre_loop_end; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it safe to cached this node? What happens if the node were ever to be replaced?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, we need to access it via pre_loop_end() which has asserts that check the consistency. Ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We just have to make sure that this field is never accessed directly. What happens if people start using it elsewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The field is already private. What else do you think we can do to further protect it?
| int VPointer::Tracer::_depth = 0; | ||
| #endif | ||
|
|
||
| VPointer::VPointer(MemNode* mem, PhaseIdealLoop* phase, IdealLoopTree* lpt, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, I can live with VPointer.
| #endif | ||
| _nstack(nstack), _analyze_only(analyze_only), _stack_idx(0) | ||
| #ifndef PRODUCT | ||
| , _tracer((phase->C->directive()->VectorizeDebugOption & 2) > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, we can do that refactoring later.
| if (pre_loop_end != nullptr) { | ||
| Node* n_c = phase()->get_ctrl(n); | ||
| return phase()->is_dominator(n_c, pre_loop_end->loopnode()); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain a bit more why CountedLoopNode::is_canonical_loop_entry() returned null at the time, and why you did move the caching?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the responses. LGTM. Thanks for the nice refactoring work!
|
@pfustc This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 238 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
|
Thanks @eme64. May I have another review from someone else? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general it looks good. I just want that you add more description.
And I have question. Part of code is under "#ifndef PRODUCT". Did you build "optimized" VM to make sure it works?
| #include "opto/loopnode.hpp" | ||
|
|
||
| // ----------------------------------VPointer---------------------------------- | ||
| // Information about an address for dependence checking and vector alignment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with using VPointer name but I think you need to add more description here to avoid confusion.
May be add a general description what is in this file: "for shared logics and utilities for C2's auto-vectorization".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| #include "opto/node.hpp" | ||
| #include "opto/loopnode.hpp" | ||
|
|
||
| // ----------------------------------VPointer---------------------------------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We stop using such lines - there was cleaning RFE to remove them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
@vnkozlov, I just checked with CompilerDirectives and got the same tracing output between "fastdebug" build and "optimized" build, and no tracing output is seen for "release" build. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good. Thank you for checking optimized build.
|
/integrate |
|
Going to push as commit 96781ba.
Your commit was automatically rebased without conflicts. |
As discussed in JDK-8308994, we should first do some refactoring work before proceeding with the new post loop vectorization. In this patch, we have done the following.
We have created new C2 source files
vectorization.[cpp|hpp]for shared logics and utilities for C2's auto-vectorization. So far we have moved classSWPointerandVectorElementSizeStatshere fromsuperword.[cpp|hpp].We have decoupled
SWPointerfrom classSuperWordand renamed it toVPointeras it will be used by vectorizers other than SuperWord. The original classSWPointerand its inner classTracerboth have a_slpfield initialized in their constructors. In this patch, we have replaced them by other fields and re-written the constructors for the same functionality. OriginalSWPointer::invariant()calls functionSuperWord::find_pre_loop_end()for loop invariant checks. To help decoupling, we moved functionfind_pre_loop_end()to classCountedLoopNode. As functionSWPointer::Tracer::invariant_1()is tightly coupled withSuperWordbut only prints some debug messages, we temporarily removed it in this patch. We will consider adding it back after later refactoring ofSuperWordso we added aTODOat its call site in this patch.We have a lot of memory phi node checks in loop optimizations. So we added a utility function
is_memory_phi()innode.hpp.Tested tier1~3 on x86 and AArch64. Also manually verified that option
VectorizeDebugin compiler directives still works well.Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/15013/head:pull/15013$ git checkout pull/15013Update a local copy of the PR:
$ git checkout pull/15013$ git pull https://git.openjdk.org/jdk.git pull/15013/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 15013View PR using the GUI difftool:
$ git pr show -t 15013Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/15013.diff
Webrev
Link to Webrev Comment