1061
1062 //------------------------------dump_spec-------------------------------------
1063 // Print special per-node info
1064 #ifndef PRODUCT
1065 void BoolTest::dump_on(outputStream *st) const {
1066 const char *msg[] = {"eq","gt","??","lt","ne","le","??","ge"};
1067 st->print(msg[_test]);
1068 }
1069 #endif
1070
1071 //=============================================================================
1072 uint BoolNode::hash() const { return (Node::hash() << 3)|(_test._test+1); }
1073 uint BoolNode::size_of() const { return sizeof(BoolNode); }
1074
1075 //------------------------------operator==-------------------------------------
1076 uint BoolNode::cmp( const Node &n ) const {
1077 const BoolNode *b = (const BoolNode *)&n; // Cast up
1078 return (_test._test == b->_test._test);
1079 }
1080
1081 //------------------------------clone_cmp--------------------------------------
1082 // Clone a compare/bool tree
1083 static Node *clone_cmp( Node *cmp, Node *cmp1, Node *cmp2, PhaseGVN *gvn, BoolTest::mask test ) {
1084 Node *ncmp = cmp->clone();
1085 ncmp->set_req(1,cmp1);
1086 ncmp->set_req(2,cmp2);
1087 ncmp = gvn->transform( ncmp );
1088 return new (gvn->C) BoolNode( ncmp, test );
1089 }
1090
1091 //-------------------------------make_predicate--------------------------------
1092 Node* BoolNode::make_predicate(Node* test_value, PhaseGVN* phase) {
1093 if (test_value->is_Con()) return test_value;
1094 if (test_value->is_Bool()) return test_value;
1095 Compile* C = phase->C;
1096 if (test_value->is_CMove() &&
1097 test_value->in(CMoveNode::Condition)->is_Bool()) {
1098 BoolNode* bol = test_value->in(CMoveNode::Condition)->as_Bool();
1099 const Type* ftype = phase->type(test_value->in(CMoveNode::IfFalse));
1100 const Type* ttype = phase->type(test_value->in(CMoveNode::IfTrue));
1101 if (ftype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ttype)) {
1102 return bol;
1103 } else if (ttype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ftype)) {
1104 return phase->transform( bol->negate(phase) );
1105 }
1106 // Else fall through. The CMove gets in the way of the test.
1107 // It should be the case that make_predicate(bol->as_int_value()) == bol.
1108 }
1109 Node* cmp = new (C) CmpINode(test_value, phase->intcon(0));
1110 cmp = phase->transform(cmp);
1198 // due to possible integer overflow.
1199 if ((_test._test == BoolTest::eq || _test._test == BoolTest::ne) &&
1200 (cop == Op_CmpI) &&
1201 (cmp1->Opcode() == Op_SubI) &&
1202 ( cmp2_type == TypeInt::ZERO ) ) {
1203 Node *ncmp = phase->transform( new (phase->C) CmpINode(cmp1->in(1),cmp1->in(2)));
1204 return new (phase->C) BoolNode( ncmp, _test._test );
1205 }
1206
1207 // Change (-A vs 0) into (A vs 0) by commuting the test. Disallow in the
1208 // most general case because negating 0x80000000 does nothing. Needed for
1209 // the CmpF3/SubI/CmpI idiom.
1210 if( cop == Op_CmpI &&
1211 cmp1->Opcode() == Op_SubI &&
1212 cmp2_type == TypeInt::ZERO &&
1213 phase->type( cmp1->in(1) ) == TypeInt::ZERO &&
1214 phase->type( cmp1->in(2) )->higher_equal(TypeInt::SYMINT) ) {
1215 Node *ncmp = phase->transform( new (phase->C) CmpINode(cmp1->in(2),cmp2));
1216 return new (phase->C) BoolNode( ncmp, _test.commute() );
1217 }
1218
1219 // The transformation below is not valid for either signed or unsigned
1220 // comparisons due to wraparound concerns at MAX_VALUE and MIN_VALUE.
1221 // This transformation can be resurrected when we are able to
1222 // make inferences about the range of values being subtracted from
1223 // (or added to) relative to the wraparound point.
1224 //
1225 // // Remove +/-1's if possible.
1226 // // "X <= Y-1" becomes "X < Y"
1227 // // "X+1 <= Y" becomes "X < Y"
1228 // // "X < Y+1" becomes "X <= Y"
1229 // // "X-1 < Y" becomes "X <= Y"
1230 // // Do not this to compares off of the counted-loop-end. These guys are
1231 // // checking the trip counter and they want to use the post-incremented
1232 // // counter. If they use the PRE-incremented counter, then the counter has
1233 // // to be incremented in a private block on a loop backedge.
1234 // if( du && du->cnt(this) && du->out(this)[0]->Opcode() == Op_CountedLoopEnd )
1235 // return NULL;
1236 // #ifndef PRODUCT
1237 // // Do not do this in a wash GVN pass during verification.
1238 // // Gets triggered by too many simple optimizations to be bothered with
1239 // // re-trying it again and again.
1240 // if( !phase->allow_progress() ) return NULL;
1241 // #endif
1242 // // Not valid for unsigned compare because of corner cases in involving zero.
1243 // // For example, replacing "X-1 <u Y" with "X <=u Y" fails to throw an
1244 // // exception in case X is 0 (because 0-1 turns into 4billion unsigned but
1245 // // "0 <=u Y" is always true).
1246 // if( cmp->Opcode() == Op_CmpU ) return NULL;
1247 // int cmp2_op = cmp2->Opcode();
1248 // if( _test._test == BoolTest::le ) {
1249 // if( cmp1_op == Op_AddI &&
1250 // phase->type( cmp1->in(2) ) == TypeInt::ONE )
1251 // return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::lt );
1252 // else if( cmp2_op == Op_AddI &&
1253 // phase->type( cmp2->in(2) ) == TypeInt::MINUS_1 )
1254 // return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::lt );
1255 // } else if( _test._test == BoolTest::lt ) {
1256 // if( cmp1_op == Op_AddI &&
1257 // phase->type( cmp1->in(2) ) == TypeInt::MINUS_1 )
1258 // return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::le );
1259 // else if( cmp2_op == Op_AddI &&
1260 // phase->type( cmp2->in(2) ) == TypeInt::ONE )
1261 // return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::le );
1262 // }
1263
1264 return NULL;
1265 }
1266
1267 //------------------------------Value------------------------------------------
1268 // Simplify a Bool (convert condition codes to boolean (1 or 0)) node,
1269 // based on local information. If the input is constant, do it.
1270 const Type *BoolNode::Value( PhaseTransform *phase ) const {
1271 return _test.cc2logical( phase->type( in(1) ) );
1272 }
1273
1274 //------------------------------dump_spec--------------------------------------
1275 // Dump special per-node info
1276 #ifndef PRODUCT
1277 void BoolNode::dump_spec(outputStream *st) const {
1278 st->print("[");
1279 _test.dump_on(st);
1280 st->print("]");
1281 }
1282 #endif
|
1061
1062 //------------------------------dump_spec-------------------------------------
1063 // Print special per-node info
1064 #ifndef PRODUCT
1065 void BoolTest::dump_on(outputStream *st) const {
1066 const char *msg[] = {"eq","gt","??","lt","ne","le","??","ge"};
1067 st->print(msg[_test]);
1068 }
1069 #endif
1070
1071 //=============================================================================
1072 uint BoolNode::hash() const { return (Node::hash() << 3)|(_test._test+1); }
1073 uint BoolNode::size_of() const { return sizeof(BoolNode); }
1074
1075 //------------------------------operator==-------------------------------------
1076 uint BoolNode::cmp( const Node &n ) const {
1077 const BoolNode *b = (const BoolNode *)&n; // Cast up
1078 return (_test._test == b->_test._test);
1079 }
1080
1081 //-------------------------------make_predicate--------------------------------
1082 Node* BoolNode::make_predicate(Node* test_value, PhaseGVN* phase) {
1083 if (test_value->is_Con()) return test_value;
1084 if (test_value->is_Bool()) return test_value;
1085 Compile* C = phase->C;
1086 if (test_value->is_CMove() &&
1087 test_value->in(CMoveNode::Condition)->is_Bool()) {
1088 BoolNode* bol = test_value->in(CMoveNode::Condition)->as_Bool();
1089 const Type* ftype = phase->type(test_value->in(CMoveNode::IfFalse));
1090 const Type* ttype = phase->type(test_value->in(CMoveNode::IfTrue));
1091 if (ftype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ttype)) {
1092 return bol;
1093 } else if (ttype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ftype)) {
1094 return phase->transform( bol->negate(phase) );
1095 }
1096 // Else fall through. The CMove gets in the way of the test.
1097 // It should be the case that make_predicate(bol->as_int_value()) == bol.
1098 }
1099 Node* cmp = new (C) CmpINode(test_value, phase->intcon(0));
1100 cmp = phase->transform(cmp);
1188 // due to possible integer overflow.
1189 if ((_test._test == BoolTest::eq || _test._test == BoolTest::ne) &&
1190 (cop == Op_CmpI) &&
1191 (cmp1->Opcode() == Op_SubI) &&
1192 ( cmp2_type == TypeInt::ZERO ) ) {
1193 Node *ncmp = phase->transform( new (phase->C) CmpINode(cmp1->in(1),cmp1->in(2)));
1194 return new (phase->C) BoolNode( ncmp, _test._test );
1195 }
1196
1197 // Change (-A vs 0) into (A vs 0) by commuting the test. Disallow in the
1198 // most general case because negating 0x80000000 does nothing. Needed for
1199 // the CmpF3/SubI/CmpI idiom.
1200 if( cop == Op_CmpI &&
1201 cmp1->Opcode() == Op_SubI &&
1202 cmp2_type == TypeInt::ZERO &&
1203 phase->type( cmp1->in(1) ) == TypeInt::ZERO &&
1204 phase->type( cmp1->in(2) )->higher_equal(TypeInt::SYMINT) ) {
1205 Node *ncmp = phase->transform( new (phase->C) CmpINode(cmp1->in(2),cmp2));
1206 return new (phase->C) BoolNode( ncmp, _test.commute() );
1207 }
1208
1209 return NULL;
1210 }
1211
1212 //------------------------------Value------------------------------------------
1213 // Simplify a Bool (convert condition codes to boolean (1 or 0)) node,
1214 // based on local information. If the input is constant, do it.
1215 const Type *BoolNode::Value( PhaseTransform *phase ) const {
1216 return _test.cc2logical( phase->type( in(1) ) );
1217 }
1218
1219 //------------------------------dump_spec--------------------------------------
1220 // Dump special per-node info
1221 #ifndef PRODUCT
1222 void BoolNode::dump_spec(outputStream *st) const {
1223 st->print("[");
1224 _test.dump_on(st);
1225 st->print("]");
1226 }
1227 #endif
|