RFR: 8350896: Integer/Long.compress gets wrong type from CompressBitsNode::Value [v8]
Emanuel Peter
epeter at openjdk.org
Mon Jun 2 04:54:53 UTC 2025
On Fri, 30 May 2025 17:43:27 GMT, Jatin Bhateja <jbhateja at openjdk.org> wrote:
>> Jatin Bhateja has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Review comments resolutions
>
> We can further constrain the value range bounds of bit compression and expansion once PR #17508 gets integrated. For now, I have developed the following draft demonstrates bound constraining with KnownBitLattice.
>
>
> //
> // Prototype of bit compress/expand value range computation
> // using KnownBits infrastructure.
> //
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <stdint.h>
> #include <assert.h>
>
> template<class U,class S>
> class KnownBitsLattice {
> private:
> U zeros;
> U ones;
>
> public:
> KnownBitsLattice(U lb, U ub);
>
> U getKnownZeros() {
> return zeros;
> }
>
> U getKnownOnes() {
> return ones;
> }
>
> long getKnownZerosCount() {
> uint64_t count = 0;
> asm volatile ("popcntq %1, %0 \n\t" : "=r"(count) : "r"(zeros) : "cc");
> return count;
> }
>
> long getKnownOnesCount() {
> uint64_t count = 0;
> asm volatile ("popcntq %1, %0 \n\t" : "=r"(count) : "r"(ones) : "cc");
> return count;
> }
>
> bool check_voilation() {
> // A given bit cannot be both zero or one.
> return (zeros & ones) != 0;
> }
>
> bool is_MSB_KnownOneBitsSet() {
> return (ones >> 63) == 1;
> }
>
> bool is_MSB_KnownZeroBitsSet() {
> return (zeros >> 63) == 1;
> }
> };
>
> template<class U, class S>
> KnownBitsLattice<U,S>::KnownBitsLattice(U lb, U ub) {
> // To find KnownBitsLattice from a given value range
> // we first find the common prefix b/w upper and lower
> // bound, we then concertize known zeros and ones bit
> // based on common prefix.
> // e.g.
> // lb = 00110001
> // ub = 00111111
> // common prefix = 0011XXXX
> // knownbits.zeros = 11000000
> // knownbits.ones = 00110000
> //
> // conversely, for a give knownbits value we can find
> // lower and upper value ranges.
> // e.g.
> // knownbits.zeros = 0x00010001
> // knownbits.ones = 0x10001100
> // range.lo = knownbits.ones, this is because knownbits.ones are
> // guaranteed to be one.
> // range.hi = ~knownbits.zeros, this is an optimistic upper bound
> // which assumes all unset knownbits.zero
> // are ones.
> // Thus in above example,
> // range.lo = 0x8C
> // range.hi = 0xEE
>
> U lzcnt = 0;
> U common_prefix = lb ^ ub;
> asm volatile ("lzcntq %1, %0 \n\t" : "=r"(lzcnt) : "r"(common_prefix) : "cc");
> U common_prefix_mask = lzcnt == 0 ? 0xFFFFFFFFFFFFFFFFL : ~((1ULL << (64 - lzcnt)) - 1);
> zeros = (~lb) & common_prefix_mask;
> ones = (lb) & c...
@jatin-bhateja Nice! Yes I'm looking forward to reviewing all the KnownBits extensions!
@jatin-bhateja Let me know whenever this is ready for another pass of reviews :)
-------------
PR Comment: https://git.openjdk.org/jdk/pull/23947#issuecomment-2928741573
More information about the hotspot-compiler-dev
mailing list