RFR: 8346664: C2: Optimize mask check with constant offset [v7]
Emanuel Peter
epeter at openjdk.org
Thu Jan 30 08:32:57 UTC 2025
On Wed, 29 Jan 2025 17:23:40 GMT, Matthias Ernst <duke at openjdk.org> wrote:
>> Fixes [JDK-8346664](https://bugs.openjdk.org/browse/JDK-8346664): extends the optimization of masked sums introduced in #6697 to cover constant values, which currently break the optimization.
>>
>> Such constant values arise in an expression of the following form, for example from `MemorySegmentImpl#isAlignedForElement`:
>>
>>
>> (base + (index + 1) << 8) & 255
>> => MulNode
>> (base + (index << 8 + 256)) & 255
>> => AddNode
>> ((base + index << 8) + 256) & 255
>>
>>
>> Currently, `256` is not being recognized as a shifted value. This PR enables further reduction:
>>
>>
>> ((base + index << 8) + 256) & 255
>> => MulNode (this PR)
>> (base + index << 8) & 255
>> => MulNode (PR #6697)
>> base & 255 (loop invariant)
>>
>>
>> Implementation notes:
>> * I verified that the originating issue "scaled varhandle indexed with i+1" (https://mail.openjdk.org/pipermail/panama-dev/2024-December/020835.html) is resolved with this PR.
>> * ~in order to stay with the flow of the current implementation, I refrained from solving general (const & mask)==0 cases, but only those where const == _ << shift.~
>> * ~I modified existing test cases adding/subtracting from the index var (which would fail with current C2). Let me know if would like to see separate cases for these.~
>
> Matthias Ernst has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 20 additional commits since the last revision:
>
> - Merge branch 'openjdk:master' into mernst/JDK-8346664
> - make the check more clear: shift >= mask_width
> - fully randomized
> - JLS: only the lower bits of the shift are taken into account (aka we don't assert).
> - (c)
> - (c)
> - Assert that MulNode::Ideal already masks constant shift amounts for us.
> Avoid accidental zero mask breaking test.
> - "element".
> - avoid redundant comment
> - addConstNonConstMaskLong
> - ... and 10 more: https://git.openjdk.org/jdk/compare/91762dbd...490cc2fb
Second failure:
`compiler/c2/TestAndShiftZeroCCP.java`
With flags: `-XX:StressLongCountedLoop=200000000` or `-XX:TypeProfileLevel=222`... or maybe none?
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (/opt/mach5/mesos/work_dir/slaves/03ecc23a-edd5-4bb5-a333-4ff8ea07fd7c-S1456/frameworks/1735e8a2-a1db-478c-8104-60c8b0af87dd-0196/executors/d9a418d8-b74f-4dff-bc17-d17ac5d84ec6/runs/03b1642e-a52b-481b-9725-31f4ae8f5f98/workspace/open/src/hotspot/share/opto/mulnode.cpp:2084), pid=3186666, tid=3186708
# assert(shift >= 0 && shift < type2aelembytes(bt) * BitsPerByte) failed: shift amount should have been masked already: 62
#
# JRE version: Java(TM) SE Runtime Environment (25.0) (fastdebug build 25-internal-LTS-2025-01-30-0704448.emanuel.peter.jdk-review)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 25-internal-LTS-2025-01-30-0704448.emanuel.peter.jdk-review, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# V [libjvm.so+0x14a6405] AndIL_is_zero_element_under_mask(PhaseGVN const*, Node const*, Node const*, BasicType)+0x4a5
#
# Core dump will be written. Default location: Core dumps may be processed with "/opt/core.sh %p" (or dumping to /opt/mach5/mesos/work_dir/slaves/03ecc23a-edd5-4bb5-a333-4ff8ea07fd7c-S1767/frameworks/1735e8a2-a1db-478c-8104-60c8b0af87dd-0196/executors/b76444c8-0dfa-4dcc-b872-356422534b8d/runs/708ac76a-0342-4254-898d-2a81965c0cfc/testoutput/test-support/jtreg_open_test_hotspot_jtreg_tier1_compiler_1/scratch/2/core.3186666)
#
# An error report file with more information is saved as:
# /opt/mach5/mesos/work_dir/slaves/03ecc23a-edd5-4bb5-a333-4ff8ea07fd7c-S1767/frameworks/1735e8a2-a1db-478c-8104-60c8b0af87dd-0196/executors/b76444c8-0dfa-4dcc-b872-356422534b8d/runs/708ac76a-0342-4254-898d-2a81965c0cfc/testoutput/test-support/jtreg_open_test_hotspot_jtreg_tier1_compiler_1/scratch/2/hs_err_pid3186666.log
#
# Compiler replay data is saved as:
# /opt/mach5/mesos/work_dir/slaves/03ecc23a-edd5-4bb5-a333-4ff8ea07fd7c-S1767/frameworks/1735e8a2-a1db-478c-8104-60c8b0af87dd-0196/executors/b76444c8-0dfa-4dcc-b872-356422534b8d/runs/708ac76a-0342-4254-898d-2a81965c0cfc/testoutput/test-support/jtreg_open_test_hotspot_jtreg_tier1_compiler_1/scratch/2/replay_pid3186666.log
#
# If you would like to submit a bug report, please visit:
# https://bugreport.java.com/bugreport/crash.jsp
That is your new assert. Needs investigation.
Same assert for:
`compiler/ccp/TestShiftConvertAndNotification.java#id0`
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (/opt/mach5/mesos/work_dir/slaves/03ecc23a-edd5-4bb5-a333-4ff8ea07fd7c-S1456/frameworks/1735e8a2-a1db-478c-8104-60c8b0af87dd-0196/executors/d9a418d8-b74f-4dff-bc17-d17ac5d84ec6/runs/03b1642e-a52b-481b-9725-31f4ae8f5f98/workspace/open/src/hotspot/share/opto/mulnode.cpp:2084), pid=28081, tid=28126
# assert(shift >= 0 && shift < type2aelembytes(bt) * BitsPerByte) failed: shift amount should have been masked already: 49
#
# JRE version: Java(TM) SE Runtime Environment (25.0) (fastdebug build 25-internal-LTS-2025-01-30-0704448.emanuel.peter.jdk-review)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 25-internal-LTS-2025-01-30-0704448.emanuel.peter.jdk-review, compiled mode, sharing, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# V [libjvm.so+0x14a6405] AndIL_is_zero_element_under_mask(PhaseGVN const*, Node const*, Node const*, BasicType)+0x4a5
#
# Core dump will be written. Default location: Core dumps may be processed with "/opt/core.sh %p" (or dumping to /opt/mach5/mesos/work_dir/slaves/1115c4e2-181d-4f4d-866f-faedfa24d464-S684/frameworks/1735e8a2-a1db-478c-8104-60c8b0af87dd-0196/executors/cb8e1da0-ecca-4a33-9969-138cf384be96/runs/cca65d00-a4cc-4cbf-a7f6-e969b02bf066/testoutput/test-support/jtreg_open_test_hotspot_jtreg_tier3_compiler/scratch/3/core.28081)
#
# An error report file with more information is saved as:
# /opt/mach5/mesos/work_dir/slaves/1115c4e2-181d-4f4d-866f-faedfa24d464-S684/frameworks/1735e8a2-a1db-478c-8104-60c8b0af87dd-0196/executors/cb8e1da0-ecca-4a33-9969-138cf384be96/runs/cca65d00-a4cc-4cbf-a7f6-e969b02bf066/testoutput/test-support/jtreg_open_test_hotspot_jtreg_tier3_compiler/scratch/3/hs_err_pid28081.log
#
# Compiler replay data is saved as:
# /opt/mach5/mesos/work_dir/slaves/1115c4e2-181d-4f4d-866f-faedfa24d464-S684/frameworks/1735e8a2-a1db-478c-8104-60c8b0af87dd-0196/executors/cb8e1da0-ecca-4a33-9969-138cf384be96/runs/cca65d00-a4cc-4cbf-a7f6-e969b02bf066/testoutput/test-support/jtreg_open_test_hotspot_jtreg_tier3_compiler/scratch/3/replay_pid28081.log
#
# If you would like to submit a bug report, please visit:
# https://bugreport.java.com/bugreport/crash.jsp
#
-------------
PR Comment: https://git.openjdk.org/jdk/pull/22856#issuecomment-2623835460
PR Comment: https://git.openjdk.org/jdk/pull/22856#issuecomment-2623837563
More information about the hotspot-compiler-dev
mailing list