Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8264020: Optimize double negation elimination
Reviewed-by: thartmann, chagedorn
  • Loading branch information
e1iu authored and Ningsheng Jian committed Mar 30, 2021
1 parent 4ffa41c commit f3726a8
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/hotspot/share/opto/subnode.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -235,9 +235,10 @@ Node *SubINode::Ideal(PhaseGVN *phase, bool can_reshape){
return new SubINode(phase->intcon(0), in2->in(1));
}

// Convert "0 - (x-y)" into "y-x"
if( t1 == TypeInt::ZERO && op2 == Op_SubI )
return new SubINode( in2->in(2), in2->in(1) );
// Convert "0 - (x-y)" into "y-x", leave the double negation "-(-y)" to SubNode::Identity().
if (t1 == TypeInt::ZERO && op2 == Op_SubI && phase->type(in2->in(1)) != TypeInt::ZERO) {
return new SubINode(in2->in(2), in2->in(1));
}

// Convert "0 - (x+con)" into "-con-x"
jint con;
Expand Down Expand Up @@ -373,9 +374,10 @@ Node *SubLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
return new SubLNode(phase->makecon(TypeLong::ZERO), in2->in(1));
}

// Convert "0 - (x-y)" into "y-x"
if( phase->type( in1 ) == TypeLong::ZERO && op2 == Op_SubL )
return new SubLNode( in2->in(2), in2->in(1) );
// Convert "0 - (x-y)" into "y-x", leave the double negation "-(-y)" to SubNode::Identity.
if (t1 == TypeLong::ZERO && op2 == Op_SubL && phase->type(in2->in(1)) != TypeLong::ZERO) {
return new SubLNode(in2->in(2), in2->in(1));
}

// Convert "(X+A) - (X+B)" into "A - B"
if( op1 == Op_AddL && op2 == Op_AddL && in1->in(1) == in2->in(1) )
Expand Down

1 comment on commit f3726a8

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.