38 Node* dom = dominating_cast(phase);
39 if (dom != NULL) {
40 return dom;
41 }
42 if (_carry_dependency) {
43 return this;
44 }
45 return phase->type(in(1))->higher_equal_speculative(_type) ? in(1) : this;
46 }
47
48 //------------------------------Value------------------------------------------
49 // Take 'join' of input and cast-up type
50 const Type* ConstraintCastNode::Value(PhaseGVN* phase) const {
51 if (in(0) && phase->type(in(0)) == Type::TOP) return Type::TOP;
52 const Type* ft = phase->type(in(1))->filter_speculative(_type);
53
54 #ifdef ASSERT
55 // Previous versions of this function had some special case logic,
56 // which is no longer necessary. Make sure of the required effects.
57 switch (Opcode()) {
58 case Op_CastII:
59 {
60 const Type* t1 = phase->type(in(1));
61 if( t1 == Type::TOP ) assert(ft == Type::TOP, "special case #1");
62 const Type* rt = t1->join_speculative(_type);
63 if (rt->empty()) assert(ft == Type::TOP, "special case #2");
64 break;
65 }
66 case Op_CastPP:
67 if (phase->type(in(1)) == TypePtr::NULL_PTR &&
68 _type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull)
69 assert(ft == Type::TOP, "special case #3");
70 break;
71 }
72 #endif //ASSERT
73
74 return ft;
75 }
76
77 //------------------------------Ideal------------------------------------------
78 // Return a node which is more "ideal" than the current node. Strip out
79 // control copies
80 Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape) {
81 return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
82 }
83
84 uint ConstraintCastNode::cmp(const Node &n) const {
85 return TypeNode::cmp(n) && ((ConstraintCastNode&)n)._carry_dependency == _carry_dependency;
86 }
87
88 uint ConstraintCastNode::size_of() const {
89 return sizeof(*this);
90 }
91
92 Node* ConstraintCastNode::make_cast(int opcode, Node* c, Node *n, const Type *t, bool carry_dependency) {
93 switch(opcode) {
94 case Op_CastII: {
95 Node* cast = new CastIINode(n, t, carry_dependency);
96 cast->set_req(0, c);
97 return cast;
98 }
99 case Op_CastPP: {
100 Node* cast = new CastPPNode(n, t, carry_dependency);
101 cast->set_req(0, c);
102 return cast;
103 }
104 case Op_CheckCastPP: return new CheckCastPPNode(c, n, t, carry_dependency);
105 default:
106 fatal("Bad opcode %d", opcode);
107 }
108 return NULL;
109 }
110
111 TypeNode* ConstraintCastNode::dominating_cast(PhaseTransform *phase) const {
112 Node* val = in(1);
113 Node* ctl = in(0);
114 int opc = Opcode();
115 if (ctl == NULL) {
116 return NULL;
117 }
118 // Range check CastIIs may all end up under a single range check and
119 // in that case only the narrower CastII would be kept by the code
120 // below which would be incorrect.
121 if (is_CastII() && as_CastII()->has_range_check()) {
122 return NULL;
123 }
124 for (DUIterator_Fast imax, i = val->fast_outs(imax); i < imax; i++) {
125 Node* u = val->fast_out(i);
126 if (u != this &&
127 u->outcnt() > 0 &&
128 u->Opcode() == opc &&
129 u->in(0) != NULL &&
130 u->bottom_type()->higher_equal(type())) {
131 if (phase->is_dominator(u->in(0), ctl)) {
132 return u->as_Type();
133 }
134 if (is_CheckCastPP() && u->in(1)->is_Proj() && u->in(1)->in(0)->is_Allocate() &&
146 #ifndef PRODUCT
147 void ConstraintCastNode::dump_spec(outputStream *st) const {
148 TypeNode::dump_spec(st);
149 if (_carry_dependency) {
150 st->print(" carry dependency");
151 }
152 }
153 #endif
154
155 const Type* CastIINode::Value(PhaseGVN* phase) const {
156 const Type *res = ConstraintCastNode::Value(phase);
157
158 // Try to improve the type of the CastII if we recognize a CmpI/If
159 // pattern.
160 if (_carry_dependency) {
161 if (in(0) != NULL && in(0)->in(0) != NULL && in(0)->in(0)->is_If()) {
162 assert(in(0)->is_IfFalse() || in(0)->is_IfTrue(), "should be If proj");
163 Node* proj = in(0);
164 if (proj->in(0)->in(1)->is_Bool()) {
165 Node* b = proj->in(0)->in(1);
166 if (b->in(1)->Opcode() == Op_CmpI) {
167 Node* cmp = b->in(1);
168 if (cmp->in(1) == in(1) && phase->type(cmp->in(2))->isa_int()) {
169 const TypeInt* in2_t = phase->type(cmp->in(2))->is_int();
170 const Type* t = TypeInt::INT;
171 BoolTest test = b->as_Bool()->_test;
172 if (proj->is_IfFalse()) {
173 test = test.negate();
174 }
175 BoolTest::mask m = test._test;
176 jlong lo_long = min_jint;
177 jlong hi_long = max_jint;
178 if (m == BoolTest::le || m == BoolTest::lt) {
179 hi_long = in2_t->_hi;
180 if (m == BoolTest::lt) {
181 hi_long -= 1;
182 }
183 } else if (m == BoolTest::ge || m == BoolTest::gt) {
184 lo_long = in2_t->_lo;
185 if (m == BoolTest::gt) {
186 lo_long += 1;
210 res = res->filter_speculative(t);
211
212 return res;
213 }
214 }
215 }
216 }
217 }
218 return res;
219 }
220
221 Node *CastIINode::Ideal(PhaseGVN *phase, bool can_reshape) {
222 Node* progress = ConstraintCastNode::Ideal(phase, can_reshape);
223 if (progress != NULL) {
224 return progress;
225 }
226
227 // transform:
228 // (CastII (AddI x const)) -> (AddI (CastII x) const)
229 // So the AddI has a chance to be optimized out
230 if (in(1)->Opcode() == Op_AddI) {
231 Node* in2 = in(1)->in(2);
232 const TypeInt* in2_t = phase->type(in2)->isa_int();
233 if (in2_t != NULL && in2_t->singleton()) {
234 int in2_const = in2_t->_lo;
235 const TypeInt* current_type = _type->is_int();
236 jlong new_lo_long = ((jlong)current_type->_lo) - in2_const;
237 jlong new_hi_long = ((jlong)current_type->_hi) - in2_const;
238 int new_lo = (int)new_lo_long;
239 int new_hi = (int)new_hi_long;
240 if (((jlong)new_lo) == new_lo_long && ((jlong)new_hi) == new_hi_long) {
241 Node* in1 = in(1)->in(1);
242 CastIINode* new_cast = (CastIINode*)clone();
243 AddINode* new_add = (AddINode*)in(1)->clone();
244 new_cast->set_type(TypeInt::make(new_lo, new_hi, current_type->_widen));
245 new_cast->set_req(1, in1);
246 new_add->set_req(1, phase->transform(new_cast));
247 return new_add;
248 }
249 }
250 }
416 jint lo = min_jint;
417 jint hi = max_jint;
418 if (but_not_min_int) ++lo; // caller wants to negate the value w/o overflow
419 return (tl->_lo >= lo) && (tl->_hi <= hi);
420 }
421
422 static inline Node* addP_of_X2P(PhaseGVN *phase,
423 Node* base,
424 Node* dispX,
425 bool negate = false) {
426 if (negate) {
427 dispX = new SubXNode(phase->MakeConX(0), phase->transform(dispX));
428 }
429 return new AddPNode(phase->C->top(),
430 phase->transform(new CastX2PNode(base)),
431 phase->transform(dispX));
432 }
433
434 Node *CastX2PNode::Ideal(PhaseGVN *phase, bool can_reshape) {
435 // convert CastX2P(AddX(x, y)) to AddP(CastX2P(x), y) if y fits in an int
436 int op = in(1)->Opcode();
437 Node* x;
438 Node* y;
439 switch (op) {
440 case Op_SubX:
441 x = in(1)->in(1);
442 // Avoid ideal transformations ping-pong between this and AddP for raw pointers.
443 if (phase->find_intptr_t_con(x, -1) == 0)
444 break;
445 y = in(1)->in(2);
446 if (fits_in_int(phase->type(y), true)) {
447 return addP_of_X2P(phase, x, y, true);
448 }
449 break;
450 case Op_AddX:
451 x = in(1)->in(1);
452 y = in(1)->in(2);
453 if (fits_in_int(phase->type(y))) {
454 return addP_of_X2P(phase, x, y);
455 }
456 if (fits_in_int(phase->type(x))) {
457 return addP_of_X2P(phase, y, x);
458 }
459 break;
460 }
461 return NULL;
462 }
463
464 //------------------------------Identity---------------------------------------
465 Node* CastX2PNode::Identity(PhaseGVN* phase) {
466 if (in(1)->Opcode() == Op_CastP2X) return in(1)->in(1);
467 return this;
468 }
469
470 //=============================================================================
471 //------------------------------Value------------------------------------------
472 const Type* CastP2XNode::Value(PhaseGVN* phase) const {
473 const Type* t = phase->type(in(1));
474 if (t == Type::TOP) return Type::TOP;
475 if (t->base() == Type::RawPtr && t->singleton()) {
476 uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
477 return TypeX::make(bits);
478 }
479 return CastP2XNode::bottom_type();
480 }
481
482 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
483 return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
484 }
485
486 //------------------------------Identity---------------------------------------
487 Node* CastP2XNode::Identity(PhaseGVN* phase) {
488 if (in(1)->Opcode() == Op_CastX2P) return in(1)->in(1);
489 return this;
490 }
|
38 Node* dom = dominating_cast(phase);
39 if (dom != NULL) {
40 return dom;
41 }
42 if (_carry_dependency) {
43 return this;
44 }
45 return phase->type(in(1))->higher_equal_speculative(_type) ? in(1) : this;
46 }
47
48 //------------------------------Value------------------------------------------
49 // Take 'join' of input and cast-up type
50 const Type* ConstraintCastNode::Value(PhaseGVN* phase) const {
51 if (in(0) && phase->type(in(0)) == Type::TOP) return Type::TOP;
52 const Type* ft = phase->type(in(1))->filter_speculative(_type);
53
54 #ifdef ASSERT
55 // Previous versions of this function had some special case logic,
56 // which is no longer necessary. Make sure of the required effects.
57 switch (Opcode()) {
58 case Opcodes::Op_CastII:
59 {
60 const Type* t1 = phase->type(in(1));
61 if( t1 == Type::TOP ) assert(ft == Type::TOP, "special case #1");
62 const Type* rt = t1->join_speculative(_type);
63 if (rt->empty()) assert(ft == Type::TOP, "special case #2");
64 break;
65 }
66 case Opcodes::Op_CastPP:
67 if (phase->type(in(1)) == TypePtr::NULL_PTR &&
68 _type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull)
69 assert(ft == Type::TOP, "special case #3");
70 break;
71 }
72 #endif //ASSERT
73
74 return ft;
75 }
76
77 //------------------------------Ideal------------------------------------------
78 // Return a node which is more "ideal" than the current node. Strip out
79 // control copies
80 Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape) {
81 return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
82 }
83
84 uint ConstraintCastNode::cmp(const Node &n) const {
85 return TypeNode::cmp(n) && ((ConstraintCastNode&)n)._carry_dependency == _carry_dependency;
86 }
87
88 uint ConstraintCastNode::size_of() const {
89 return sizeof(*this);
90 }
91
92 Node* ConstraintCastNode::make_cast(Opcodes opcode, Node* c, Node *n, const Type *t, bool carry_dependency) {
93 switch(opcode) {
94 case Opcodes::Op_CastII: {
95 Node* cast = new CastIINode(n, t, carry_dependency);
96 cast->set_req(0, c);
97 return cast;
98 }
99 case Opcodes::Op_CastPP: {
100 Node* cast = new CastPPNode(n, t, carry_dependency);
101 cast->set_req(0, c);
102 return cast;
103 }
104 case Opcodes::Op_CheckCastPP: return new CheckCastPPNode(c, n, t, carry_dependency);
105 default:
106 fatal("Bad opcode %u", static_cast<uint>(opcode));
107 }
108 return NULL;
109 }
110
111 TypeNode* ConstraintCastNode::dominating_cast(PhaseTransform *phase) const {
112 Node* val = in(1);
113 Node* ctl = in(0);
114 Opcodes opc = Opcode();
115 if (ctl == NULL) {
116 return NULL;
117 }
118 // Range check CastIIs may all end up under a single range check and
119 // in that case only the narrower CastII would be kept by the code
120 // below which would be incorrect.
121 if (is_CastII() && as_CastII()->has_range_check()) {
122 return NULL;
123 }
124 for (DUIterator_Fast imax, i = val->fast_outs(imax); i < imax; i++) {
125 Node* u = val->fast_out(i);
126 if (u != this &&
127 u->outcnt() > 0 &&
128 u->Opcode() == opc &&
129 u->in(0) != NULL &&
130 u->bottom_type()->higher_equal(type())) {
131 if (phase->is_dominator(u->in(0), ctl)) {
132 return u->as_Type();
133 }
134 if (is_CheckCastPP() && u->in(1)->is_Proj() && u->in(1)->in(0)->is_Allocate() &&
146 #ifndef PRODUCT
147 void ConstraintCastNode::dump_spec(outputStream *st) const {
148 TypeNode::dump_spec(st);
149 if (_carry_dependency) {
150 st->print(" carry dependency");
151 }
152 }
153 #endif
154
155 const Type* CastIINode::Value(PhaseGVN* phase) const {
156 const Type *res = ConstraintCastNode::Value(phase);
157
158 // Try to improve the type of the CastII if we recognize a CmpI/If
159 // pattern.
160 if (_carry_dependency) {
161 if (in(0) != NULL && in(0)->in(0) != NULL && in(0)->in(0)->is_If()) {
162 assert(in(0)->is_IfFalse() || in(0)->is_IfTrue(), "should be If proj");
163 Node* proj = in(0);
164 if (proj->in(0)->in(1)->is_Bool()) {
165 Node* b = proj->in(0)->in(1);
166 if (b->in(1)->Opcode() == Opcodes::Op_CmpI) {
167 Node* cmp = b->in(1);
168 if (cmp->in(1) == in(1) && phase->type(cmp->in(2))->isa_int()) {
169 const TypeInt* in2_t = phase->type(cmp->in(2))->is_int();
170 const Type* t = TypeInt::INT;
171 BoolTest test = b->as_Bool()->_test;
172 if (proj->is_IfFalse()) {
173 test = test.negate();
174 }
175 BoolTest::mask m = test._test;
176 jlong lo_long = min_jint;
177 jlong hi_long = max_jint;
178 if (m == BoolTest::le || m == BoolTest::lt) {
179 hi_long = in2_t->_hi;
180 if (m == BoolTest::lt) {
181 hi_long -= 1;
182 }
183 } else if (m == BoolTest::ge || m == BoolTest::gt) {
184 lo_long = in2_t->_lo;
185 if (m == BoolTest::gt) {
186 lo_long += 1;
210 res = res->filter_speculative(t);
211
212 return res;
213 }
214 }
215 }
216 }
217 }
218 return res;
219 }
220
221 Node *CastIINode::Ideal(PhaseGVN *phase, bool can_reshape) {
222 Node* progress = ConstraintCastNode::Ideal(phase, can_reshape);
223 if (progress != NULL) {
224 return progress;
225 }
226
227 // transform:
228 // (CastII (AddI x const)) -> (AddI (CastII x) const)
229 // So the AddI has a chance to be optimized out
230 if (in(1)->Opcode() == Opcodes::Op_AddI) {
231 Node* in2 = in(1)->in(2);
232 const TypeInt* in2_t = phase->type(in2)->isa_int();
233 if (in2_t != NULL && in2_t->singleton()) {
234 int in2_const = in2_t->_lo;
235 const TypeInt* current_type = _type->is_int();
236 jlong new_lo_long = ((jlong)current_type->_lo) - in2_const;
237 jlong new_hi_long = ((jlong)current_type->_hi) - in2_const;
238 int new_lo = (int)new_lo_long;
239 int new_hi = (int)new_hi_long;
240 if (((jlong)new_lo) == new_lo_long && ((jlong)new_hi) == new_hi_long) {
241 Node* in1 = in(1)->in(1);
242 CastIINode* new_cast = (CastIINode*)clone();
243 AddINode* new_add = (AddINode*)in(1)->clone();
244 new_cast->set_type(TypeInt::make(new_lo, new_hi, current_type->_widen));
245 new_cast->set_req(1, in1);
246 new_add->set_req(1, phase->transform(new_cast));
247 return new_add;
248 }
249 }
250 }
416 jint lo = min_jint;
417 jint hi = max_jint;
418 if (but_not_min_int) ++lo; // caller wants to negate the value w/o overflow
419 return (tl->_lo >= lo) && (tl->_hi <= hi);
420 }
421
422 static inline Node* addP_of_X2P(PhaseGVN *phase,
423 Node* base,
424 Node* dispX,
425 bool negate = false) {
426 if (negate) {
427 dispX = new SubXNode(phase->MakeConX(0), phase->transform(dispX));
428 }
429 return new AddPNode(phase->C->top(),
430 phase->transform(new CastX2PNode(base)),
431 phase->transform(dispX));
432 }
433
434 Node *CastX2PNode::Ideal(PhaseGVN *phase, bool can_reshape) {
435 // convert CastX2P(AddX(x, y)) to AddP(CastX2P(x), y) if y fits in an int
436 Opcodes op = in(1)->Opcode();
437 Node* x;
438 Node* y;
439 switch (op) {
440 case Opcodes::Op_SubX:
441 x = in(1)->in(1);
442 // Avoid ideal transformations ping-pong between this and AddP for raw pointers.
443 if (phase->find_intptr_t_con(x, -1) == 0)
444 break;
445 y = in(1)->in(2);
446 if (fits_in_int(phase->type(y), true)) {
447 return addP_of_X2P(phase, x, y, true);
448 }
449 break;
450 case Opcodes::Op_AddX:
451 x = in(1)->in(1);
452 y = in(1)->in(2);
453 if (fits_in_int(phase->type(y))) {
454 return addP_of_X2P(phase, x, y);
455 }
456 if (fits_in_int(phase->type(x))) {
457 return addP_of_X2P(phase, y, x);
458 }
459 break;
460 }
461 return NULL;
462 }
463
464 //------------------------------Identity---------------------------------------
465 Node* CastX2PNode::Identity(PhaseGVN* phase) {
466 if (in(1)->Opcode() == Opcodes::Op_CastP2X) return in(1)->in(1);
467 return this;
468 }
469
470 //=============================================================================
471 //------------------------------Value------------------------------------------
472 const Type* CastP2XNode::Value(PhaseGVN* phase) const {
473 const Type* t = phase->type(in(1));
474 if (t == Type::TOP) return Type::TOP;
475 if (t->base() == Type::RawPtr && t->singleton()) {
476 uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
477 return TypeX::make(bits);
478 }
479 return CastP2XNode::bottom_type();
480 }
481
482 Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
483 return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
484 }
485
486 //------------------------------Identity---------------------------------------
487 Node* CastP2XNode::Identity(PhaseGVN* phase) {
488 if (in(1)->Opcode() == Opcodes::Op_CastX2P) return in(1)->in(1);
489 return this;
490 }
|