< prev index next >

src/share/vm/opto/movenode.cpp

Print this page




  88     if( in(Condition)->is_Bool() ) {
  89       BoolNode* b  = in(Condition)->as_Bool();
  90       BoolNode* b2 = b->negate(phase);
  91       return make(in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type);
  92     }
  93   }
  94   return NULL;
  95 }
  96 
  97 //------------------------------is_cmove_id------------------------------------
  98 // Helper function to check for CMOVE identity.  Shared with PhiNode::Identity
  99 Node *CMoveNode::is_cmove_id( PhaseTransform *phase, Node *cmp, Node *t, Node *f, BoolNode *b ) {
 100   // Check for Cmp'ing and CMove'ing same values
 101   if( (phase->eqv(cmp->in(1),f) &&
 102        phase->eqv(cmp->in(2),t)) ||
 103      // Swapped Cmp is OK
 104      (phase->eqv(cmp->in(2),f) &&
 105       phase->eqv(cmp->in(1),t)) ) {
 106        // Give up this identity check for floating points because it may choose incorrect
 107        // value around 0.0 and -0.0
 108        if ( cmp->Opcode()==Op_CmpF || cmp->Opcode()==Op_CmpD )
 109        return NULL;
 110        // Check for "(t==f)?t:f;" and replace with "f"
 111        if( b->_test._test == BoolTest::eq )
 112        return f;
 113        // Allow the inverted case as well
 114        // Check for "(t!=f)?t:f;" and replace with "t"
 115        if( b->_test._test == BoolTest::ne )
 116        return t;
 117      }
 118   return NULL;
 119 }
 120 
 121 //------------------------------Identity---------------------------------------
 122 // Conditional-move is an identity if both inputs are the same, or the test
 123 // true or false.
 124 Node* CMoveNode::Identity(PhaseGVN* phase) {
 125   if( phase->eqv(in(IfFalse),in(IfTrue)) ) // C-moving identical inputs?
 126   return in(IfFalse);         // Then it doesn't matter
 127   if( phase->type(in(Condition)) == TypeInt::ZERO )
 128   return in(IfFalse);         // Always pick left(false) input


 247   Node *x = CMoveNode::Ideal(phase, can_reshape);
 248   if( x ) return x;
 249 
 250   int  cmp_zero_idx = 0;        // Index of compare input where to look for zero
 251   int  phi_x_idx = 0;           // Index of phi input where to find naked x
 252 
 253   // Find the Bool
 254   if( !in(1)->is_Bool() ) return NULL;
 255   BoolNode *bol = in(1)->as_Bool();
 256   // Check bool sense
 257   switch( bol->_test._test ) {
 258     case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue;  break;
 259     case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break;
 260     case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue;  break;
 261     case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break;
 262     default:           return NULL;                           break;
 263   }
 264 
 265   // Find zero input of CmpF; the other input is being abs'd
 266   Node *cmpf = bol->in(1);
 267   if( cmpf->Opcode() != Op_CmpF ) return NULL;
 268   Node *X = NULL;
 269   bool flip = false;
 270   if( phase->type(cmpf->in(cmp_zero_idx)) == TypeF::ZERO ) {
 271     X = cmpf->in(3 - cmp_zero_idx);
 272   } else if (phase->type(cmpf->in(3 - cmp_zero_idx)) == TypeF::ZERO) {
 273     // The test is inverted, we should invert the result...
 274     X = cmpf->in(cmp_zero_idx);
 275     flip = true;
 276   } else {
 277     return NULL;
 278   }
 279 
 280   // If X is found on the appropriate phi input, find the subtract on the other
 281   if( X != in(phi_x_idx) ) return NULL;
 282   int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue;
 283   Node *sub = in(phi_sub_idx);
 284 
 285   // Allow only SubF(0,X) and fail out for all others; NegF is not OK
 286   if( sub->Opcode() != Op_SubF ||
 287      sub->in(2) != X ||
 288      phase->type(sub->in(1)) != TypeF::ZERO ) return NULL;
 289 
 290   Node *abs = new AbsFNode( X );
 291   if( flip )
 292   abs = new SubFNode(sub->in(1), phase->transform(abs));
 293 
 294   return abs;
 295 }
 296 
 297 //=============================================================================
 298 //------------------------------Ideal------------------------------------------
 299 // Return a node which is more "ideal" than the current node.
 300 // Check for absolute value
 301 Node *CMoveDNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 302   // Try generic ideal's first
 303   Node *x = CMoveNode::Ideal(phase, can_reshape);
 304   if( x ) return x;
 305 
 306   int  cmp_zero_idx = 0;        // Index of compare input where to look for zero
 307   int  phi_x_idx = 0;           // Index of phi input where to find naked x
 308 
 309   // Find the Bool
 310   if( !in(1)->is_Bool() ) return NULL;
 311   BoolNode *bol = in(1)->as_Bool();
 312   // Check bool sense
 313   switch( bol->_test._test ) {
 314     case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue;  break;
 315     case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break;
 316     case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue;  break;
 317     case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break;
 318     default:           return NULL;                           break;
 319   }
 320 
 321   // Find zero input of CmpD; the other input is being abs'd
 322   Node *cmpd = bol->in(1);
 323   if( cmpd->Opcode() != Op_CmpD ) return NULL;
 324   Node *X = NULL;
 325   bool flip = false;
 326   if( phase->type(cmpd->in(cmp_zero_idx)) == TypeD::ZERO ) {
 327     X = cmpd->in(3 - cmp_zero_idx);
 328   } else if (phase->type(cmpd->in(3 - cmp_zero_idx)) == TypeD::ZERO) {
 329     // The test is inverted, we should invert the result...
 330     X = cmpd->in(cmp_zero_idx);
 331     flip = true;
 332   } else {
 333     return NULL;
 334   }
 335 
 336   // If X is found on the appropriate phi input, find the subtract on the other
 337   if( X != in(phi_x_idx) ) return NULL;
 338   int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue;
 339   Node *sub = in(phi_sub_idx);
 340 
 341   // Allow only SubD(0,X) and fail out for all others; NegD is not OK
 342   if( sub->Opcode() != Op_SubD ||
 343      sub->in(2) != X ||
 344      phase->type(sub->in(1)) != TypeD::ZERO ) return NULL;
 345 
 346   Node *abs = new AbsDNode( X );
 347   if( flip )
 348   abs = new SubDNode(sub->in(1), phase->transform(abs));
 349 
 350   return abs;
 351 }
 352 
 353 //------------------------------Value------------------------------------------
 354 const Type* MoveL2DNode::Value(PhaseGVN* phase) const {
 355   const Type *t = phase->type( in(1) );
 356   if( t == Type::TOP ) return Type::TOP;
 357   const TypeLong *tl = t->is_long();
 358   if( !tl->is_con() ) return bottom_type();
 359   JavaValue v;
 360   v.set_jlong(tl->get_con());
 361   return TypeD::make( v.get_jdouble() );
 362 }




  88     if( in(Condition)->is_Bool() ) {
  89       BoolNode* b  = in(Condition)->as_Bool();
  90       BoolNode* b2 = b->negate(phase);
  91       return make(in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type);
  92     }
  93   }
  94   return NULL;
  95 }
  96 
  97 //------------------------------is_cmove_id------------------------------------
  98 // Helper function to check for CMOVE identity.  Shared with PhiNode::Identity
  99 Node *CMoveNode::is_cmove_id( PhaseTransform *phase, Node *cmp, Node *t, Node *f, BoolNode *b ) {
 100   // Check for Cmp'ing and CMove'ing same values
 101   if( (phase->eqv(cmp->in(1),f) &&
 102        phase->eqv(cmp->in(2),t)) ||
 103      // Swapped Cmp is OK
 104      (phase->eqv(cmp->in(2),f) &&
 105       phase->eqv(cmp->in(1),t)) ) {
 106        // Give up this identity check for floating points because it may choose incorrect
 107        // value around 0.0 and -0.0
 108        if ( cmp->Opcode()==Opcodes::Op_CmpF || cmp->Opcode()==Opcodes::Op_CmpD )
 109        return NULL;
 110        // Check for "(t==f)?t:f;" and replace with "f"
 111        if( b->_test._test == BoolTest::eq )
 112        return f;
 113        // Allow the inverted case as well
 114        // Check for "(t!=f)?t:f;" and replace with "t"
 115        if( b->_test._test == BoolTest::ne )
 116        return t;
 117      }
 118   return NULL;
 119 }
 120 
 121 //------------------------------Identity---------------------------------------
 122 // Conditional-move is an identity if both inputs are the same, or the test
 123 // true or false.
 124 Node* CMoveNode::Identity(PhaseGVN* phase) {
 125   if( phase->eqv(in(IfFalse),in(IfTrue)) ) // C-moving identical inputs?
 126   return in(IfFalse);         // Then it doesn't matter
 127   if( phase->type(in(Condition)) == TypeInt::ZERO )
 128   return in(IfFalse);         // Always pick left(false) input


 247   Node *x = CMoveNode::Ideal(phase, can_reshape);
 248   if( x ) return x;
 249 
 250   int  cmp_zero_idx = 0;        // Index of compare input where to look for zero
 251   int  phi_x_idx = 0;           // Index of phi input where to find naked x
 252 
 253   // Find the Bool
 254   if( !in(1)->is_Bool() ) return NULL;
 255   BoolNode *bol = in(1)->as_Bool();
 256   // Check bool sense
 257   switch( bol->_test._test ) {
 258     case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue;  break;
 259     case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break;
 260     case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue;  break;
 261     case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break;
 262     default:           return NULL;                           break;
 263   }
 264 
 265   // Find zero input of CmpF; the other input is being abs'd
 266   Node *cmpf = bol->in(1);
 267   if( cmpf->Opcode() != Opcodes::Op_CmpF ) return NULL;
 268   Node *X = NULL;
 269   bool flip = false;
 270   if( phase->type(cmpf->in(cmp_zero_idx)) == TypeF::ZERO ) {
 271     X = cmpf->in(3 - cmp_zero_idx);
 272   } else if (phase->type(cmpf->in(3 - cmp_zero_idx)) == TypeF::ZERO) {
 273     // The test is inverted, we should invert the result...
 274     X = cmpf->in(cmp_zero_idx);
 275     flip = true;
 276   } else {
 277     return NULL;
 278   }
 279 
 280   // If X is found on the appropriate phi input, find the subtract on the other
 281   if( X != in(phi_x_idx) ) return NULL;
 282   int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue;
 283   Node *sub = in(phi_sub_idx);
 284 
 285   // Allow only SubF(0,X) and fail out for all others; NegF is not OK
 286   if( sub->Opcode() != Opcodes::Op_SubF ||
 287      sub->in(2) != X ||
 288      phase->type(sub->in(1)) != TypeF::ZERO ) return NULL;
 289 
 290   Node *abs = new AbsFNode( X );
 291   if( flip )
 292   abs = new SubFNode(sub->in(1), phase->transform(abs));
 293 
 294   return abs;
 295 }
 296 
 297 //=============================================================================
 298 //------------------------------Ideal------------------------------------------
 299 // Return a node which is more "ideal" than the current node.
 300 // Check for absolute value
 301 Node *CMoveDNode::Ideal(PhaseGVN *phase, bool can_reshape) {
 302   // Try generic ideal's first
 303   Node *x = CMoveNode::Ideal(phase, can_reshape);
 304   if( x ) return x;
 305 
 306   int  cmp_zero_idx = 0;        // Index of compare input where to look for zero
 307   int  phi_x_idx = 0;           // Index of phi input where to find naked x
 308 
 309   // Find the Bool
 310   if( !in(1)->is_Bool() ) return NULL;
 311   BoolNode *bol = in(1)->as_Bool();
 312   // Check bool sense
 313   switch( bol->_test._test ) {
 314     case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue;  break;
 315     case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break;
 316     case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue;  break;
 317     case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break;
 318     default:           return NULL;                           break;
 319   }
 320 
 321   // Find zero input of CmpD; the other input is being abs'd
 322   Node *cmpd = bol->in(1);
 323   if( cmpd->Opcode() != Opcodes::Op_CmpD ) return NULL;
 324   Node *X = NULL;
 325   bool flip = false;
 326   if( phase->type(cmpd->in(cmp_zero_idx)) == TypeD::ZERO ) {
 327     X = cmpd->in(3 - cmp_zero_idx);
 328   } else if (phase->type(cmpd->in(3 - cmp_zero_idx)) == TypeD::ZERO) {
 329     // The test is inverted, we should invert the result...
 330     X = cmpd->in(cmp_zero_idx);
 331     flip = true;
 332   } else {
 333     return NULL;
 334   }
 335 
 336   // If X is found on the appropriate phi input, find the subtract on the other
 337   if( X != in(phi_x_idx) ) return NULL;
 338   int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue;
 339   Node *sub = in(phi_sub_idx);
 340 
 341   // Allow only SubD(0,X) and fail out for all others; NegD is not OK
 342   if( sub->Opcode() != Opcodes::Op_SubD ||
 343      sub->in(2) != X ||
 344      phase->type(sub->in(1)) != TypeD::ZERO ) return NULL;
 345 
 346   Node *abs = new AbsDNode( X );
 347   if( flip )
 348   abs = new SubDNode(sub->in(1), phase->transform(abs));
 349 
 350   return abs;
 351 }
 352 
 353 //------------------------------Value------------------------------------------
 354 const Type* MoveL2DNode::Value(PhaseGVN* phase) const {
 355   const Type *t = phase->type( in(1) );
 356   if( t == Type::TOP ) return Type::TOP;
 357   const TypeLong *tl = t->is_long();
 358   if( !tl->is_con() ) return bottom_type();
 359   JavaValue v;
 360   v.set_jlong(tl->get_con());
 361   return TypeD::make( v.get_jdouble() );
 362 }


< prev index next >