RFR: 8291336: Add ideal rule to convert floating point multiply by 2 into addition [v2]
SuperCoder79
duke at openjdk.org
Sat Jul 30 03:04:17 UTC 2022
On Wed, 27 Jul 2022 15:54:01 GMT, Quan Anh Mai <duke at openjdk.org> wrote:
>> SuperCoder79 has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Apply changes from code review and improve benchmark
>
> src/hotspot/share/opto/mulnode.cpp line 439:
>
>> 437: // Check to see if we are multiplying by a constant 2 and convert to add, then try the regular MulNode::Ideal
>> 438: Node *MulFNode::Ideal(PhaseGVN *phase, bool can_reshape) {
>> 439: const TypeF *t1 = in(1)->bottom_type()->isa_float_constant();
>
> `phase->type(Node*)` refers to the type inferred by the GVN in this phase, while `Node::bottom_type()` refers to the loosest type the node can have. For example, the bottom type of an `AddINode` is always `TypeInt::INT` (every `int` value possible) while the GVN can ensure a stricter type if it knows both the inputs are integers between 0 and 10. In this case, you obtain the correct type nonetheless because `ConNode` extends `TypeNode`, a family of nodes which has their bottom types updated by the GVN. In general, in idealisation, it is more efficient to use `phase->type(Node*)`.
Thank you for this perspective! I have updated the code to use `phase->type()`.
> src/hotspot/share/opto/mulnode.cpp line 442:
>
>> 440: const TypeF *t2 = in(2)->bottom_type()->isa_float_constant();
>> 441:
>> 442: // x * 2 -> x + x
>
> Since constants are always pushed to the right of the expression, you don't need to try both permutations of the pattern.
Done, thanks!
> test/hotspot/jtreg/compiler/c2/irTests/TestMulBy2.java line 37:
>
>> 35: * @run driver compiler.c2.irTests.TestMulBy2
>> 36: */
>> 37: public class TestMulBy2 {
>
> Please use a more general name such as `MulFNodeIdealizationTests`
Done
-------------
PR: https://git.openjdk.org/jdk/pull/9642
More information about the hotspot-compiler-dev
mailing list