JDK-8275202 : C2: optimize out more redundant conditions
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 18,21,22
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2021-10-13
  • Updated: 2024-07-09
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
tbdUnresolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
In patterns like:

if (i >= 42) {
  if (i < 10) {

the second test is not optimized out.
This is also related to JDK-8272562 where a CastII optimizes to top on a branch that's never taken but optimized out.
Comments
A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/14586 Date: 2023-06-21 12:47:26 +0000
09-07-2024

Turning this back into an RFE. I've filed JDK-8321097 to keep track of all the bad graph assertion failures related to dying Cast nodes. I've re-linked all bugs to JDK-8321097. I will step through these re-linked bugs and check if JDK-8319372 fixes some or all of them.
30-11-2023

Here's hs_err_pid snippets from the jdk-22+21-1662-tier8 sighting: applications/javafuzzer/BigTest.java # Internal Error (/opt/mach5/mesos/work_dir/slaves/afbc6042-3a24-4198-9369-18c663a3f74c-S32968/frameworks/1735e8a2-a1db-478c-8104-60c8b0af87dd-0196/executors/359c844b-6a7b-4794-a89f-3f9a6b4dca5a/runs/9b9357c6-c96e-424b-b2b7-26573436dc1e/workspace/open/src/hotspot/share/opto/loopnode.cpp:6144), pid=1717141, tid=1717157 # assert(false) failed: Bad graph detected in build_loop_late # # JRE version: Java(TM) SE Runtime Environment (22.0+21) (fastdebug build 22-ea+21-1662) # Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 22-ea+21-1662, mixed mode, sharing, compressed oops, compressed class ptrs, g1 gc, linux-amd64) # Problematic frame: # V [libjvm.so+0x12aa768] PhaseIdealLoop::build_loop_late_post_work(Node*, bool)+0x9f8 <snip> --------------- T H R E A D --------------- Current thread (0x00007f9324355460): JavaThread "C2 CompilerThread0" daemon [_thread_in_native, id=1717157, stack(0x00007f93145a1000,0x00007f93146a1000) (1024K)] Current CompileTask: C2:403 1 % !b Test::mainTest @ 163 (582 bytes) Stack: [0x00007f93145a1000,0x00007f93146a1000], sp=0x00007f931469bd00, free space=1003k Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) V [libjvm.so+0x12aa768] PhaseIdealLoop::build_loop_late_post_work(Node*, bool)+0x9f8 (loopnode.cpp:6144) V [libjvm.so+0x12aa84d] PhaseIdealLoop::build_loop_late(VectorSet&, Node_List&, Node_Stack&)+0xbd (loopnode.cpp:6047) V [libjvm.so+0x12ab17d] PhaseIdealLoop::build_and_optimize()+0x61d (loopnode.cpp:4461) V [libjvm.so+0x9fdf4b] PhaseIdealLoop::optimize(PhaseIterGVN&, LoopOptsMode)+0x3ab (loopnode.hpp:1112) V [libjvm.so+0x9fa0a6] Compile::Optimize()+0xf36 (compile.cpp:2173) V [libjvm.so+0x9fc631] Compile::Compile(ciEnv*, ciMethod*, int, Options, DirectiveSet*)+0x1bc1 (compile.cpp:854) V [libjvm.so+0x849c77] C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x207 (c2compiler.cpp:134) V [libjvm.so+0xa08660] CompileBroker::invoke_compiler_on_method(CompileTask*)+0x980 (compileBroker.cpp:2292) V [libjvm.so+0xa093f8] CompileBroker::compiler_thread_loop()+0x508 (compileBroker.cpp:1951) V [libjvm.so+0xec434c] JavaThread::thread_main_inner()+0xcc (javaThread.cpp:720) V [libjvm.so+0x17a25aa] Thread::call_run()+0xba (thread.cpp:220) V [libjvm.so+0x14a71fa] thread_native_entry(Thread*)+0x12a (os_linux.cpp:785) I would have gone with this bug: JDK-8314111 C2: assert(false) failed: Bad graph detected in build_loop_late but it is closed as a duplicate of this bug (JDK-8275202)
26-10-2023

Here's a log file snippet from the jdk-22+21-1590-tier1 sighting: java/util/concurrent/tck/JSR166TestCase.java#others ----------System.out:(20/1450)---------- # # A fatal error has been detected by the Java Runtime Environment: # # SIGSEGV (0xb) at pc=0x0000ffffb5f0ccec, pid=389310, tid=392958 # # JRE version: Java(TM) SE Runtime Environment (22.0+21) (build 22-ea+21-1590) # Java VM: Java HotSpot(TM) 64-Bit Server VM (22-ea+21-1590, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-aarch64) # Problematic frame: # V [libjvm.so+0xa82cec] PhaseIdealLoop::build_loop_late_post_work(Node*, bool)+0xdc # # 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/afbc6042-3a24-4198-9369-18c663a3f74c-S30469/frameworks/1735e8a2-a1db-478c-8104-60c8b0af87dd-0196/executors/03f4f51b-fccb-4f33-8c3c-d8f295830597/runs/3368ae83-8fd0-4ee0-bf31-9cb42eab0bef/testoutput/test-support/jtreg_open_test_jdk_tier1_part2/scratch/1/core.389310) # # An error report file with more information is saved as: # /opt/mach5/mesos/work_dir/slaves/afbc6042-3a24-4198-9369-18c663a3f74c-S30469/frameworks/1735e8a2-a1db-478c-8104-60c8b0af87dd-0196/executors/03f4f51b-fccb-4f33-8c3c-d8f295830597/runs/3368ae83-8fd0-4ee0-bf31-9cb42eab0bef/testoutput/test-support/jtreg_open_test_jdk_tier1_part2/scratch/1/hs_err_pid389310.log [thread 389537 also had an error] [thread 392964 also had an error] [thread 389441 also had an error] ------ Timeout during error reporting after 120 s. ------ # [ timer expired, abort... ] ----------System.err:(1202/93229)---------- Here's the crashing thread's stack: --------------- T H R E A D --------------- Current thread (0x0000ffff549a0c80): JavaThread "C2 CompilerThread1" daemon [_thread_in_native, id=392958, stack(0x0000ffff58f43000,0x0000ffff59141000) (2040K)] Current CompileTask: C2:5780 4307 4 java.util.stream.ForEachOps$ForEachTask::compute (183 bytes) Stack: [0x0000ffff58f43000,0x0000ffff59141000], sp=0x0000ffff5913bee0, free space=2019k Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) V [libjvm.so+0xa82cec] PhaseIdealLoop::build_loop_late_post_work(Node*, bool)+0xdc (node.hpp:399) V [libjvm.so+0xa83568] PhaseIdealLoop::build_loop_late(VectorSet&, Node_List&, Node_Stack&)+0x168 (loopnode.cpp:6047) V [libjvm.so+0xa83d3c] PhaseIdealLoop::build_and_optimize()+0x6bc (loopnode.cpp:4461) V [libjvm.so+0x5a1a84] PhaseIdealLoop::optimize(PhaseIterGVN&, LoopOptsMode)+0x1a4 (loopnode.hpp:1112) V [libjvm.so+0x59fbd0] Compile::Optimize()+0x4c0 (compile.cpp:2317) V [libjvm.so+0x5a12f0] Compile::Compile(ciEnv*, ciMethod*, int, Options, DirectiveSet*)+0xba0 (compile.cpp:854) V [libjvm.so+0x4d2868] C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x164 (c2compiler.cpp:134) V [libjvm.so+0x5a6cc4] CompileBroker::invoke_compiler_on_method(CompileTask*)+0x9b4 (compileBroker.cpp:2290) V [libjvm.so+0x5a9770] CompileBroker::compiler_thread_loop()+0x380 (compileBroker.cpp:1951) V [libjvm.so+0x81b194] JavaThread::thread_main_inner() [clone .part.0]+0xa4 (javaThread.cpp:720) V [libjvm.so+0xd05ef8] Thread::call_run()+0xa8 (thread.cpp:220) V [libjvm.so+0xb8e2cc] thread_native_entry(Thread*)+0xdc (os_linux.cpp:785) C [libpthread.so.0+0x7928] start_thread+0x188 siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr: 0x0000000000000008
20-10-2023

[~roland] I found a duplicate JDK-8314111. I checked that Reduced2.java passes with your current fix. You can also read the ananysis I did for the graph: https://bugs.openjdk.org/browse/JDK-8314111?focusedCommentId=14611799&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14611799
18-09-2023

Converted to bug because this will fix JDK-8293941 and set fix version to JDK 22 for now. ILW = Same as JDK-8293941 = P3
03-05-2023

I linked some related RFEs. We should check if they are still relevant once we have a fix for this issue.
29-11-2022