RFR: 8353345: C2 asserts because maskShiftAmount modifies node without deleting the hash [v2]

Christian Hagedorn chagedorn at openjdk.org
Thu Apr 3 05:21:59 UTC 2025


On Wed, 2 Apr 2025 17:20:35 GMT, Marc Chevalier <mchevalier at openjdk.org> wrote:

>> First delete the hash, then `set_req`. This way, we avoid changing the node (a non-`this` node) without deleting the hash. This wrong ordering is not new from [JDK-8347459](https://bugs.openjdk.org/browse/JDK-8347459), but before that, only `this` was going through this function, so it was ok. But since, it is used with other nodes, hence the need to remove the hash.
>> 
>> Also, not do any of that outside IGVN, but requires to register nested shifts for IGVN in parsing not to miss them later.
>> 
>> Thanks,
>> Marc
>
> Marc Chevalier has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - Fix spacing
>  - Do not eagerly replace shift amounts in nested lshift

Nice, thanks for the update! Looks much better now. Some more comments.

src/hotspot/share/opto/mulnode.cpp line 953:

> 951: }
> 952: 
> 953: //=============================================================================

While at it, you can also remove this line which we no longer use today
Suggestion:

src/hotspot/share/opto/mulnode.cpp line 966:

> 964: 
> 965: // Returns whether the shift amount is constant. If so, sets real_shift and masked_shift.
> 966: static bool mask_shift_amount(PhaseGVN* phase, const Node* shiftNode, uint nBits, int& real_shift, int& masked_shift) {

While at it, we should probably use underscores instead of camelCase for `shiftNode`. Same below.

src/hotspot/share/opto/mulnode.cpp line 995:

> 993:       if (igvn != nullptr) {
> 994:         igvn->rehash_node_delayed(shiftNode);
> 995:       }

Do we still need this now? If we always call it with `shiftNode == this` then we already get the rehashing "for free" due to modifying `this` as part of `Ideal()`.

src/hotspot/share/opto/mulnode.cpp line 1007:

> 1005: //   outer_shift = (_ << rhs0)
> 1006: // We are looking for the pattern:
> 1007: //   outer_shift = ((X << rhs1) << rhs0)

Just an idea: To better keep track of what is the outer and inner rhs, we could use `rhs_inner` and `rhs_outer`.

src/hotspot/share/opto/mulnode.cpp line 1010:

> 1008: //   where rhs0 and rhs1 are constant
> 1009: //   we denote inner_shift the nested expression (X << rhs1)
> 1010: //   con0 = rhs1 % nbits and con0 = rhs1 % nbits

Probably copy-paste error, did you want to define `con1` here as well?

-------------

PR Review: https://git.openjdk.org/jdk/pull/24355#pullrequestreview-2738524807
PR Review Comment: https://git.openjdk.org/jdk/pull/24355#discussion_r2026199599
PR Review Comment: https://git.openjdk.org/jdk/pull/24355#discussion_r2026200378
PR Review Comment: https://git.openjdk.org/jdk/pull/24355#discussion_r2026202624
PR Review Comment: https://git.openjdk.org/jdk/pull/24355#discussion_r2026204009
PR Review Comment: https://git.openjdk.org/jdk/pull/24355#discussion_r2026207250


More information about the hotspot-compiler-dev mailing list