RFR: 8347645: C2: XOR bounded value handling blocks constant folding

Johannes Graham duke at openjdk.org
Wed Jan 15 21:38:51 UTC 2025


On Mon, 13 Jan 2025 22:16:20 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.

Sample program:

public class XorTest {
    public static void main(String[] args) {
        long t=0;
        for (int i = 0; i < 10_000; i++) {
            t+=doXor();
        }
        System.out.println("t = " + t);
    }

    static long doXor(){
        long c=42;
        return c ^ 2025L;
    }
}


IGV before patch (constant nodes are red)

![Xor before](https://github.com/user-attachments/assets/8cecb845-8273-4647-91fa-919dec02a4f0)


IGV after patch
![25 Return](https://github.com/user-attachments/assets/36f02474-df70-4a0c-b1c0-71c02732501f)

Thanks for creating the bug.

I have left the x ^x =0 check in Value because it was operating on the Node rather than the Type. I moved the rest into add_ring.

Done for Int, Long to follow.

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

PR Comment: https://git.openjdk.org/jdk/pull/23089#issuecomment-2588337092
PR Comment: https://git.openjdk.org/jdk/pull/23089#issuecomment-2590764813


More information about the hotspot-compiler-dev mailing list