Skip to content
Permalink
Browse files
8264020: Optimize double negation elimination
Reviewed-by: thartmann, chagedorn
  • Loading branch information
theRealELiu authored and Ningsheng Jian committed Mar 30, 2021
1 parent 4ffa41c commit f3726a87007f2ec40ff961824f6efe99862284d8
Showing with 9 additions and 7 deletions.
  1. +9 −7 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
@@ -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;
@@ -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) )

1 comment on commit f3726a8

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on f3726a8 Mar 30, 2021

Please sign in to comment.