8261008: Optimize Xor

Reviewed-by: thartmann, kvn
This commit is contained in:
Eric Liu 2021-03-06 08:52:35 +00:00 committed by Vladimir Kozlov
parent e1cad97049
commit 23ee60d1b7
2 changed files with 33 additions and 1 deletions
src/hotspot/share/opto

@ -913,6 +913,22 @@ const Type *OrLNode::add_ring( const Type *t0, const Type *t1 ) const {
}
//=============================================================================
const Type* XorINode::Value(PhaseGVN* phase) const {
Node* in1 = in(1);
Node* in2 = in(2);
const Type* t1 = phase->type(in1);
const Type* t2 = phase->type(in2);
if (t1 == Type::TOP || t2 == Type::TOP) {
return Type::TOP;
}
// x ^ x ==> 0
if (in1->eqv_uncast(in2)) {
return add_id();
}
return AddNode::Value(phase);
}
//------------------------------add_ring---------------------------------------
// Supplied function returns the sum of the inputs IN THE CURRENT RING. For
// the logical operations the ring's ADD is really a logical OR function.
@ -948,6 +964,20 @@ const Type *XorLNode::add_ring( const Type *t0, const Type *t1 ) const {
return TypeLong::make( r0->get_con() ^ r1->get_con() );
}
const Type* XorLNode::Value(PhaseGVN* phase) const {
Node* in1 = in(1);
Node* in2 = in(2);
const Type* t1 = phase->type(in1);
const Type* t2 = phase->type(in2);
if (t1 == Type::TOP || t2 == Type::TOP) {
return Type::TOP;
}
// x ^ x ==> 0
if (in1->eqv_uncast(in2)) {
return add_id();
}
return AddNode::Value(phase);
}
Node* MaxNode::build_min_max(Node* a, Node* b, bool is_max, bool is_unsigned, const Type* t, PhaseGVN& gvn) {
bool is_int = gvn.type(a)->isa_int();

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, 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
@ -212,6 +212,7 @@ public:
virtual const Type *add_ring( const Type *, const Type * ) const;
virtual const Type *add_id() const { return TypeInt::ZERO; }
virtual const Type *bottom_type() const { return TypeInt::INT; }
virtual const Type *Value(PhaseGVN *phase) const;
virtual uint ideal_reg() const { return Op_RegI; }
};
@ -224,6 +225,7 @@ public:
virtual const Type *add_ring( const Type *, const Type * ) const;
virtual const Type *add_id() const { return TypeLong::ZERO; }
virtual const Type *bottom_type() const { return TypeLong::LONG; }
virtual const Type *Value(PhaseGVN *phase) const;
virtual uint ideal_reg() const { return Op_RegL; }
};