RFR: 8264020: Optimize double negation elimination
Tobias Hartmann
thartmann at openjdk.java.net
Mon Mar 29 08:12:33 UTC 2021
On Sun, 28 Mar 2021 01:36:56 GMT, Eric Liu <github.com+10482586+theRealELiu at openjdk.org> wrote:
> For the double negation '-(-x)', c2 could reduce the redundant 'sub'
> through SubNode::Ideal. But every time when 'sub' is removed, there
> would generate two useless nodes SubNode(x, 0)[1] and AddNode(x, -0)[2],
> which would be removed by later phases but should have optimized better
> to 'x' itself without generating those new stuffs.
>
> This patch is a small fix for SubNode's Ideal, by leaving this special
> case to 'Identity' which handled double negation already[3].
>
> [1] https://github.com/openjdk/jdk/blob/master/src/hotspot/share/opto/subnode.cpp#L238
> [2] https://github.com/openjdk/jdk/blob/master/src/hotspot/share/opto/subnode.cpp#L181
> [3] https://github.com/openjdk/jdk/blob/master/src/hotspot/share/opto/subnode.cpp#L55
Otherwise, looks good to me.
src/hotspot/share/opto/subnode.cpp line 239:
> 237:
> 238: // Convert "0 - (x-y)" into "y-x", leave the double negation "-(-y)" to SubNode::Identity().
> 239: if(t1 == TypeInt::ZERO && op2 == Op_SubI && phase->type(in2->in(1)) != TypeInt::ZERO)
Since you are modifying that code, please also add parentheses around the body, update the code style and add a whitespace between `if` and the condition.
-------------
Marked as reviewed by thartmann (Reviewer).
PR: https://git.openjdk.java.net/jdk/pull/3231
More information about the hotspot-compiler-dev
mailing list