RFR: 8291336: Add ideal rule to convert floating point multiply by 2 into addition [v4]
SuperCoder79
duke at openjdk.org
Thu Aug 25 17:13:31 UTC 2022
On Thu, 4 Aug 2022 15:05:53 GMT, SuperCoder79 <duke at openjdk.org> wrote:
>> Hello,
>> I would like to propose an ideal transform that converts floating point multiply by 2 (`x * 2`) into an addition operation instead. This would allow for the elimination of the memory reference for the constant two, and keep the whole operation inside registers. My justifications for this optimization include:
>> * As per [Agner Fog's instruction tables](https://www.agner.org/optimize/instruction_tables.pdf) many older systems, such as the sandy bridge and ivy bridge architectures, have different latencies for addition and multiplication meaning this change could have beneficial effects when in hot code.
>> * The removal of the memory load would have a beneficial effect in cache bound situations.
>> * Multiplication by 2 is relatively common construct so this change can apply to a wide range of Java code.
>>
>> As this is my first time looking into the c2 codebase, I have a few lingering questions about my implementation and how certain parts of the compiler work. Mainly, is this patch getting the type of the operands correctly? I saw some cases where code used `bottom_type()` and other cases where it used `phase->type(value)`. Similarly, are nodes able to be reused as is being done in the AddNode constructors? I saw some places where the clone method was being used, but other places where it wasn't.
>>
>> I have attached an IR test and a jmh benchmark. Tier 1 testing passes on my machine.
>>
>> Thanks for your time,
>> Jasmine
>
> SuperCoder79 has updated the pull request incrementally with one additional commit since the last revision:
>
> Apply style changes from code review
Hi, may I have more reviews on this change, please?
Thanks
-------------
PR: https://git.openjdk.org/jdk/pull/9642
More information about the hotspot-compiler-dev
mailing list