comparison src/share/vm/opto/addnode.cpp @ 400:cc80376deb0c

6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop Summary: Fix loop's probability. Add optimizations to avoid spilling. Change InlineSmallCode to product flag. Reviewed-by: never
author kvn
date Thu, 02 Oct 2008 08:37:44 -0700
parents 2b73d212b1fd
children 660978a2a31a
comparison
equal deleted inserted replaced
372:be41fa651400 400:cc80376deb0c
154 154
155 // Convert "(x+1)+y" into "(x+y)+1". Push constants down the expression tree. 155 // Convert "(x+1)+y" into "(x+y)+1". Push constants down the expression tree.
156 if( add1_op == this_op && !con_right ) { 156 if( add1_op == this_op && !con_right ) {
157 Node *a12 = add1->in(2); 157 Node *a12 = add1->in(2);
158 const Type *t12 = phase->type( a12 ); 158 const Type *t12 = phase->type( a12 );
159 if( t12->singleton() && t12 != Type::TOP && (add1 != add1->in(1)) ) { 159 if( t12->singleton() && t12 != Type::TOP && (add1 != add1->in(1)) &&
160 !(add1->in(1)->is_Phi() && add1->in(1)->as_Phi()->is_tripcount()) ) {
160 assert(add1->in(1) != this, "dead loop in AddNode::Ideal"); 161 assert(add1->in(1) != this, "dead loop in AddNode::Ideal");
161 add2 = add1->clone(); 162 add2 = add1->clone();
162 add2->set_req(2, in(2)); 163 add2->set_req(2, in(2));
163 add2 = phase->transform(add2); 164 add2 = phase->transform(add2);
164 set_req(1, add2); 165 set_req(1, add2);
171 // Convert "x+(y+1)" into "(x+y)+1". Push constants down the expression tree. 172 // Convert "x+(y+1)" into "(x+y)+1". Push constants down the expression tree.
172 int add2_op = add2->Opcode(); 173 int add2_op = add2->Opcode();
173 if( add2_op == this_op && !con_left ) { 174 if( add2_op == this_op && !con_left ) {
174 Node *a22 = add2->in(2); 175 Node *a22 = add2->in(2);
175 const Type *t22 = phase->type( a22 ); 176 const Type *t22 = phase->type( a22 );
176 if( t22->singleton() && t22 != Type::TOP && (add2 != add2->in(1)) ) { 177 if( t22->singleton() && t22 != Type::TOP && (add2 != add2->in(1)) &&
178 !(add2->in(1)->is_Phi() && add2->in(1)->as_Phi()->is_tripcount()) ) {
177 assert(add2->in(1) != this, "dead loop in AddNode::Ideal"); 179 assert(add2->in(1) != this, "dead loop in AddNode::Ideal");
178 Node *addx = add2->clone(); 180 Node *addx = add2->clone();
179 addx->set_req(1, in(1)); 181 addx->set_req(1, in(1));
180 addx->set_req(2, add2->in(1)); 182 addx->set_req(2, add2->in(1));
181 addx = phase->transform(addx); 183 addx = phase->transform(addx);
223 225
224 226
225 //============================================================================= 227 //=============================================================================
226 //------------------------------Idealize--------------------------------------- 228 //------------------------------Idealize---------------------------------------
227 Node *AddINode::Ideal(PhaseGVN *phase, bool can_reshape) { 229 Node *AddINode::Ideal(PhaseGVN *phase, bool can_reshape) {
228 int op1 = in(1)->Opcode(); 230 Node* in1 = in(1);
229 int op2 = in(2)->Opcode(); 231 Node* in2 = in(2);
232 int op1 = in1->Opcode();
233 int op2 = in2->Opcode();
230 // Fold (con1-x)+con2 into (con1+con2)-x 234 // Fold (con1-x)+con2 into (con1+con2)-x
235 if ( op1 == Op_AddI && op2 == Op_SubI ) {
236 // Swap edges to try optimizations below
237 in1 = in2;
238 in2 = in(1);
239 op1 = op2;
240 op2 = in2->Opcode();
241 }
231 if( op1 == Op_SubI ) { 242 if( op1 == Op_SubI ) {
232 const Type *t_sub1 = phase->type( in(1)->in(1) ); 243 const Type *t_sub1 = phase->type( in1->in(1) );
233 const Type *t_2 = phase->type( in(2) ); 244 const Type *t_2 = phase->type( in2 );
234 if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP ) 245 if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP )
235 return new (phase->C, 3) SubINode(phase->makecon( add_ring( t_sub1, t_2 ) ), 246 return new (phase->C, 3) SubINode(phase->makecon( add_ring( t_sub1, t_2 ) ),
236 in(1)->in(2) ); 247 in1->in(2) );
237 // Convert "(a-b)+(c-d)" into "(a+c)-(b+d)" 248 // Convert "(a-b)+(c-d)" into "(a+c)-(b+d)"
238 if( op2 == Op_SubI ) { 249 if( op2 == Op_SubI ) {
239 // Check for dead cycle: d = (a-b)+(c-d) 250 // Check for dead cycle: d = (a-b)+(c-d)
240 assert( in(1)->in(2) != this && in(2)->in(2) != this, 251 assert( in1->in(2) != this && in2->in(2) != this,
241 "dead loop in AddINode::Ideal" ); 252 "dead loop in AddINode::Ideal" );
242 Node *sub = new (phase->C, 3) SubINode(NULL, NULL); 253 Node *sub = new (phase->C, 3) SubINode(NULL, NULL);
243 sub->init_req(1, phase->transform(new (phase->C, 3) AddINode(in(1)->in(1), in(2)->in(1) ) )); 254 sub->init_req(1, phase->transform(new (phase->C, 3) AddINode(in1->in(1), in2->in(1) ) ));
244 sub->init_req(2, phase->transform(new (phase->C, 3) AddINode(in(1)->in(2), in(2)->in(2) ) )); 255 sub->init_req(2, phase->transform(new (phase->C, 3) AddINode(in1->in(2), in2->in(2) ) ));
245 return sub; 256 return sub;
246 } 257 }
258 // Convert "(a-b)+(b+c)" into "(a+c)"
259 if( op2 == Op_AddI && in1->in(2) == in2->in(1) ) {
260 assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal");
261 return new (phase->C, 3) AddINode(in1->in(1), in2->in(2));
262 }
263 // Convert "(a-b)+(c+b)" into "(a+c)"
264 if( op2 == Op_AddI && in1->in(2) == in2->in(2) ) {
265 assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddINode::Ideal");
266 return new (phase->C, 3) AddINode(in1->in(1), in2->in(1));
267 }
268 // Convert "(a-b)+(b-c)" into "(a-c)"
269 if( op2 == Op_SubI && in1->in(2) == in2->in(1) ) {
270 assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal");
271 return new (phase->C, 3) SubINode(in1->in(1), in2->in(2));
272 }
273 // Convert "(a-b)+(c-a)" into "(c-b)"
274 if( op2 == Op_SubI && in1->in(1) == in2->in(2) ) {
275 assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddINode::Ideal");
276 return new (phase->C, 3) SubINode(in2->in(1), in1->in(2));
277 }
247 } 278 }
248 279
249 // Convert "x+(0-y)" into "(x-y)" 280 // Convert "x+(0-y)" into "(x-y)"
250 if( op2 == Op_SubI && phase->type(in(2)->in(1)) == TypeInt::ZERO ) 281 if( op2 == Op_SubI && phase->type(in2->in(1)) == TypeInt::ZERO )
251 return new (phase->C, 3) SubINode(in(1), in(2)->in(2) ); 282 return new (phase->C, 3) SubINode(in1, in2->in(2) );
252 283
253 // Convert "(0-y)+x" into "(x-y)" 284 // Convert "(0-y)+x" into "(x-y)"
254 if( op1 == Op_SubI && phase->type(in(1)->in(1)) == TypeInt::ZERO ) 285 if( op1 == Op_SubI && phase->type(in1->in(1)) == TypeInt::ZERO )
255 return new (phase->C, 3) SubINode( in(2), in(1)->in(2) ); 286 return new (phase->C, 3) SubINode( in2, in1->in(2) );
256 287
257 // Convert (x>>>z)+y into (x+(y<<z))>>>z for small constant z and y. 288 // Convert (x>>>z)+y into (x+(y<<z))>>>z for small constant z and y.
258 // Helps with array allocation math constant folding 289 // Helps with array allocation math constant folding
259 // See 4790063: 290 // See 4790063:
260 // Unrestricted transformation is unsafe for some runtime values of 'x' 291 // Unrestricted transformation is unsafe for some runtime values of 'x'
264 // (x + (y << z)) does not cross zero. 295 // (x + (y << z)) does not cross zero.
265 // Implement support for negative y and (x >= -(y << z)) 296 // Implement support for negative y and (x >= -(y << z))
266 // Have not observed cases where type information exists to support 297 // Have not observed cases where type information exists to support
267 // positive y and (x <= -(y << z)) 298 // positive y and (x <= -(y << z))
268 if( op1 == Op_URShiftI && op2 == Op_ConI && 299 if( op1 == Op_URShiftI && op2 == Op_ConI &&
269 in(1)->in(2)->Opcode() == Op_ConI ) { 300 in1->in(2)->Opcode() == Op_ConI ) {
270 jint z = phase->type( in(1)->in(2) )->is_int()->get_con() & 0x1f; // only least significant 5 bits matter 301 jint z = phase->type( in1->in(2) )->is_int()->get_con() & 0x1f; // only least significant 5 bits matter
271 jint y = phase->type( in(2) )->is_int()->get_con(); 302 jint y = phase->type( in2 )->is_int()->get_con();
272 303
273 if( z < 5 && -5 < y && y < 0 ) { 304 if( z < 5 && -5 < y && y < 0 ) {
274 const Type *t_in11 = phase->type(in(1)->in(1)); 305 const Type *t_in11 = phase->type(in1->in(1));
275 if( t_in11 != Type::TOP && (t_in11->is_int()->_lo >= -(y << z)) ) { 306 if( t_in11 != Type::TOP && (t_in11->is_int()->_lo >= -(y << z)) ) {
276 Node *a = phase->transform( new (phase->C, 3) AddINode( in(1)->in(1), phase->intcon(y<<z) ) ); 307 Node *a = phase->transform( new (phase->C, 3) AddINode( in1->in(1), phase->intcon(y<<z) ) );
277 return new (phase->C, 3) URShiftINode( a, in(1)->in(2) ); 308 return new (phase->C, 3) URShiftINode( a, in1->in(2) );
278 } 309 }
279 } 310 }
280 } 311 }
281 312
282 return AddNode::Ideal(phase, can_reshape); 313 return AddNode::Ideal(phase, can_reshape);
326 357
327 358
328 //============================================================================= 359 //=============================================================================
329 //------------------------------Idealize--------------------------------------- 360 //------------------------------Idealize---------------------------------------
330 Node *AddLNode::Ideal(PhaseGVN *phase, bool can_reshape) { 361 Node *AddLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
331 int op1 = in(1)->Opcode(); 362 Node* in1 = in(1);
332 int op2 = in(2)->Opcode(); 363 Node* in2 = in(2);
364 int op1 = in1->Opcode();
365 int op2 = in2->Opcode();
366 // Fold (con1-x)+con2 into (con1+con2)-x
367 if ( op1 == Op_AddL && op2 == Op_SubL ) {
368 // Swap edges to try optimizations below
369 in1 = in2;
370 in2 = in(1);
371 op1 = op2;
372 op2 = in2->Opcode();
373 }
333 // Fold (con1-x)+con2 into (con1+con2)-x 374 // Fold (con1-x)+con2 into (con1+con2)-x
334 if( op1 == Op_SubL ) { 375 if( op1 == Op_SubL ) {
335 const Type *t_sub1 = phase->type( in(1)->in(1) ); 376 const Type *t_sub1 = phase->type( in1->in(1) );
336 const Type *t_2 = phase->type( in(2) ); 377 const Type *t_2 = phase->type( in2 );
337 if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP ) 378 if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP )
338 return new (phase->C, 3) SubLNode(phase->makecon( add_ring( t_sub1, t_2 ) ), 379 return new (phase->C, 3) SubLNode(phase->makecon( add_ring( t_sub1, t_2 ) ),
339 in(1)->in(2) ); 380 in1->in(2) );
340 // Convert "(a-b)+(c-d)" into "(a+c)-(b+d)" 381 // Convert "(a-b)+(c-d)" into "(a+c)-(b+d)"
341 if( op2 == Op_SubL ) { 382 if( op2 == Op_SubL ) {
342 // Check for dead cycle: d = (a-b)+(c-d) 383 // Check for dead cycle: d = (a-b)+(c-d)
343 assert( in(1)->in(2) != this && in(2)->in(2) != this, 384 assert( in1->in(2) != this && in2->in(2) != this,
344 "dead loop in AddLNode::Ideal" ); 385 "dead loop in AddLNode::Ideal" );
345 Node *sub = new (phase->C, 3) SubLNode(NULL, NULL); 386 Node *sub = new (phase->C, 3) SubLNode(NULL, NULL);
346 sub->init_req(1, phase->transform(new (phase->C, 3) AddLNode(in(1)->in(1), in(2)->in(1) ) )); 387 sub->init_req(1, phase->transform(new (phase->C, 3) AddLNode(in1->in(1), in2->in(1) ) ));
347 sub->init_req(2, phase->transform(new (phase->C, 3) AddLNode(in(1)->in(2), in(2)->in(2) ) )); 388 sub->init_req(2, phase->transform(new (phase->C, 3) AddLNode(in1->in(2), in2->in(2) ) ));
348 return sub; 389 return sub;
349 } 390 }
391 // Convert "(a-b)+(b+c)" into "(a+c)"
392 if( op2 == Op_AddL && in1->in(2) == in2->in(1) ) {
393 assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal");
394 return new (phase->C, 3) AddLNode(in1->in(1), in2->in(2));
395 }
396 // Convert "(a-b)+(c+b)" into "(a+c)"
397 if( op2 == Op_AddL && in1->in(2) == in2->in(2) ) {
398 assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal");
399 return new (phase->C, 3) AddLNode(in1->in(1), in2->in(1));
400 }
401 // Convert "(a-b)+(b-c)" into "(a-c)"
402 if( op2 == Op_SubL && in1->in(2) == in2->in(1) ) {
403 assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal");
404 return new (phase->C, 3) SubLNode(in1->in(1), in2->in(2));
405 }
406 // Convert "(a-b)+(c-a)" into "(c-b)"
407 if( op2 == Op_SubL && in1->in(1) == in1->in(2) ) {
408 assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal");
409 return new (phase->C, 3) SubLNode(in2->in(1), in1->in(2));
410 }
350 } 411 }
351 412
352 // Convert "x+(0-y)" into "(x-y)" 413 // Convert "x+(0-y)" into "(x-y)"
353 if( op2 == Op_SubL && phase->type(in(2)->in(1)) == TypeLong::ZERO ) 414 if( op2 == Op_SubL && phase->type(in2->in(1)) == TypeLong::ZERO )
354 return new (phase->C, 3) SubLNode(in(1), in(2)->in(2) ); 415 return new (phase->C, 3) SubLNode( in1, in2->in(2) );
416
417 // Convert "(0-y)+x" into "(x-y)"
418 if( op1 == Op_SubL && phase->type(in1->in(1)) == TypeInt::ZERO )
419 return new (phase->C, 3) SubLNode( in2, in1->in(2) );
355 420
356 // Convert "X+X+X+X+X...+X+Y" into "k*X+Y" or really convert "X+(X+Y)" 421 // Convert "X+X+X+X+X...+X+Y" into "k*X+Y" or really convert "X+(X+Y)"
357 // into "(X<<1)+Y" and let shift-folding happen. 422 // into "(X<<1)+Y" and let shift-folding happen.
358 if( op2 == Op_AddL && 423 if( op2 == Op_AddL &&
359 in(2)->in(1) == in(1) && 424 in2->in(1) == in1 &&
360 op1 != Op_ConL && 425 op1 != Op_ConL &&
361 0 ) { 426 0 ) {
362 Node *shift = phase->transform(new (phase->C, 3) LShiftLNode(in(1),phase->intcon(1))); 427 Node *shift = phase->transform(new (phase->C, 3) LShiftLNode(in1,phase->intcon(1)));
363 return new (phase->C, 3) AddLNode(shift,in(2)->in(2)); 428 return new (phase->C, 3) AddLNode(shift,in2->in(2));
364 } 429 }
365 430
366 return AddNode::Ideal(phase, can_reshape); 431 return AddNode::Ideal(phase, can_reshape);
367 } 432 }
368 433