RFR: 8364766: C2: Improve Value() of DivI and DivL for non-constant inputs [v8]

Manuel Hässig mhaessig at openjdk.org
Thu Oct 23 10:22:17 UTC 2025


On Sun, 19 Oct 2025 19:20:58 GMT, Tobias Hotz <duke at openjdk.org> wrote:

>> This PR improves the value of interger division nodes.
>> Currently, we only emit a good type if either input is constant. But we can also cover the generic case. It does that by finding the four corners of the division. This is guranteed to find the extrema that we can use for min/max. Some special logic is required for MIN_INT / -1, though, as this is a special case
>> We also need some special logic to handle ranges that cross zero, but in this case, we just need to check for the negative and positive range once.
>> This also cleans up and unifies the code paths for DivINode and DivLNode.
>> I've added some tests to validate the optimization. Without the changes, some of these tests fail.
>
> Tobias Hotz has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - Add additional nodes to fail conditions to detect idealized/transformed DivI Nodes that did not constant fold
>  - Remove checks for bottom and reorganize DivI/DivL Value functions

Unfortunately, testing revealed a problem in one of our internal tests, that I am unable to share. The Test is run with `-Xomp -XX:-TieredCompilation` and the error is

STDOUT:
 485  ConvI2L  === _ 486  [[ 483 ]]  #long:minint..maxint, 0u..maxulong, widen: 3 !orig=153 !jvms: b4735597::checkLong @ bci:4 (line 99) b4735597::run @ bci:19 (line 75)
 152  ConL  === 0  [[ 169 164 483 568 ]]  #long:minlong
 489  IfTrue  === 488  [[ 483 490 ]] #1 !orig=161 !jvms: b4735597::checkLong @ bci:5 (line 99) b4735597::run @ bci:19 (line 75)
 483  DivL  === 489 152 485  [[ 482 504 ]]  !orig=169 !jvms: b4735597::checkLong @ bci:5 (line 99) b4735597::run @ bci:19 (line 75)
told = long:maxint..2305843009213693952, widen: 3
tnew = long:minlong..9007199254740992, 0u..maxulong, widen: 3
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/src/jdk-pr-26143/open/src/hotspot/share/opto/phaseX.cpp:2763), pid=92732, tid=92759
#  fatal error: Not monotonic
#
# JRE version: Java(TM) SE Runtime Environment (26.0) (fastdebug build 26-internal-mhassig.open)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 26-internal-mhassig.open, compiled mode, sharing, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# V  [libjvm.so+0x185c479]  PhaseCCP::verify_type(Node*, Type const*, Type const*)+0x169

Stack: [0x0000ffff79bf4000,0x0000ffff79df2000],  sp=0x0000ffff79dec8c0,  free space=2018k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x15a7f0c]  PhaseCCP::verify_type(Node*, Type const*, Type const*)+0x1a4  (phaseX.cpp:2763)
V  [libjvm.so+0x15b0350]  PhaseCCP::analyze()+0x2cc  (phaseX.cpp:2806)
V  [libjvm.so+0x9be4e8]  Compile::Optimize()+0x780  (compile.cpp:2489)
V  [libjvm.so+0x9c0db0]  Compile::Compile(ciEnv*, ciMethod*, int, Options, DirectiveSet*)+0x16a4  (compile.cpp:860)
V  [libjvm.so+0x7ec560]  C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x2dc  (c2compiler.cpp:147)
V  [libjvm.so+0x9cfacc]  CompileBroker::invoke_compiler_on_method(CompileTask*)+0xb08  (compileBroker.cpp:2345)
V  [libjvm.so+0x9d09f8]  CompileBroker::compiler_thread_loop()+0x638  (compileBroker.cpp:1989)
V  [libjvm.so+0xed1ea8]  JavaThread::thread_main_inner()+0x108  (javaThread.cpp:771)
V  [libjvm.so+0x18455bc]  Thread::call_run()+0xac  (thread.cpp:243)
V  [libjvm.so+0x15248bc]  thread_native_entry(Thread*)+0x12c  (os_linux.cpp:883)
C  [libc.so.6+0x80b50]  start_thread+0x300

test/hotspot/jtreg/compiler/c2/irTests/IntegerDivValueTests.java line 1:

> 1: /*

I only noticed now: please move this test out of the `irTests` directory. It is a historic mistake. Probably `compiler/igvn` would be a good location.

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

Changes requested by mhaessig (Committer).

PR Review: https://git.openjdk.org/jdk/pull/26143#pullrequestreview-3368956083
PR Review Comment: https://git.openjdk.org/jdk/pull/26143#discussion_r2454453693


More information about the hotspot-compiler-dev mailing list