RFR: 8277850: C2: optimize mask checks in counted loops
Tobias Hartmann
thartmann at openjdk.java.net
Tue Dec 7 08:45:18 UTC 2021
On Fri, 3 Dec 2021 10:04:58 GMT, Roland Westrelin <roland at openjdk.org> wrote:
> This is another fix that addresses a performance issue with panama and that was brought up by Maurizio. The pattern to optimize is:
> if ((base + (offset << 2)) & 3) != 0) {
> }
>
> where base is loop independent but offset depends on a loop variable. This can be transformed to:
>
> if ((base & 3) != 0) {
>
> That check becomes loop independent and be optimized by loop predication (or I suppose loop unswitching but that wasn't the case of the micro benchmark I worked on).
>
> This change also optimizes the pattern:
>
> (offset << 2) & 3
>
> to return 0.
Looks good to me, I submitted testing.
src/hotspot/share/opto/mulnode.cpp line 702:
> 700:
> 701: Node* in1 = in(1);
> 702: int op = in1->Opcode();
I got curious and checked the code, we have similar patterns everywhere. Filed [JDK-8278328](https://bugs.openjdk.java.net/browse/JDK-8278328) to clean up this mess.
src/hotspot/share/opto/mulnode.cpp line 1753:
> 1751: }
> 1752:
> 1753: Node* MulNode::AndIL_add_shift_and_mask(PhaseGVN* phase, BasicType bt) {
Please add a comment describing the pattern.
test/hotspot/jtreg/compiler/c2/irTests/TestShiftAndMask.java line 30:
> 28: /*
> 29: * @test
> 30: * @bug JDK-8277850
Should be `@bug 8277850` (not sure if that is a requirement but all other tests use that format).
test/hotspot/jtreg/compiler/c2/irTests/TestShiftAndMask.java line 36:
> 34: */
> 35:
> 36: public class TestShiftAndMask {
Nice tests!
-------------
PR: https://git.openjdk.java.net/jdk/pull/6697
More information about the hotspot-compiler-dev
mailing list