src/share/vm/opto/addnode.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 6667595 Cdiff src/share/vm/opto/addnode.cpp

src/share/vm/opto/addnode.cpp

Print this page

        

*** 154,164 **** // Convert "(x+1)+y" into "(x+y)+1". Push constants down the expression tree. if( add1_op == this_op && !con_right ) { Node *a12 = add1->in(2); const Type *t12 = phase->type( a12 ); ! if( t12->singleton() && t12 != Type::TOP && (add1 != add1->in(1)) ) { assert(add1->in(1) != this, "dead loop in AddNode::Ideal"); add2 = add1->clone(); add2->set_req(2, in(2)); add2 = phase->transform(add2); set_req(1, add2); --- 154,165 ---- // Convert "(x+1)+y" into "(x+y)+1". Push constants down the expression tree. if( add1_op == this_op && !con_right ) { Node *a12 = add1->in(2); const Type *t12 = phase->type( a12 ); ! if( t12->singleton() && t12 != Type::TOP && (add1 != add1->in(1)) && ! !(add1->in(1)->is_Phi() && add1->in(1)->as_Phi()->is_tripcount()) ) { assert(add1->in(1) != this, "dead loop in AddNode::Ideal"); add2 = add1->clone(); add2->set_req(2, in(2)); add2 = phase->transform(add2); set_req(1, add2);
*** 171,181 **** // Convert "x+(y+1)" into "(x+y)+1". Push constants down the expression tree. int 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)) ) { assert(add2->in(1) != this, "dead loop in AddNode::Ideal"); Node *addx = add2->clone(); addx->set_req(1, in(1)); addx->set_req(2, add2->in(1)); addx = phase->transform(addx); --- 172,183 ---- // Convert "x+(y+1)" into "(x+y)+1". Push constants down the expression tree. int 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()) ) { assert(add2->in(1) != this, "dead loop in AddNode::Ideal"); Node *addx = add2->clone(); addx->set_req(1, in(1)); addx->set_req(2, add2->in(1)); addx = phase->transform(addx);
*** 223,260 **** //============================================================================= //------------------------------Idealize--------------------------------------- Node *AddINode::Ideal(PhaseGVN *phase, bool can_reshape) { ! int op1 = in(1)->Opcode(); ! int op2 = in(2)->Opcode(); // Fold (con1-x)+con2 into (con1+con2)-x if( op1 == Op_SubI ) { ! const Type *t_sub1 = phase->type( in(1)->in(1) ); ! const Type *t_2 = phase->type( in(2) ); if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP ) return new (phase->C, 3) SubINode(phase->makecon( add_ring( t_sub1, t_2 ) ), ! in(1)->in(2) ); // Convert "(a-b)+(c-d)" into "(a+c)-(b+d)" if( op2 == Op_SubI ) { // Check for dead cycle: d = (a-b)+(c-d) ! assert( in(1)->in(2) != this && in(2)->in(2) != this, "dead loop in AddINode::Ideal" ); Node *sub = new (phase->C, 3) SubINode(NULL, NULL); ! sub->init_req(1, phase->transform(new (phase->C, 3) AddINode(in(1)->in(1), in(2)->in(1) ) )); ! sub->init_req(2, phase->transform(new (phase->C, 3) AddINode(in(1)->in(2), in(2)->in(2) ) )); return sub; } } // Convert "x+(0-y)" into "(x-y)" ! if( op2 == Op_SubI && phase->type(in(2)->in(1)) == TypeInt::ZERO ) ! return new (phase->C, 3) SubINode(in(1), in(2)->in(2) ); // Convert "(0-y)+x" into "(x-y)" ! if( op1 == Op_SubI && phase->type(in(1)->in(1)) == TypeInt::ZERO ) ! return new (phase->C, 3) SubINode( in(2), in(1)->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: // Unrestricted transformation is unsafe for some runtime values of 'x' --- 225,291 ---- //============================================================================= //------------------------------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(); // Fold (con1-x)+con2 into (con1+con2)-x + if ( op1 == Op_AddI && op2 == Op_SubI ) { + // Swap edges to try optimizations below + in1 = in2; + in2 = in(1); + op1 = op2; + op2 = in2->Opcode(); + } if( op1 == 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 (phase->C, 3) 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 ) { // 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 (phase->C, 3) SubINode(NULL, NULL); ! sub->init_req(1, phase->transform(new (phase->C, 3) AddINode(in1->in(1), in2->in(1) ) )); ! sub->init_req(2, phase->transform(new (phase->C, 3) 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) ) { + assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal"); + return new (phase->C, 3) 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) ) { + assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddINode::Ideal"); + return new (phase->C, 3) 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) ) { + assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal"); + return new (phase->C, 3) 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) ) { + assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddINode::Ideal"); + return new (phase->C, 3) 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 ) ! return new (phase->C, 3) SubINode(in1, in2->in(2) ); // Convert "(0-y)+x" into "(x-y)" ! if( op1 == Op_SubI && phase->type(in1->in(1)) == TypeInt::ZERO ) ! return new (phase->C, 3) 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: // Unrestricted transformation is unsafe for some runtime values of 'x'
*** 264,282 **** // (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 && ! in(1)->in(2)->Opcode() == Op_ConI ) { ! jint z = phase->type( in(1)->in(2) )->is_int()->get_con() & 0x1f; // only least significant 5 bits matter ! jint y = phase->type( in(2) )->is_int()->get_con(); if( z < 5 && -5 < y && y < 0 ) { ! const Type *t_in11 = phase->type(in(1)->in(1)); if( t_in11 != Type::TOP && (t_in11->is_int()->_lo >= -(y << z)) ) { ! Node *a = phase->transform( new (phase->C, 3) AddINode( in(1)->in(1), phase->intcon(y<<z) ) ); ! return new (phase->C, 3) URShiftINode( a, in(1)->in(2) ); } } } return AddNode::Ideal(phase, can_reshape); --- 295,313 ---- // (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 ) { ! 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)); if( t_in11 != Type::TOP && (t_in11->is_int()->_lo >= -(y << z)) ) { ! Node *a = phase->transform( new (phase->C, 3) AddINode( in1->in(1), phase->intcon(y<<z) ) ); ! return new (phase->C, 3) URShiftINode( a, in1->in(2) ); } } } return AddNode::Ideal(phase, can_reshape);
*** 326,368 **** //============================================================================= //------------------------------Idealize--------------------------------------- Node *AddLNode::Ideal(PhaseGVN *phase, bool can_reshape) { ! int op1 = in(1)->Opcode(); ! int op2 = in(2)->Opcode(); // Fold (con1-x)+con2 into (con1+con2)-x if( op1 == Op_SubL ) { ! const Type *t_sub1 = phase->type( in(1)->in(1) ); ! const Type *t_2 = phase->type( in(2) ); if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP ) return new (phase->C, 3) SubLNode(phase->makecon( add_ring( t_sub1, t_2 ) ), ! in(1)->in(2) ); // Convert "(a-b)+(c-d)" into "(a+c)-(b+d)" if( op2 == Op_SubL ) { // Check for dead cycle: d = (a-b)+(c-d) ! assert( in(1)->in(2) != this && in(2)->in(2) != this, "dead loop in AddLNode::Ideal" ); Node *sub = new (phase->C, 3) SubLNode(NULL, NULL); ! sub->init_req(1, phase->transform(new (phase->C, 3) AddLNode(in(1)->in(1), in(2)->in(1) ) )); ! sub->init_req(2, phase->transform(new (phase->C, 3) AddLNode(in(1)->in(2), in(2)->in(2) ) )); return sub; } } // Convert "x+(0-y)" into "(x-y)" ! if( op2 == Op_SubL && phase->type(in(2)->in(1)) == TypeLong::ZERO ) ! return new (phase->C, 3) SubLNode(in(1), in(2)->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 && ! in(2)->in(1) == in(1) && op1 != Op_ConL && 0 ) { ! Node *shift = phase->transform(new (phase->C, 3) LShiftLNode(in(1),phase->intcon(1))); ! return new (phase->C, 3) AddLNode(shift,in(2)->in(2)); } return AddNode::Ideal(phase, can_reshape); } --- 357,433 ---- //============================================================================= //------------------------------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(); // Fold (con1-x)+con2 into (con1+con2)-x + if ( op1 == Op_AddL && op2 == 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 ) { ! 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 (phase->C, 3) 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 ) { // 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 (phase->C, 3) SubLNode(NULL, NULL); ! sub->init_req(1, phase->transform(new (phase->C, 3) AddLNode(in1->in(1), in2->in(1) ) )); ! sub->init_req(2, phase->transform(new (phase->C, 3) 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) ) { + assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal"); + return new (phase->C, 3) 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) ) { + assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal"); + return new (phase->C, 3) 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) ) { + assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal"); + return new (phase->C, 3) 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) ) { + assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal"); + return new (phase->C, 3) 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 ) ! return new (phase->C, 3) SubLNode( in1, in2->in(2) ); + // Convert "(0-y)+x" into "(x-y)" + if( op1 == Op_SubL && phase->type(in1->in(1)) == TypeInt::ZERO ) + return new (phase->C, 3) 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 && ! in2->in(1) == in1 && op1 != Op_ConL && 0 ) { ! Node *shift = phase->transform(new (phase->C, 3) LShiftLNode(in1,phase->intcon(1))); ! return new (phase->C, 3) AddLNode(shift,in2->in(2)); } return AddNode::Ideal(phase, can_reshape); }
src/share/vm/opto/addnode.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File