Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8261008: Optimize Xor
Reviewed-by: thartmann, kvn
  • Loading branch information
theRealELiu authored and Vladimir Kozlov committed Mar 6, 2021
1 parent e1cad97 commit 23ee60d1b7e1fd7b9f961364efb137fcc16bf34e
Showing with 33 additions and 1 deletion.
  1. +30 −0 src/hotspot/share/opto/addnode.cpp
  2. +3 −1 src/hotspot/share/opto/addnode.hpp
@@ -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 @@ class XorINode : public AddNode {
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 @@ class XorLNode : public AddNode {
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; }
};

0 comments on commit 23ee60d

Please sign in to comment.