RFR: 8347645: C2: XOR bounded value handling blocks constant folding [v12]

Quan Anh Mai qamai at openjdk.org
Fri Jan 31 01:41:54 UTC 2025


On Thu, 30 Jan 2025 23:08:27 GMT, Johannes Graham <duke at openjdk.org> wrote:

>> C2 does not eliminate XOR nodes with constant arguments. This has a noticeable effect on `Long.expand` with a constant mask, on architectures that don't have instructions equivalent  to `PDEP` to be used in an intrinsic.
>> 
>> This patch demonstrates a potential fix to the problem, but there might well be better ways to do it.
>
> Johannes Graham has updated the pull request incrementally with one additional commit since the last revision:
> 
>   extract static methods for testing; add GTESTs; more extensive int ir tests; remove some ir tests for longs due to difficulty in applying constant clamping.

src/hotspot/share/opto/addnode.cpp line 1012:

> 1010: }
> 1011: 
> 1012: jint XorINode::calc_xor_max(const jint hi_0, const jint hi_1) {

Since this is only used in `XorINode::Value`, I think a static local method would be better. And if you are comfortable with templates, I suggest templatizing it to unify the implementation with `jlong` below.

test/hotspot/gtest/opto/test_xor_node.cpp line 29:

> 27: #include "runtime/interfaceSupport.inline.hpp"
> 28: 
> 29: TEST_VM(opto, xor) {

Did you forget to add the tests to this file?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/23089#discussion_r1936550883
PR Review Comment: https://git.openjdk.org/jdk/pull/23089#discussion_r1936551953


More information about the hotspot-compiler-dev mailing list