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

Emanuel Peter epeter at openjdk.org
Thu Jan 30 11:04:53 UTC 2025


On Mon, 27 Jan 2025 19:34:51 GMT, Johannes Graham <duke at openjdk.org> wrote:

>> test/hotspot/jtreg/compiler/c2/irTests/XorINodeIdealizationTests.java line 273:
>> 
>>> 271:     private static int forceMinMax(int value){
>>> 272:         // equivalent to Math.min(CONST_POW_2, Math.max(value, 1))
>>> 273:         return 1 + (value & (CONST_POW_2 - 1));
>> 
>> Why do you chose the complicated way here? What's wrong with using `min / max`? I'm afraid that the XOR gets folded through the ADD or AND here.... I think that would be less likely with `min / max`, right?
>
> Surprisingly the min/max bounds do not get propagated on longs. Once I found a pattern that worked for longs,  I used it for ints as well, though min/max is ok there.

Ah, I think that is because we do not yet intrinsify `Long.max/min` yet! See https://github.com/openjdk/jdk/pull/20098.

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

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


More information about the hotspot-compiler-dev mailing list