JDK-8330274 : C2 SuperWord: VPointer invar: same sum with different addition order should be equal
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 23
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2024-04-15
  • Updated: 2025-01-07
  • Resolved: 2025-01-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdResolved
Related Reports
Duplicate :  
Relates :  
Description
I have seen a few examples now, where we could know that the invar of two VPointer is identical: the same summands are added up, only in a different order. This means that the invar nodes are not identical. Somtimes there are CastLL between the additions, which further compilcates the comparison.

I suggest that we recompute the invar for each VPointer as follows:
take the invar, and traverse all AddP, AddL and CastLL nodes, to find all summands. Then sort the summands by their idx. Then add these up with new AddL nodes. If two VPointer have the same summands, then the sorted list is identical, and the result of the addition with new AddL nodes is also identical.  Thus, the final invar can be relied upon to be invariant (no pun intended) to the addition order.

This optimization seems to be relevant for MemorySegment, where we work with varhandles, which seem to sometimes have different addition orders, or only sometimes have CastLL and sometimes not.
Comments
Duplicates JDK-8343685. I added the tests from this PR to that patch.
07-01-2025

After JDK-8343685, a few cases are fixed. There are still some to be investigated, in tests: test/hotspot/jtreg/compiler/loopopts/superword/TestMemorySegment.java test/hotspot/jtreg/compiler/loopopts/superword/TestEquivalentInvariants.java
01-12-2024

While this was a good idea on its own, I would rather do this as part of JDK-8330991.
26-04-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/18795 Date: 2024-04-16 12:00:51 +0000
19-04-2024