RFR: 8277850: C2: optimize mask checks in counted loops
Vladimir Kozlov
kvn at openjdk.java.net
Sat Dec 4 00:57:11 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.
src/hotspot/share/opto/mulnode.cpp line 514:
> 512: }
> 513:
> 514: return MulINode::Value(phase);
There is no `MulINode::value()` or `MulLNode::value()`, only based class `MulNode` have it.
You missing initial check done by `MulNode::value()`.
I suggest to move this code into `AndINode::mul_ring()` and `AndLNode::mul_ring()`.
Also in `mul_ring()` you can pass `r1->get_con()` as `mask` value to `AndIL_shift_and_mask()`.
src/hotspot/share/opto/mulnode.cpp line 1716:
> 1714: }
> 1715: }
> 1716:
Add comment here too which pattern it is looking for.
src/hotspot/share/opto/mulnode.cpp line 1717:
> 1715: }
> 1716:
> 1717: bool MulNode::AndIL_shift_and_mask(PhaseGVN* phase, Node* mask, Node* shift, BasicType bt) const {
Pass `mask` as value here.
src/hotspot/share/opto/mulnode.cpp line 1719:
> 1717: bool MulNode::AndIL_shift_and_mask(PhaseGVN* phase, Node* mask, Node* shift, BasicType bt) const {
> 1718: if (mask == NULL || shift == NULL) {
> 1719: return false;
You need to check `shift` for `TOP`.
src/hotspot/share/opto/mulnode.cpp line 1755:
> 1753: Node* MulNode::AndIL_add_shift_and_mask(PhaseGVN* phase, BasicType bt) {
> 1754: Node* in1 = in(1);
> 1755: Node* in2 = in(2);
Caller already determine that `in2` is `const int mask = t2->get_con()`. You can pass it here.
-------------
PR: https://git.openjdk.java.net/jdk/pull/6697
More information about the hotspot-compiler-dev
mailing list