RFR: 8361140: Missing OptimizePtrCompare check in ConnectionGraph::reduce_phi_on_cmp

Christian Hagedorn chagedorn at openjdk.org
Mon Jul 7 12:16:40 UTC 2025


On Fri, 4 Jul 2025 02:49:27 GMT, guanqiang han <duke at openjdk.org> wrote:

> When running with `-XX:-OptimizePtrCompare` (which disables pointer comparison optimization), the compiler may hit an assertion failure in debug builds because `optimize_ptr_compare` is still being called. This violates the intended usage of the flag and leads to unexpected crashes.
> 
> This patch adds an early return to `reduce_phi_on_cmp` when `OptimizePtrCompare` is false. Since the optimization relies on `optimize_ptr_compare` for static reasoning about comparisons, there's no benefit in proceeding with `reduce_phi_on_cmp` when this flag is disabled.

Changes requested by chagedorn (Reviewer).

src/hotspot/share/opto/escape.cpp line 981:

> 979:   if (!OptimizePtrCompare) {
> 980:     return;
> 981:   }

Thanks for working on this! IIUC, having the bailout here will fail to reduce the phi which could be unexpected. Shouldn't we just return `UNKNOWN` from within `ConnectionGraph::optimize_ptr_compare()` when we run without `OptimizePtrCompare`?

On a separate note, can you also add a regression test? Maybe you can also just add a run with `-XX:-OptimizePtrCompare` - maybe together with `-XX:+VerifyReduceAllocationMerges` for more verification - to `compiler/c2/irTests/scalarReplacement/AllocationMergesTests.java`.

@JohnTortugo you might also want to have a look at this.

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

PR Review: https://git.openjdk.org/jdk/pull/26125#pullrequestreview-2993546963
PR Review Comment: https://git.openjdk.org/jdk/pull/26125#discussion_r2189878464


More information about the hotspot-compiler-dev mailing list