225 226 // Convert "(X+A) - (B+X)" into "A - B" 227 if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(2) ) 228 return new (phase->C) SubINode( in1->in(2), in2->in(1) ); 229 230 // Convert "A-(B-C)" into (A+C)-B", since add is commutative and generally 231 // nicer to optimize than subtract. 232 if( op2 == Op_SubI && in2->outcnt() == 1) { 233 Node *add1 = phase->transform( new (phase->C) AddINode( in1, in2->in(2) ) ); 234 return new (phase->C) SubINode( add1, in2->in(1) ); 235 } 236 237 return NULL; 238 } 239 240 //------------------------------sub-------------------------------------------- 241 // A subtract node differences it's two inputs. 242 const Type *SubINode::sub( const Type *t1, const Type *t2 ) const { 243 const TypeInt *r0 = t1->is_int(); // Handy access 244 const TypeInt *r1 = t2->is_int(); 245 int32 lo = r0->_lo - r1->_hi; 246 int32 hi = r0->_hi - r1->_lo; 247 248 // We next check for 32-bit overflow. 249 // If that happens, we just assume all integers are possible. 250 if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR 251 ((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND 252 (((r0->_hi ^ r1->_lo) >= 0) || // hi ends have same signs OR 253 ((r0->_hi ^ hi) >= 0)) ) // hi results have same signs 254 return TypeInt::make(lo,hi,MAX2(r0->_widen,r1->_widen)); 255 else // Overflow; assume all integers 256 return TypeInt::INT; 257 } 258 259 //============================================================================= 260 //------------------------------Ideal------------------------------------------ 261 Node *SubLNode::Ideal(PhaseGVN *phase, bool can_reshape) { 262 Node *in1 = in(1); 263 Node *in2 = in(2); 264 uint op1 = in1->Opcode(); 265 uint op2 = in2->Opcode(); 266 | 225 226 // Convert "(X+A) - (B+X)" into "A - B" 227 if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(2) ) 228 return new (phase->C) SubINode( in1->in(2), in2->in(1) ); 229 230 // Convert "A-(B-C)" into (A+C)-B", since add is commutative and generally 231 // nicer to optimize than subtract. 232 if( op2 == Op_SubI && in2->outcnt() == 1) { 233 Node *add1 = phase->transform( new (phase->C) AddINode( in1, in2->in(2) ) ); 234 return new (phase->C) SubINode( add1, in2->in(1) ); 235 } 236 237 return NULL; 238 } 239 240 //------------------------------sub-------------------------------------------- 241 // A subtract node differences it's two inputs. 242 const Type *SubINode::sub( const Type *t1, const Type *t2 ) const { 243 const TypeInt *r0 = t1->is_int(); // Handy access 244 const TypeInt *r1 = t2->is_int(); 245 int32_t lo = r0->_lo - r1->_hi; 246 int32_t hi = r0->_hi - r1->_lo; 247 248 // We next check for 32-bit overflow. 249 // If that happens, we just assume all integers are possible. 250 if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR 251 ((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND 252 (((r0->_hi ^ r1->_lo) >= 0) || // hi ends have same signs OR 253 ((r0->_hi ^ hi) >= 0)) ) // hi results have same signs 254 return TypeInt::make(lo,hi,MAX2(r0->_widen,r1->_widen)); 255 else // Overflow; assume all integers 256 return TypeInt::INT; 257 } 258 259 //============================================================================= 260 //------------------------------Ideal------------------------------------------ 261 Node *SubLNode::Ideal(PhaseGVN *phase, bool can_reshape) { 262 Node *in1 = in(1); 263 Node *in2 = in(2); 264 uint op1 = in1->Opcode(); 265 uint op2 = in2->Opcode(); 266 |