235
236 // Convert "(X+A) - (B+X)" into "A - B"
237 if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(2) )
238 return new SubINode( in1->in(2), in2->in(1) );
239
240 // Convert "A-(B-C)" into (A+C)-B", since add is commutative and generally
241 // nicer to optimize than subtract.
242 if( op2 == Op_SubI && in2->outcnt() == 1) {
243 Node *add1 = phase->transform( new AddINode( in1, in2->in(2) ) );
244 return new SubINode( add1, in2->in(1) );
245 }
246
247 return NULL;
248 }
249
250 //------------------------------sub--------------------------------------------
251 // A subtract node differences it's two inputs.
252 const Type *SubINode::sub( const Type *t1, const Type *t2 ) const {
253 const TypeInt *r0 = t1->is_int(); // Handy access
254 const TypeInt *r1 = t2->is_int();
255 int32_t lo = r0->_lo - r1->_hi;
256 int32_t hi = r0->_hi - r1->_lo;
257
258 // We next check for 32-bit overflow.
259 // If that happens, we just assume all integers are possible.
260 if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR
261 ((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND
262 (((r0->_hi ^ r1->_lo) >= 0) || // hi ends have same signs OR
263 ((r0->_hi ^ hi) >= 0)) ) // hi results have same signs
264 return TypeInt::make(lo,hi,MAX2(r0->_widen,r1->_widen));
265 else // Overflow; assume all integers
266 return TypeInt::INT;
267 }
268
269 //=============================================================================
270 //------------------------------Ideal------------------------------------------
271 Node *SubLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
272 Node *in1 = in(1);
273 Node *in2 = in(2);
274 uint op1 = in1->Opcode();
275 uint op2 = in2->Opcode();
276
344 return new SubLNode( in1->in(2), in2->in(2) );
345
346 // Convert "(A+X) - (B+X)" into "A - B"
347 if( op1 == Op_AddL && op2 == Op_AddL && in1->in(2) == in2->in(2) )
348 return new SubLNode( in1->in(1), in2->in(1) );
349
350 // Convert "A-(B-C)" into (A+C)-B"
351 if( op2 == Op_SubL && in2->outcnt() == 1) {
352 Node *add1 = phase->transform( new AddLNode( in1, in2->in(2) ) );
353 return new SubLNode( add1, in2->in(1) );
354 }
355
356 return NULL;
357 }
358
359 //------------------------------sub--------------------------------------------
360 // A subtract node differences it's two inputs.
361 const Type *SubLNode::sub( const Type *t1, const Type *t2 ) const {
362 const TypeLong *r0 = t1->is_long(); // Handy access
363 const TypeLong *r1 = t2->is_long();
364 jlong lo = r0->_lo - r1->_hi;
365 jlong hi = r0->_hi - r1->_lo;
366
367 // We next check for 32-bit overflow.
368 // If that happens, we just assume all integers are possible.
369 if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR
370 ((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND
371 (((r0->_hi ^ r1->_lo) >= 0) || // hi ends have same signs OR
372 ((r0->_hi ^ hi) >= 0)) ) // hi results have same signs
373 return TypeLong::make(lo,hi,MAX2(r0->_widen,r1->_widen));
374 else // Overflow; assume all integers
375 return TypeLong::LONG;
376 }
377
378 //=============================================================================
379 //------------------------------Value------------------------------------------
380 // A subtract node differences its two inputs.
381 const Type *SubFPNode::Value( PhaseTransform *phase ) const {
382 const Node* in1 = in(1);
383 const Node* in2 = in(2);
384 // Either input is TOP ==> the result is TOP
385 const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
|
235
236 // Convert "(X+A) - (B+X)" into "A - B"
237 if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(2) )
238 return new SubINode( in1->in(2), in2->in(1) );
239
240 // Convert "A-(B-C)" into (A+C)-B", since add is commutative and generally
241 // nicer to optimize than subtract.
242 if( op2 == Op_SubI && in2->outcnt() == 1) {
243 Node *add1 = phase->transform( new AddINode( in1, in2->in(2) ) );
244 return new SubINode( add1, in2->in(1) );
245 }
246
247 return NULL;
248 }
249
250 //------------------------------sub--------------------------------------------
251 // A subtract node differences it's two inputs.
252 const Type *SubINode::sub( const Type *t1, const Type *t2 ) const {
253 const TypeInt *r0 = t1->is_int(); // Handy access
254 const TypeInt *r1 = t2->is_int();
255 int32_t lo = java_subtract(r0->_lo, r1->_hi);
256 int32_t hi = java_subtract(r0->_hi, r1->_lo);
257
258 // We next check for 32-bit overflow.
259 // If that happens, we just assume all integers are possible.
260 if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR
261 ((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND
262 (((r0->_hi ^ r1->_lo) >= 0) || // hi ends have same signs OR
263 ((r0->_hi ^ hi) >= 0)) ) // hi results have same signs
264 return TypeInt::make(lo,hi,MAX2(r0->_widen,r1->_widen));
265 else // Overflow; assume all integers
266 return TypeInt::INT;
267 }
268
269 //=============================================================================
270 //------------------------------Ideal------------------------------------------
271 Node *SubLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
272 Node *in1 = in(1);
273 Node *in2 = in(2);
274 uint op1 = in1->Opcode();
275 uint op2 = in2->Opcode();
276
344 return new SubLNode( in1->in(2), in2->in(2) );
345
346 // Convert "(A+X) - (B+X)" into "A - B"
347 if( op1 == Op_AddL && op2 == Op_AddL && in1->in(2) == in2->in(2) )
348 return new SubLNode( in1->in(1), in2->in(1) );
349
350 // Convert "A-(B-C)" into (A+C)-B"
351 if( op2 == Op_SubL && in2->outcnt() == 1) {
352 Node *add1 = phase->transform( new AddLNode( in1, in2->in(2) ) );
353 return new SubLNode( add1, in2->in(1) );
354 }
355
356 return NULL;
357 }
358
359 //------------------------------sub--------------------------------------------
360 // A subtract node differences it's two inputs.
361 const Type *SubLNode::sub( const Type *t1, const Type *t2 ) const {
362 const TypeLong *r0 = t1->is_long(); // Handy access
363 const TypeLong *r1 = t2->is_long();
364 jlong lo = java_subtract(r0->_lo, r1->_hi);
365 jlong hi = java_subtract(r0->_hi, r1->_lo);
366
367 // We next check for 32-bit overflow.
368 // If that happens, we just assume all integers are possible.
369 if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR
370 ((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND
371 (((r0->_hi ^ r1->_lo) >= 0) || // hi ends have same signs OR
372 ((r0->_hi ^ hi) >= 0)) ) // hi results have same signs
373 return TypeLong::make(lo,hi,MAX2(r0->_widen,r1->_widen));
374 else // Overflow; assume all integers
375 return TypeLong::LONG;
376 }
377
378 //=============================================================================
379 //------------------------------Value------------------------------------------
380 // A subtract node differences its two inputs.
381 const Type *SubFPNode::Value( PhaseTransform *phase ) const {
382 const Node* in1 = in(1);
383 const Node* in2 = in(2);
384 // Either input is TOP ==> the result is TOP
385 const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
|