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

Johannes Graham duke at openjdk.org
Sun Mar 30 03:14:32 UTC 2025


> An interaction between xor bounds optimization and constant folding resulted in xor over constants not being optimized. 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 change moves logic from the `Xor(L|I)Node::Value` methods into the `add_ring` methods, and gives priority to constant-folding. A static method was separated out to facilitate direct unit-testing. It also (subjectively) simplified the  calculation of the upper bound and added an explanation of the reasoning behind it.
> 
> In addition to testing for constant folding over xor, IR tests were added to `XorINodeIdealizationTests` and `XorLNodeIdealizationTests` to cover these related items:
>  - Bounds optimization of xor
>  - A check for  `x ^ x = 0`
>  - Explicit testing of xor over booleans.
> 
> Also `test_xor_node.cpp` was added to more extensively test the correctness of the bounds optimization. It exhaustively tests ranges of 4-bit numbers as well as at the high and low end of the affected types.

Johannes Graham has updated the pull request incrementally with one additional commit since the last revision:

  add missing import

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/23089/files
  - new: https://git.openjdk.org/jdk/pull/23089/files/ce17608b..94a32dba

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=23089&range=45
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=23089&range=44-45

  Stats: 1 line in 1 file changed: 1 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/23089.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/23089/head:pull/23089

PR: https://git.openjdk.org/jdk/pull/23089


More information about the hotspot-compiler-dev mailing list