RFR: 8346964: C2: Improve integer multiplication with constant in MulINode::Ideal()

erifan duke at openjdk.org
Mon Feb 10 21:25:01 UTC 2025


On Wed, 8 Jan 2025 01:35:08 GMT, erifan <duke at openjdk.org> wrote:

>> src/hotspot/share/opto/mulnode.cpp line 273:
>> 
>>> 271:         new LShiftINode(in(1), phase->intcon(log2i_exact(abs_con - 1))));
>>> 272:     res = new AddINode(in(1), n1);
>>> 273:   } else if (is_power_of_2(abs_con + 1)) {
>> 
>> So now you only check for `power_of_2   +- 1`, right? But before we also looked at patterns with 2 bits, such as `64 + 8`.
>> 
>> You would really need to prove that this is not a loss on any of the platforms we care about, incl. x64.
>
> Yes, I have tested the patch on several of x64 machines, including amd Genoa and Intel SPR and some older x86 machines, there's no noticeable performance loss.  Test results on aarch64 and amd Genoa were included in the commit message, please take a look, thanks~

> So now you only check for power_of_2 +- 1, right?

Yes now I only check these patterns:

1, Const = 1<<n,         (n > 0)
2, Const = -(1<<n),      (n > 0)
3, Const = (1<<n) + 1,   (n > 0)
4, Const = (1<<n) - 1,   (n > 0)
5, Const = -((1<<n) -1)  (n > 0)


Removed these patterns:

1, Const = (1<<m) + (1<<n)      (m > 0, n > 0)
2, Const = -((1<<m) + (1<<n))   (m > 0, n > 0)
3, Const = -((1<<n) + 1),       (n > 0)

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

PR Review Comment: https://git.openjdk.org/jdk/pull/22922#discussion_r1906305352


More information about the hotspot-compiler-dev mailing list