Skip to content

Commit 23ee60d

Browse files
Eric LiuVladimir Kozlov
authored andcommitted
8261008: Optimize Xor
Reviewed-by: thartmann, kvn
1 parent e1cad97 commit 23ee60d

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/hotspot/share/opto/addnode.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,22 @@ const Type *OrLNode::add_ring( const Type *t0, const Type *t1 ) const {
913913
}
914914

915915
//=============================================================================
916+
917+
const Type* XorINode::Value(PhaseGVN* phase) const {
918+
Node* in1 = in(1);
919+
Node* in2 = in(2);
920+
const Type* t1 = phase->type(in1);
921+
const Type* t2 = phase->type(in2);
922+
if (t1 == Type::TOP || t2 == Type::TOP) {
923+
return Type::TOP;
924+
}
925+
// x ^ x ==> 0
926+
if (in1->eqv_uncast(in2)) {
927+
return add_id();
928+
}
929+
return AddNode::Value(phase);
930+
}
931+
916932
//------------------------------add_ring---------------------------------------
917933
// Supplied function returns the sum of the inputs IN THE CURRENT RING. For
918934
// 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 {
948964
return TypeLong::make( r0->get_con() ^ r1->get_con() );
949965
}
950966

967+
const Type* XorLNode::Value(PhaseGVN* phase) const {
968+
Node* in1 = in(1);
969+
Node* in2 = in(2);
970+
const Type* t1 = phase->type(in1);
971+
const Type* t2 = phase->type(in2);
972+
if (t1 == Type::TOP || t2 == Type::TOP) {
973+
return Type::TOP;
974+
}
975+
// x ^ x ==> 0
976+
if (in1->eqv_uncast(in2)) {
977+
return add_id();
978+
}
979+
return AddNode::Value(phase);
980+
}
951981

952982
Node* MaxNode::build_min_max(Node* a, Node* b, bool is_max, bool is_unsigned, const Type* t, PhaseGVN& gvn) {
953983
bool is_int = gvn.type(a)->isa_int();

src/hotspot/share/opto/addnode.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -212,6 +212,7 @@ class XorINode : public AddNode {
212212
virtual const Type *add_ring( const Type *, const Type * ) const;
213213
virtual const Type *add_id() const { return TypeInt::ZERO; }
214214
virtual const Type *bottom_type() const { return TypeInt::INT; }
215+
virtual const Type *Value(PhaseGVN *phase) const;
215216
virtual uint ideal_reg() const { return Op_RegI; }
216217
};
217218

@@ -224,6 +225,7 @@ class XorLNode : public AddNode {
224225
virtual const Type *add_ring( const Type *, const Type * ) const;
225226
virtual const Type *add_id() const { return TypeLong::ZERO; }
226227
virtual const Type *bottom_type() const { return TypeLong::LONG; }
228+
virtual const Type *Value(PhaseGVN *phase) const;
227229
virtual uint ideal_reg() const { return Op_RegL; }
228230
};
229231

0 commit comments

Comments
 (0)