RFR: 8332856: C2: Add new transform for bool eq/ne (cmp (and (urshift X const1) const2) 0)
Tobias Hotz
duke at openjdk.org
Fri May 24 15:56:14 UTC 2024
This PR adds a new ideal optimization for the following pattern:
public boolean testFunc(int a) {
int mask = 0b101;
int shift = 12;
return ((a >> shift) & mask) == 0;
}
Where the mask and shift are constant values and a is a variable. For this optimization to work, the right shift has to be idealized to a unsinged right shift earlier in the pipeline, which here: https://github.com/openjdk/jdk/blob/b92bd671835c37cff58e2cdcecd0fe4277557d7f/src/hotspot/share/opto/mulnode.cpp#L731
If the shift is already an unsiged bit shift, it works as well.
On AMD64 CPUs, this means that this whole line computation can be reduced to a simple `test` instruction.
-------------
Commit messages:
- Add summary and bugid to test
- remove trailing whitespace in test
- force LF line endings for test
- Add ideal for bool eq/ne (cmp (and (urshift X const1) const2) 0) -> bool eq/ne (cmp (and X newconst) 0)
Changes: https://git.openjdk.org/jdk/pull/19310/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=19310&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8332856
Stats: 197 lines in 2 files changed: 197 ins; 0 del; 0 mod
Patch: https://git.openjdk.org/jdk/pull/19310.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/19310/head:pull/19310
PR: https://git.openjdk.org/jdk/pull/19310
More information about the hotspot-compiler-dev
mailing list