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

Johannes Graham duke at openjdk.org
Thu Jan 23 22:47:48 UTC 2025


On Thu, 23 Jan 2025 08:53:40 GMT, Quan Anh Mai <qamai at openjdk.org> wrote:

>> src/hotspot/share/opto/addnode.cpp line 1008:
>> 
>>> 1006:       const TypeInt* t2x = TypeInt::make(0, round_down_power_of_2(r1->_hi) + (round_down_power_of_2(r1->_hi) - 1), r1->_widen);
>>> 1007:       return t1x->meet(t2x);
>>> 1008:     }
>> 
>> I know you only moved this code - but can you add some more comments about what it does? Maybe add some examples? It would help me review this code faster if I don't have to figure it out myself ;)
>
> Tbh I think this would be clearer, there is also no need for rounding down since the max value of `r->_hi` has the highest bit unset:
> 
>     // x ^ y cannot have any bit set that is higher than both the highest bits set in x and y
>     // x cannot have any bit set that is higher than the highest bit set in r0->_hi
>     // y cannot have any bit set that is higher than the highest bit set in r1->_hi
>     juint max = round_up_power_of_2<juint>(r0->_hi | r1->_hi) - 1;
>     return TypeInt::make(0, max, MAX2(r0->_widen, r1->_widen));

How about this: 

      // x ^ y cannot have any bit set that is higher than both the highest bits set in x and y
      // x cannot have any bit set that is higher than the highest bit set in r0->_hi
      // y cannot have any bit set that is higher than the highest bit set in r1->_hi

      // so we want to find a value that has all 1 bits  everywhere up to and including
      // the highest bits set in r0->_hi as well as r1->_hi. For this, we can take the smallest power
      // of 2 strictly greater than both hi values and subtract 1 from it.

      julong max = (round_down_power_of_2<julong>(r0->_hi | r1->_hi)<<1) - 1;

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

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


More information about the hotspot-compiler-dev mailing list