RFR: 8262341: Refine identical code in AddI/LNode.

Roland Westrelin roland at openjdk.java.net
Mon Dec 6 08:48:21 UTC 2021


On Mon, 6 Dec 2021 01:51:05 GMT, Eric Liu <eliu at openjdk.org> wrote:

>> AddINode::Ideal() and AddlNode::Ideal() are almost identical but the
>> same logic had to be duplicated because AddINode::Ideal() tests its
>> inputs for Op_AddI, Op_SubI etc. while AddLNode::Ideal() tests for
>> Op_AddL, Op_SubL etc. This patch refactors the code so the common
>> logic is in a single method parameterized by a BasicType argument.
>> 
>> The way I've done this before in the context of int/long counted loops
>> was to use and extra virtual method operates_on(). So:
>> 
>> n->Opcode() == Op_AddI becomes n->is_Add() && n->operates_on(T_INT)
>> 
>> Working on this change made me realize that pattern doesn't work that well:
>> 
>> - it's quite a bit more verbose and converting existing code is not as
>>   mechanical as we would like to avoid conversion errors.
>> 
>> - it breaks when a class has a subclass. For instance AddNode has
>>   OrINode and OrLNode as subclasses so testing for n->is_Add() returns
>>   true with an OrI node.
>> 
>> Instead, this change introduces new functions. For instance of
>> AddI/AddL:
>> 
>> int Op_Add(BasicType bt)
>> 
>> that returns either Op_AddI or Op_AddL depending on bt. This made
>> refactoring the AddINode::Ideal() logic straightforward. I removed all
>> use of operates_on() as well and converted existing code to the new
>> Op_XXX() functions.
>
> src/hotspot/share/opto/addnode.cpp line 280:
> 
>> 278:   }
>> 279:   if (op1 == Op_Sub(bt)) {
>> 280:     const Type *t_sub1 = phase->type(in1->in(1));
> 
> I'm not very clear about the current code style which we should follow. Shall we need to align the style in the changed code?

Are you commenting about the change from:
if( op1 to if (op1
?
The first style is used in a some places and the guideline is to switch to the second one.

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

PR: https://git.openjdk.java.net/jdk/pull/6607


More information about the hotspot-compiler-dev mailing list