< prev index next >

## src/share/vm/opto/addnode.cpp

Print this page

```@@ -45,11 +45,11 @@
//------------------------------hash-------------------------------------------
// Hash function over AddNodes.  Needs to be commutative; i.e., I swap
// (commute) inputs to AddNodes willy-nilly so the hash function must return
// the same value in the presence of edge swapping.
uint AddNode::hash() const {
-  return (uintptr_t)in(1) + (uintptr_t)in(2) + Opcode();
+  return (uintptr_t)in(1) + (uintptr_t)in(2) + static_cast<uint>(Opcode());
}

//------------------------------Identity---------------------------------------
// If either input is a constant 0, return the other input.
Node* AddNode::Identity(PhaseGVN* phase) {
```

```@@ -121,23 +121,23 @@
// Convert "(x+1)+2" into "x+(1+2)".  If the right input is a
// constant, and the left input is an add of a constant, flatten the
// expression tree.
Node *add1 = in(1);
Node *add2 = in(2);
-  int add1_op = add1->Opcode();
-  int this_op = Opcode();
+  Opcodes add1_op = add1->Opcode();
+  Opcodes this_op = Opcode();
if( con_right && t2 != Type::TOP && // Right input is a constant?
add1_op == this_op ) { // Left input is an Add?

// Type of left _in right input
const Type *t12 = phase->type( add1->in(2) );
if( t12->singleton() && t12 != Type::TOP ) { // Left input is an add of a constant?
// Check for rare case of closed data cycle which can happen inside
// unreachable loops. In these cases the computation is undefined.
#ifdef ASSERT
Node *add11    = add1->in(1);
-      int   add11_op = add11->Opcode();
+      Opcodes  add11_op = add11->Opcode();
if( (add1 == add1->in(1))
|| (add11_op == this_op && add11->in(1) == add1) ) {
assert(false, "dead loop in AddNode::Ideal");
}
#endif
```

```@@ -174,11 +174,11 @@
add2 = a12;
}
}

// Convert "x+(y+1)" into "(x+y)+1".  Push constants down the expression tree.
-  int add2_op = add2->Opcode();
+  Opcodes add2_op = add2->Opcode();
if( add2_op == this_op && !con_left ) {
Node *a22 = add2->in(2);
const Type *t22 = phase->type( a22 );
if( t22->singleton() && t22 != Type::TOP && (add2 != add2->in(1)) &&
!(add2->in(1)->is_Phi() && add2->in(1)->as_Phi()->is_tripcount()) ) {
```

```@@ -238,63 +238,63 @@
//=============================================================================
//------------------------------Idealize---------------------------------------
Node *AddINode::Ideal(PhaseGVN *phase, bool can_reshape) {
Node* in1 = in(1);
Node* in2 = in(2);
-  int op1 = in1->Opcode();
-  int op2 = in2->Opcode();
+  Opcodes op1 = in1->Opcode();
+  Opcodes op2 = in2->Opcode();
// Fold (con1-x)+con2 into (con1+con2)-x
-  if ( op1 == Op_AddI && op2 == Op_SubI ) {
+  if ( op1 == Opcodes::Op_AddI && op2 == Opcodes::Op_SubI ) {
// Swap edges to try optimizations below
in1 = in2;
in2 = in(1);
op1 = op2;
op2 = in2->Opcode();
}
-  if( op1 == Op_SubI ) {
+  if( op1 == Opcodes::Op_SubI ) {
const Type *t_sub1 = phase->type( in1->in(1) );
const Type *t_2    = phase->type( in2        );
if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP )
return new SubINode(phase->makecon( add_ring( t_sub1, t_2 ) ), in1->in(2) );
// Convert "(a-b)+(c-d)" into "(a+c)-(b+d)"
-    if( op2 == Op_SubI ) {
+    if( op2 == Opcodes::Op_SubI ) {
// Check for dead cycle: d = (a-b)+(c-d)
assert( in1->in(2) != this && in2->in(2) != this,
"dead loop in AddINode::Ideal" );
Node *sub  = new SubINode(NULL, NULL);
sub->init_req(1, phase->transform(new AddINode(in1->in(1), in2->in(1) ) ));
sub->init_req(2, phase->transform(new AddINode(in1->in(2), in2->in(2) ) ));
return sub;
}
// Convert "(a-b)+(b+c)" into "(a+c)"
-    if( op2 == Op_AddI && in1->in(2) == in2->in(1) ) {
+    if( op2 == Opcodes::Op_AddI && in1->in(2) == in2->in(1) ) {
assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal");
return new AddINode(in1->in(1), in2->in(2));
}
// Convert "(a-b)+(c+b)" into "(a+c)"
-    if( op2 == Op_AddI && in1->in(2) == in2->in(2) ) {
+    if( op2 == Opcodes::Op_AddI && in1->in(2) == in2->in(2) ) {
assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddINode::Ideal");
return new AddINode(in1->in(1), in2->in(1));
}
// Convert "(a-b)+(b-c)" into "(a-c)"
-    if( op2 == Op_SubI && in1->in(2) == in2->in(1) ) {
+    if( op2 == Opcodes::Op_SubI && in1->in(2) == in2->in(1) ) {
assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal");
return new SubINode(in1->in(1), in2->in(2));
}
// Convert "(a-b)+(c-a)" into "(c-b)"
-    if( op2 == Op_SubI && in1->in(1) == in2->in(2) ) {
+    if( op2 == Opcodes::Op_SubI && in1->in(1) == in2->in(2) ) {
assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddINode::Ideal");
return new SubINode(in2->in(1), in1->in(2));
}
}

// Convert "x+(0-y)" into "(x-y)"
-  if( op2 == Op_SubI && phase->type(in2->in(1)) == TypeInt::ZERO )
+  if( op2 == Opcodes::Op_SubI && phase->type(in2->in(1)) == TypeInt::ZERO )
return new SubINode(in1, in2->in(2) );

// Convert "(0-y)+x" into "(x-y)"
-  if( op1 == Op_SubI && phase->type(in1->in(1)) == TypeInt::ZERO )
+  if( op1 == Opcodes::Op_SubI && phase->type(in1->in(1)) == TypeInt::ZERO )
return new SubINode( in2, in1->in(2) );

// Convert (x>>>z)+y into (x+(y<<z))>>>z for small constant z and y.
// Helps with array allocation math constant folding
// See 4790063:
```

```@@ -304,12 +304,12 @@
// Transform works for small z and small negative y when the addition
// (x + (y << z)) does not cross zero.
// Implement support for negative y and (x >= -(y << z))
// Have not observed cases where type information exists to support
// positive y and (x <= -(y << z))
-  if( op1 == Op_URShiftI && op2 == Op_ConI &&
-      in1->in(2)->Opcode() == Op_ConI ) {
+  if( op1 == Opcodes::Op_URShiftI && op2 == Opcodes::Op_ConI &&
+      in1->in(2)->Opcode() == Opcodes::Op_ConI ) {
jint z = phase->type( in1->in(2) )->is_int()->get_con() & 0x1f; // only least significant 5 bits matter
jint y = phase->type( in2 )->is_int()->get_con();

if( z < 5 && -5 < y && y < 0 ) {
const Type *t_in11 = phase->type(in1->in(1));
```

```@@ -325,14 +325,14 @@

//------------------------------Identity---------------------------------------
// Fold (x-y)+y  OR  y+(x-y)  into  x
Node* AddINode::Identity(PhaseGVN* phase) {
-  if( in(1)->Opcode() == Op_SubI && phase->eqv(in(1)->in(2),in(2)) ) {
+  if( in(1)->Opcode() == Opcodes::Op_SubI && phase->eqv(in(1)->in(2),in(2)) ) {
return in(1)->in(1);
}
-  else if( in(2)->Opcode() == Op_SubI && phase->eqv(in(2)->in(2),in(1)) ) {
+  else if( in(2)->Opcode() == Opcodes::Op_SubI && phase->eqv(in(2)->in(2),in(1)) ) {
return in(2)->in(1);
}
return AddNode::Identity(phase);
}

```

```@@ -369,71 +369,71 @@
//=============================================================================
//------------------------------Idealize---------------------------------------
Node *AddLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
Node* in1 = in(1);
Node* in2 = in(2);
-  int op1 = in1->Opcode();
-  int op2 = in2->Opcode();
+  Opcodes op1 = in1->Opcode();
+  Opcodes op2 = in2->Opcode();
// Fold (con1-x)+con2 into (con1+con2)-x
-  if ( op1 == Op_AddL && op2 == Op_SubL ) {
+  if ( op1 == Opcodes::Op_AddL && op2 == Opcodes::Op_SubL ) {
// Swap edges to try optimizations below
in1 = in2;
in2 = in(1);
op1 = op2;
op2 = in2->Opcode();
}
// Fold (con1-x)+con2 into (con1+con2)-x
-  if( op1 == Op_SubL ) {
+  if( op1 == Opcodes::Op_SubL ) {
const Type *t_sub1 = phase->type( in1->in(1) );
const Type *t_2    = phase->type( in2        );
if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP )
return new SubLNode(phase->makecon( add_ring( t_sub1, t_2 ) ), in1->in(2) );
// Convert "(a-b)+(c-d)" into "(a+c)-(b+d)"
-    if( op2 == Op_SubL ) {
+    if( op2 == Opcodes::Op_SubL ) {
// Check for dead cycle: d = (a-b)+(c-d)
assert( in1->in(2) != this && in2->in(2) != this,
"dead loop in AddLNode::Ideal" );
Node *sub  = new SubLNode(NULL, NULL);
sub->init_req(1, phase->transform(new AddLNode(in1->in(1), in2->in(1) ) ));
sub->init_req(2, phase->transform(new AddLNode(in1->in(2), in2->in(2) ) ));
return sub;
}
// Convert "(a-b)+(b+c)" into "(a+c)"
-    if( op2 == Op_AddL && in1->in(2) == in2->in(1) ) {
+    if( op2 == Opcodes::Op_AddL && in1->in(2) == in2->in(1) ) {
assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal");
return new AddLNode(in1->in(1), in2->in(2));
}
// Convert "(a-b)+(c+b)" into "(a+c)"
-    if( op2 == Op_AddL && in1->in(2) == in2->in(2) ) {
+    if( op2 == Opcodes::Op_AddL && in1->in(2) == in2->in(2) ) {
assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal");
return new AddLNode(in1->in(1), in2->in(1));
}
// Convert "(a-b)+(b-c)" into "(a-c)"
-    if( op2 == Op_SubL && in1->in(2) == in2->in(1) ) {
+    if( op2 == Opcodes::Op_SubL && in1->in(2) == in2->in(1) ) {
assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal");
return new SubLNode(in1->in(1), in2->in(2));
}
// Convert "(a-b)+(c-a)" into "(c-b)"
-    if( op2 == Op_SubL && in1->in(1) == in1->in(2) ) {
+    if( op2 == Opcodes::Op_SubL && in1->in(1) == in1->in(2) ) {
assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal");
return new SubLNode(in2->in(1), in1->in(2));
}
}

// Convert "x+(0-y)" into "(x-y)"
-  if( op2 == Op_SubL && phase->type(in2->in(1)) == TypeLong::ZERO )
+  if( op2 == Opcodes::Op_SubL && phase->type(in2->in(1)) == TypeLong::ZERO )
return new SubLNode( in1, in2->in(2) );

// Convert "(0-y)+x" into "(x-y)"
-  if( op1 == Op_SubL && phase->type(in1->in(1)) == TypeInt::ZERO )
+  if( op1 == Opcodes::Op_SubL && phase->type(in1->in(1)) == TypeInt::ZERO )
return new SubLNode( in2, in1->in(2) );

// Convert "X+X+X+X+X...+X+Y" into "k*X+Y" or really convert "X+(X+Y)"
// into "(X<<1)+Y" and let shift-folding happen.
-  if( op2 == Op_AddL &&
+  if( op2 == Opcodes::Op_AddL &&
in2->in(1) == in1 &&
-      op1 != Op_ConL &&
+      op1 != Opcodes::Op_ConL &&
0 ) {
Node *shift = phase->transform(new LShiftLNode(in1,phase->intcon(1)));
return new AddLNode(shift,in2->in(2));
}

```

```@@ -442,14 +442,14 @@

//------------------------------Identity---------------------------------------
// Fold (x-y)+y  OR  y+(x-y)  into  x
Node* AddLNode::Identity(PhaseGVN* phase) {
-  if( in(1)->Opcode() == Op_SubL && phase->eqv(in(1)->in(2),in(2)) ) {
+  if( in(1)->Opcode() == Opcodes::Op_SubL && phase->eqv(in(1)->in(2),in(2)) ) {
return in(1)->in(1);
}
-  else if( in(2)->Opcode() == Op_SubL && phase->eqv(in(2)->in(2),in(1)) ) {
+  else if( in(2)->Opcode() == Opcodes::Op_SubL && phase->eqv(in(2)->in(2),in(1)) ) {
return in(2)->in(1);
}
return AddNode::Identity(phase);
}

```

```@@ -621,11 +621,11 @@
// If the right is an add of a constant, push the offset down.
// Convert: (ptr + (offset+con)) into (ptr+offset)+con.
// The idea is to merge array_base+scaled_index groups together,
// and only have different constant offsets from the same base.
const Node *add = in(Offset);
-  if( add->Opcode() == Op_AddX && add->in(1) != add ) {
+  if( add->Opcode() == Opcodes::Op_AddX && add->in(1) != add ) {
const Type *t22 = phase->type( add->in(2) );
if( t22->singleton() && (t22 != Type::TOP) ) {  // Right input is an add of a constant?
set_req(Address, phase->transform(new AddPNode(in(Base),in(Address),add->in(1))));
set_req(Offset, add->in(2));
PhaseIterGVN *igvn = phase->is_IterGVN();
```

```@@ -644,11 +644,11 @@
// Bottom-type is the pointer-type with unknown offset.
const Type *AddPNode::bottom_type() const {
if (in(Address) == NULL)  return TypePtr::BOTTOM;
const TypePtr *tp = in(Address)->bottom_type()->isa_ptr();
if( !tp ) return Type::TOP;   // TOP input means TOP output
-  assert( in(Offset)->Opcode() != Op_ConP, "" );
+  assert( in(Offset)->Opcode() != Opcodes::Op_ConP, "" );
const Type *t = in(Offset)->bottom_type();
if( t == Type::TOP )
return tp->add_offset(Type::OffsetTop);
const TypeX *tx = t->is_intptr_t();
intptr_t txoffset = Type::OffsetBot;
```

```@@ -852,11 +852,11 @@
// Force a right-spline graph
Node *l = in(1);
Node *r = in(2);
// Transform  MinI1( MinI2(a,b), c)  into  MinI1( a, MinI2(b,c) )
// to force a right-spline graph for the rest of MinINode::Ideal().
-  if( l->Opcode() == Op_MinI ) {
+  if( l->Opcode() == Opcodes::Op_MinI ) {
assert( l != l->in(1), "dead loop in MinINode::Ideal" );
r = phase->transform(new MinINode(l->in(2),r));
l = l->in(1);
set_req(1, l);
set_req(2, r);
```

```@@ -864,11 +864,11 @@
}

// Get left input & constant
Node *x = l;
int x_off = 0;
-  if( x->Opcode() == Op_AddI && // Check for "x+c0" and collect constant
+  if( x->Opcode() == Opcodes::Op_AddI && // Check for "x+c0" and collect constant
x->in(2)->is_Con() ) {
const Type *t = x->in(2)->bottom_type();
if( t == Type::TOP ) return NULL;  // No progress
x_off = t->is_int()->get_con();
x = x->in(1);
```

```@@ -876,28 +876,28 @@

// Scan a right-spline-tree for MINs
Node *y = r;
int y_off = 0;
// Check final part of MIN tree
-  if( y->Opcode() == Op_AddI && // Check for "y+c1" and collect constant
+  if( y->Opcode() == Opcodes::Op_AddI && // Check for "y+c1" and collect constant
y->in(2)->is_Con() ) {
const Type *t = y->in(2)->bottom_type();
if( t == Type::TOP ) return NULL;  // No progress
y_off = t->is_int()->get_con();
y = y->in(1);
}
-  if( x->_idx > y->_idx && r->Opcode() != Op_MinI ) {
+  if( x->_idx > y->_idx && r->Opcode() != Opcodes::Op_MinI ) {
swap_edges(1, 2);
return this;
}

-  if( r->Opcode() == Op_MinI ) {
+  if( r->Opcode() == Opcodes::Op_MinI ) {
assert( r != r->in(2), "dead loop in MinINode::Ideal" );
y = r->in(1);
// Check final part of MIN tree
-    if( y->Opcode() == Op_AddI &&// Check for "y+c1" and collect constant
+    if( y->Opcode() == Opcodes::Op_AddI &&// Check for "y+c1" and collect constant
y->in(2)->is_Con() ) {
const Type *t = y->in(2)->bottom_type();
if( t == Type::TOP ) return NULL;  // No progress
y_off = t->is_int()->get_con();
y = y->in(1);
```
< prev index next >