RFR: 8277850: C2: optimize mask checks in counted loops
Roland Westrelin
roland at openjdk.java.net
Mon Dec 6 08:45:16 UTC 2021
On Sat, 4 Dec 2021 00:33:04 GMT, Vladimir Kozlov <kvn 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()`.
Thanks for reviewing this.
MulNode::AndIL_shift_and_mask() needs the shift node so it can test for shift->Opcode() == Op_ConvI2L. mult_ring() only gets the Type* as input. Are you suggesting to change mul_ring's signature?
> 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`.
Code below:
const TypeInteger* shift_t = phase->type(shift)->isa_integer(bt);
if (mask_t == NULL || shift_t == NULL) {
catches the case where shift is top, I think.
-------------
PR: https://git.openjdk.java.net/jdk/pull/6697
More information about the hotspot-compiler-dev
mailing list