JDK-8356176 : C2 MemorySegment: missing RCE with byteSize() in Loop Exit Check inside the for Expression
  • Type: Sub-task
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 25
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2025-05-05
  • Updated: 2025-09-04
  • Resolved: 2025-08-19
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.
JDK 26
26 b12Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
In simple Memory Segment loops C2 fails to vectorize the loop if the loop exit check is MemorySegment::byteSize() and the function is called inside the for expression. If the function call is lifted above the for expression in the source code, everything works as expected.

The reason for the missing vectorization seems to be that the range checks are not eliminated if the loop exit check in the for expression contains MemorySegment::byteSize() because it takes longer for the loop to be converted to a counted loop

See the attached test case contributed by [~epeter]. Run it with
 java -Xbatch -XX:CompileCommand=compileonly,TestLoop.test\* -XX:CompileCommand=printcompilation,TestLoop.test\* -XX:+TraceNewVectors -XX:+TraceLoopOpts Test3.java
Comments
Changeset: 626bea80 Branch: master Author: Manuel Hässig <mhaessig@openjdk.org> Date: 2025-08-19 06:37:52 +0000 URL: https://git.openjdk.org/jdk/commit/626bea80abf1660757a12462ebc8313ef6d41f92
19-08-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/26429 Date: 2025-07-22 15:05:29 +0000
30-07-2025