25
#include "precompiled.hpp"
26
#include "compiler/compileLog.hpp"
27
#include "gc/shared/barrierSet.hpp"
28
#include "gc/shared/c2/barrierSetC2.hpp"
29
#include "memory/allocation.inline.hpp"
30
#include "opto/addnode.hpp"
31
#include "opto/callnode.hpp"
32
#include "opto/cfgnode.hpp"
33
#include "opto/loopnode.hpp"
34
#include "opto/matcher.hpp"
35
#include "opto/movenode.hpp"
36
#include "opto/mulnode.hpp"
37
#include "opto/opaquenode.hpp"
38
#include "opto/opcodes.hpp"
39
#include "opto/phaseX.hpp"
40
#include "opto/subnode.hpp"
41
#include "runtime/sharedRuntime.hpp"
42
#include "utilities/reverse_bits.hpp"
53
Node* SubNode::Identity(PhaseGVN* phase) {
54
assert(in(1) != this, "Must already have called Value");
55
assert(in(2) != this, "Must already have called Value");
58
const Type *zero = add_id();
59
if( phase->type( in(1) )->higher_equal( zero ) &&
60
in(2)->Opcode() == Opcode() &&
61
phase->type( in(2)->in(1) )->higher_equal( zero ) ) {
66
if (in(1)->Opcode() == Op_AddI || in(1)->Opcode() == Op_AddL) {
67
if (in(1)->in(2) == in(2)) {
70
if (in(1)->in(1) == in(2)) {
75
return ( phase->type( in(2) )->higher_equal( zero ) ) ? in(1) : this;
80
const Type* SubNode::Value_common(PhaseValues* phase) const {
81
const Node* in1 = in(1);
82
const Node* in2 = in(2);
84
const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
85
if( t1 == Type::TOP ) return Type::TOP;
86
const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
87
if( t2 == Type::TOP ) return Type::TOP;
91
if (in1->eqv_uncast(in2)) return add_id();
94
if( t1 == Type::BOTTOM || t2 == Type::BOTTOM )
100
const Type* SubNode::Value(PhaseGVN* phase) const {
101
const Type* t = Value_common(phase);
105
const Type* t1 = phase->type(in(1));
106
const Type* t2 = phase->type(in(2));
111
SubNode* SubNode::make(Node* in1, Node* in2, BasicType bt) {
114
return new SubINode(in1, in2);
116
return new SubLNode(in1, in2);
118
fatal("Not implemented for %s", type2name(bt));
126
static bool is_cloop_increment(Node* inc) {
127
precond(inc->Opcode() == Op_AddI || inc->Opcode() == Op_AddL);
129
if (!inc->in(1)->is_Phi()) {
132
const PhiNode* phi = inc->in(1)->as_Phi();
134
if (!phi->region()->is_CountedLoop()) {
138
return inc == phi->region()->as_CountedLoop()->incr();
151
static bool ok_to_convert(Node* inc, Node* var) {
152
return !(is_cloop_increment(inc) || var->is_cloop_ind_var());
155
static bool is_cloop_condition(BoolNode* bol) {
156
for (DUIterator_Fast imax, i = bol->fast_outs(imax); i < imax; i++) {
157
Node* out = bol->fast_out(i);
158
if (out->is_BaseCountedLoopEnd()) {
166
Node *SubINode::Ideal(PhaseGVN *phase, bool can_reshape){
169
uint op1 = in1->Opcode();
170
uint op2 = in2->Opcode();
174
if ((in1 == this) || (in2 == this) ||
175
((op1 == Op_AddI || op1 == Op_SubI) &&
176
((in1->in(1) == this) || (in1->in(2) == this) ||
177
(in1->in(1) == in1) || (in1->in(2) == in1)))) {
178
assert(false, "dead loop in SubINode::Ideal");
182
const Type *t2 = phase->type( in2 );
183
if( t2 == Type::TOP ) return nullptr;
185
if( t2->base() == Type::Int ){
186
const TypeInt *i = t2->is_int();
188
return new AddINode(in1, phase->intcon(java_negate(i->get_con())));
194
if( op1 == Op_AddI && ok_to_convert(in1, in2) ) {
195
const Type *tadd = phase->type( in1->in(2) );
196
if( tadd->singleton() && tadd != Type::TOP ) {
197
Node *sub2 = phase->transform( new SubINode( in1->in(1), in2 ));
198
return new AddINode( sub2, in1->in(2) );
206
&& ok_to_convert(in2, in1)
207
&& in2->in(2)->Opcode() == Op_ConI) {
208
jint c0 = phase->type(in2->in(2))->isa_int()->get_con();
209
Node* in21 = in2->in(1);
210
if (in1->Opcode() == Op_ConI) {
212
jint c1 = phase->type(in1)->isa_int()->get_con();
213
Node* sub2 = phase->intcon(java_subtract(c1, c0));
214
return new SubINode(sub2, in21);
217
Node* sub2 = phase->transform(new SubINode(in1, in21));
218
Node* neg_c0 = phase->intcon(java_negate(c0));
219
return new AddINode(sub2, neg_c0);
223
const Type *t1 = phase->type( in1 );
224
if( t1 == Type::TOP ) return nullptr;
228
if ((op2 == Op_AddI || op2 == Op_SubI) &&
229
((in2->in(1) == this) || (in2->in(2) == this) ||
230
(in2->in(1) == in2) || (in2->in(2) == in2))) {
231
assert(false, "dead loop in SubINode::Ideal");
236
if (op2 == Op_AddI && in1 == in2->in(1)) {
237
return new SubINode(phase->intcon(0), in2->in(2));
240
if (op1 == Op_SubI && in1->in(1) == in2) {
241
return new SubINode(phase->intcon(0), in1->in(2));
244
if (op2 == Op_AddI && in1 == in2->in(2)) {
245
return new SubINode(phase->intcon(0), in2->in(1));
249
if (t1 == TypeInt::ZERO && op2 == Op_SubI && phase->type(in2->in(1)) != TypeInt::ZERO) {
250
return new SubINode(in2->in(2), in2->in(1));
255
if( t1 == TypeInt::ZERO && op2 == Op_AddI &&
256
(con = in2->in(2)->find_int_con(0)) != 0 )
257
return new SubINode( phase->intcon(-con), in2->in(1) );
260
if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(1) )
261
return new SubINode( in1->in(2), in2->in(2) );
264
if( op1 == Op_AddI && op2 == Op_AddI && in1->in(2) == in2->in(2) )
265
return new SubINode( in1->in(1), in2->in(1) );
268
if( op1 == Op_AddI && op2 == Op_AddI && in1->in(2) == in2->in(1) )
269
return new SubINode( in1->in(1), in2->in(2) );
272
if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(2) )
273
return new SubINode( in1->in(2), in2->in(1) );
277
if( op2 == Op_SubI && in2->outcnt() == 1) {
278
Node *add1 = phase->transform( new AddINode( in1, in2->in(2) ) );
279
return new SubINode( add1, in2->in(1) );
283
if (op1 == Op_MulI && op2 == Op_MulI) {
284
Node* sub_in1 = nullptr;
285
Node* sub_in2 = nullptr;
286
Node* mul_in = nullptr;
288
if (in1->in(1) == in2->in(1)) {
290
sub_in1 = in1->in(2);
291
sub_in2 = in2->in(2);
293
} else if (in1->in(2) == in2->in(1)) {
295
sub_in1 = in1->in(1);
296
sub_in2 = in2->in(2);
298
} else if (in1->in(2) == in2->in(2)) {
300
sub_in1 = in1->in(1);
301
sub_in2 = in2->in(1);
303
} else if (in1->in(1) == in2->in(2)) {
305
sub_in1 = in1->in(2);
306
sub_in2 = in2->in(1);
310
if (mul_in != nullptr) {
311
Node* sub = phase->transform(new SubINode(sub_in1, sub_in2));
312
return new MulINode(mul_in, sub);
317
if ( op2 == Op_RShiftI ) {
318
Node *in21 = in2->in(1);
319
Node *in22 = in2->in(2);
320
const TypeInt *zero = phase->type(in1)->isa_int();
321
const TypeInt *t21 = phase->type(in21)->isa_int();
322
const TypeInt *t22 = phase->type(in22)->isa_int();
323
if ( t21 && t22 && zero == TypeInt::ZERO && t22->is_con(31) ) {
324
return new URShiftINode(in21, in22);
333
const Type *SubINode::sub( const Type *t1, const Type *t2 ) const {
334
const TypeInt *r0 = t1->is_int();
335
const TypeInt *r1 = t2->is_int();
336
int32_t lo = java_subtract(r0->_lo, r1->_hi);
337
int32_t hi = java_subtract(r0->_hi, r1->_lo);
341
if( (((r0->_lo ^ r1->_hi) >= 0) ||
342
((r0->_lo ^ lo) >= 0)) &&
343
(((r0->_hi ^ r1->_lo) >= 0) ||
344
((r0->_hi ^ hi) >= 0)) )
345
return TypeInt::make(lo,hi,MAX2(r0->_widen,r1->_widen));
352
Node *SubLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
355
uint op1 = in1->Opcode();
356
uint op2 = in2->Opcode();
360
if ((in1 == this) || (in2 == this) ||
361
((op1 == Op_AddL || op1 == Op_SubL) &&
362
((in1->in(1) == this) || (in1->in(2) == this) ||
363
(in1->in(1) == in1) || (in1->in(2) == in1)))) {
364
assert(false, "dead loop in SubLNode::Ideal");
368
if( phase->type( in2 ) == Type::TOP ) return nullptr;
369
const TypeLong *i = phase->type( in2 )->isa_long();
373
return new AddLNode(in1, phase->longcon(java_negate(i->get_con())));
378
if( op1 == Op_AddL && ok_to_convert(in1, in2) ) {
379
Node *in11 = in1->in(1);
380
const Type *tadd = phase->type( in1->in(2) );
381
if( tadd->singleton() && tadd != Type::TOP ) {
382
Node *sub2 = phase->transform( new SubLNode( in11, in2 ));
383
return new AddLNode( sub2, in1->in(2) );
391
&& ok_to_convert(in2, in1)
392
&& in2->in(2)->Opcode() == Op_ConL) {
393
jlong c0 = phase->type(in2->in(2))->isa_long()->get_con();
394
Node* in21 = in2->in(1);
395
if (in1->Opcode() == Op_ConL) {
397
jlong c1 = phase->type(in1)->isa_long()->get_con();
398
Node* sub2 = phase->longcon(java_subtract(c1, c0));
399
return new SubLNode(sub2, in21);
401
Node* sub2 = phase->transform(new SubLNode(in1, in21));
402
Node* neg_c0 = phase->longcon(-c0);
403
return new AddLNode(sub2, neg_c0);
407
const Type *t1 = phase->type( in1 );
408
if( t1 == Type::TOP ) return nullptr;
412
if ((op2 == Op_AddL || op2 == Op_SubL) &&
413
((in2->in(1) == this) || (in2->in(2) == this) ||
414
(in2->in(1) == in2) || (in2->in(2) == in2))) {
415
assert(false, "dead loop in SubLNode::Ideal");
420
if (op2 == Op_AddL && in1 == in2->in(1)) {
421
return new SubLNode(phase->makecon(TypeLong::ZERO), in2->in(2));
424
if (op1 == Op_SubL && in1->in(1) == in2) {
425
return new SubLNode(phase->makecon(TypeLong::ZERO), in1->in(2));
428
if (op2 == Op_AddL && in1 == in2->in(2)) {
429
return new SubLNode(phase->makecon(TypeLong::ZERO), in2->in(1));
433
if (t1 == TypeLong::ZERO && op2 == Op_SubL && phase->type(in2->in(1)) != TypeLong::ZERO) {
434
return new SubLNode(in2->in(2), in2->in(1));
438
if( op1 == Op_AddL && op2 == Op_AddL && in1->in(1) == in2->in(1) )
439
return new SubLNode( in1->in(2), in2->in(2) );
442
if( op1 == Op_AddL && op2 == Op_AddL && in1->in(2) == in2->in(2) )
443
return new SubLNode( in1->in(1), in2->in(1) );
446
if( op1 == Op_AddL && op2 == Op_AddL && in1->in(2) == in2->in(1) )
447
return new SubLNode( in1->in(1), in2->in(2) );
450
if( op1 == Op_AddL && op2 == Op_AddL && in1->in(1) == in2->in(2) )
451
return new SubLNode( in1->in(2), in2->in(1) );
454
if( op2 == Op_SubL && in2->outcnt() == 1) {
455
Node *add1 = phase->transform( new AddLNode( in1, in2->in(2) ) );
456
return new SubLNode( add1, in2->in(1) );
460
if (op1 == Op_MulL && op2 == Op_MulL) {
461
Node* sub_in1 = nullptr;
462
Node* sub_in2 = nullptr;
463
Node* mul_in = nullptr;
465
if (in1->in(1) == in2->in(1)) {
467
sub_in1 = in1->in(2);
468
sub_in2 = in2->in(2);
470
} else if (in1->in(2) == in2->in(1)) {
472
sub_in1 = in1->in(1);
473
sub_in2 = in2->in(2);
475
} else if (in1->in(2) == in2->in(2)) {
477
sub_in1 = in1->in(1);
478
sub_in2 = in2->in(1);
480
} else if (in1->in(1) == in2->in(2)) {
482
sub_in1 = in1->in(2);
483
sub_in2 = in2->in(1);
487
if (mul_in != nullptr) {
488
Node* sub = phase->transform(new SubLNode(sub_in1, sub_in2));
489
return new MulLNode(mul_in, sub);
494
if ( op2 == Op_RShiftL ) {
495
Node *in21 = in2->in(1);
496
Node *in22 = in2->in(2);
497
const TypeLong *zero = phase->type(in1)->isa_long();
498
const TypeLong *t21 = phase->type(in21)->isa_long();
499
const TypeInt *t22 = phase->type(in22)->isa_int();
500
if ( t21 && t22 && zero == TypeLong::ZERO && t22->is_con(63) ) {
501
return new URShiftLNode(in21, in22);
510
const Type *SubLNode::sub( const Type *t1, const Type *t2 ) const {
511
const TypeLong *r0 = t1->is_long();
512
const TypeLong *r1 = t2->is_long();
513
jlong lo = java_subtract(r0->_lo, r1->_hi);
514
jlong hi = java_subtract(r0->_hi, r1->_lo);
518
if( (((r0->_lo ^ r1->_hi) >= 0) ||
519
((r0->_lo ^ lo) >= 0)) &&
520
(((r0->_hi ^ r1->_lo) >= 0) ||
521
((r0->_hi ^ hi) >= 0)) )
522
return TypeLong::make(lo,hi,MAX2(r0->_widen,r1->_widen));
524
return TypeLong::LONG;
530
const Type* SubFPNode::Value(PhaseGVN* phase) const {
531
const Node* in1 = in(1);
532
const Node* in2 = in(2);
534
const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
535
if( t1 == Type::TOP ) return Type::TOP;
536
const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
537
if( t2 == Type::TOP ) return Type::TOP;
541
if (t1->is_finite() && t2->is_finite() && in1 == in2) {
546
const Type *bot = bottom_type();
547
if( (t1 == bot) || (t2 == bot) ||
548
(t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )
557
Node *SubFNode::Ideal(PhaseGVN *phase, bool can_reshape) {
558
const Type *t2 = phase->type( in(2) );
560
if( t2->base() == Type::FloatCon ) {
574
const Type *SubFNode::sub( const Type *t1, const Type *t2 ) const {
576
if( g_isfinite(t1->getf()) && g_isfinite(t2->getf()) ) {
577
return TypeF::make( t1->getf() - t2->getf() );
579
else if( g_isnan(t1->getf()) ) {
582
else if( g_isnan(t2->getf()) ) {
592
Node *SubDNode::Ideal(PhaseGVN *phase, bool can_reshape){
593
const Type *t2 = phase->type( in(2) );
595
if( t2->base() == Type::DoubleCon ) {
609
const Type *SubDNode::sub( const Type *t1, const Type *t2 ) const {
611
if( g_isfinite(t1->getd()) && g_isfinite(t2->getd()) ) {
612
return TypeD::make( t1->getd() - t2->getd() );
614
else if( g_isnan(t1->getd()) ) {
617
else if( g_isnan(t2->getd()) ) {
630
Node* CmpNode::Identity(PhaseGVN* phase) {
634
CmpNode *CmpNode::make(Node *in1, Node *in2, BasicType bt, bool unsigned_comp) {
638
return new CmpUNode(in1, in2);
640
return new CmpINode(in1, in2);
643
return new CmpULNode(in1, in2);
645
return new CmpLNode(in1, in2);
650
return new CmpPNode(in1, in2);
653
return new CmpNNode(in1, in2);
655
fatal("Not implemented for %s", type2name(bt));
664
const Type *CmpINode::sub( const Type *t1, const Type *t2 ) const {
665
const TypeInt *r0 = t1->is_int();
666
const TypeInt *r1 = t2->is_int();
668
if( r0->_hi < r1->_lo )
669
return TypeInt::CC_LT;
670
else if( r0->_lo > r1->_hi )
671
return TypeInt::CC_GT;
673
else if( r0->is_con() && r1->is_con() ) {
674
assert(r0->get_con() == r1->get_con(), "must be equal");
675
return TypeInt::CC_EQ;
676
} else if( r0->_hi == r1->_lo )
677
return TypeInt::CC_LE;
678
else if( r0->_lo == r1->_hi )
679
return TypeInt::CC_GE;
683
const Type* CmpINode::Value(PhaseGVN* phase) const {
697
if (in1 != nullptr && in2 != nullptr) {
701
if (in1->Opcode() == Op_OpaqueZeroTripGuard && phase->type(in1) != Type::TOP) {
702
cmp = new CmpINode(in1->in(1), in2);
703
test = ((OpaqueZeroTripGuardNode*)in1)->_loop_entered_mask;
705
if (in2->Opcode() == Op_OpaqueZeroTripGuard && phase->type(in2) != Type::TOP) {
706
assert(cmp == nullptr, "A cmp with 2 OpaqueZeroTripGuard inputs");
707
cmp = new CmpINode(in1, in2->in(1));
708
test = ((OpaqueZeroTripGuardNode*)in2)->_loop_entered_mask;
710
if (cmp != nullptr) {
711
const Type* cmp_t = cmp->Value(phase);
712
const Type* t = BoolTest(test).cc2logical(cmp_t);
713
cmp->destruct(phase);
714
if (t == TypeInt::ZERO) {
720
return SubNode::Value(phase);
726
const Type *CmpUNode::sub( const Type *t1, const Type *t2 ) const {
727
assert(!t1->isa_ptr(), "obsolete usage of CmpU");
730
const TypeInt *r0 = t1->is_int();
731
const TypeInt *r1 = t2->is_int();
743
bool bot0 = ((jint)(lo0 ^ hi0) < 0);
744
bool bot1 = ((jint)(lo1 ^ hi1) < 0);
748
if (lo0 == 0 && hi0 == 0) {
749
return TypeInt::CC_LE;
750
} else if ((jint)lo0 == -1 && (jint)hi0 == -1) {
751
return TypeInt::CC_GE;
752
} else if (lo1 == 0 && hi1 == 0) {
753
return TypeInt::CC_GE;
754
} else if ((jint)lo1 == -1 && (jint)hi1 == -1) {
755
return TypeInt::CC_LE;
759
assert(lo0 <= hi0 && lo1 <= hi1, "unsigned ranges are valid");
762
return TypeInt::CC_LT;
763
} else if (lo0 > hi1) {
764
return TypeInt::CC_GT;
765
} else if (hi0 == lo1 && lo0 == hi1) {
766
return TypeInt::CC_EQ;
767
} else if (lo0 >= hi1) {
768
return TypeInt::CC_GE;
769
} else if (hi0 <= lo1) {
771
if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check())
772
return TypeInt::CC_LT;
773
return TypeInt::CC_LE;
782
if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check())
783
return TypeInt::CC_LT;
787
const Type* CmpUNode::Value(PhaseGVN* phase) const {
788
const Type* t = SubNode::Value_common(phase);
792
const Node* in1 = in(1);
793
const Node* in2 = in(2);
794
const Type* t1 = phase->type(in1);
795
const Type* t2 = phase->type(in2);
796
assert(t1->isa_int(), "CmpU has only Int type inputs");
797
if (t2 == TypeInt::INT) {
798
return bottom_type();
801
const Type* t_sub = sub(t1, t2);
803
uint in1_op = in1->Opcode();
804
if (in1_op == Op_AddI || in1_op == Op_SubI) {
816
const Node* in11 = in1->in(1);
817
const Node* in12 = in1->in(2);
818
const Type* t11 = (in11 == in1) ? Type::TOP : phase->type(in11);
819
const Type* t12 = (in12 == in1) ? Type::TOP : phase->type(in12);
821
if ((t11 != Type::TOP) && (t11 != TypeInt::INT) &&
822
(t12 != Type::TOP) && (t12 != TypeInt::INT)) {
823
const TypeInt *r0 = t11->is_int();
824
const TypeInt *r1 = t12->is_int();
825
jlong lo_r0 = r0->_lo;
826
jlong hi_r0 = r0->_hi;
827
jlong lo_r1 = r1->_lo;
828
jlong hi_r1 = r1->_hi;
829
if (in1_op == Op_SubI) {
838
jlong lo_long = lo_r0 + lo_r1;
839
jlong hi_long = hi_r0 + hi_r1;
840
int lo_tr1 = min_jint;
841
int hi_tr1 = (int)hi_long;
842
int lo_tr2 = (int)lo_long;
843
int hi_tr2 = max_jint;
844
bool underflow = lo_long != (jlong)lo_tr2;
845
bool overflow = hi_long != (jlong)hi_tr1;
848
if ((underflow != overflow) && (hi_tr1 < lo_tr2)) {
850
int w = MAX2(r0->_widen, r1->_widen);
851
const TypeInt* tr1 = TypeInt::make(lo_tr1, hi_tr1, w);
852
const TypeInt* tr2 = TypeInt::make(lo_tr2, hi_tr2, w);
853
const TypeInt* cmp1 = sub(tr1, t2)->is_int();
854
const TypeInt* cmp2 = sub(tr2, t2)->is_int();
856
const Type* t_cmp = cmp1->meet(cmp2);
858
return t_sub->filter(t_cmp);
866
bool CmpUNode::is_index_range_check() const {
868
return (in(1)->Opcode() == Op_ModI &&
869
in(1)->in(2)->eqv_uncast(in(2)));
873
Node *CmpINode::Ideal( PhaseGVN *phase, bool can_reshape ) {
874
if (phase->type(in(2))->higher_equal(TypeInt::ZERO)) {
875
switch (in(1)->Opcode()) {
877
return new CmpUNode(in(1)->in(1),in(1)->in(2));
879
return new CmpLNode(in(1)->in(1),in(1)->in(2));
881
return new CmpULNode(in(1)->in(1),in(1)->in(2));
883
return new CmpFNode(in(1)->in(1),in(1)->in(2));
885
return new CmpDNode(in(1)->in(1),in(1)->in(2));
895
Node *CmpLNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
896
const TypeLong *t2 = phase->type(in(2))->isa_long();
897
if (Opcode() == Op_CmpL && in(1)->Opcode() == Op_ConvI2L && t2 && t2->is_con()) {
898
const jlong con = t2->get_con();
899
if (con >= min_jint && con <= max_jint) {
900
return new CmpINode(in(1)->in(1), phase->intcon((jint)con));
909
const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const {
910
const TypeLong *r0 = t1->is_long();
911
const TypeLong *r1 = t2->is_long();
913
if( r0->_hi < r1->_lo )
914
return TypeInt::CC_LT;
915
else if( r0->_lo > r1->_hi )
916
return TypeInt::CC_GT;
918
else if( r0->is_con() && r1->is_con() ) {
919
assert(r0->get_con() == r1->get_con(), "must be equal");
920
return TypeInt::CC_EQ;
921
} else if( r0->_hi == r1->_lo )
922
return TypeInt::CC_LE;
923
else if( r0->_lo == r1->_hi )
924
return TypeInt::CC_GE;
931
const Type* CmpULNode::sub(const Type* t1, const Type* t2) const {
932
assert(!t1->isa_ptr(), "obsolete usage of CmpUL");
935
const TypeLong* r0 = t1->is_long();
936
const TypeLong* r1 = t2->is_long();
940
julong lo0 = r0->_lo;
941
julong hi0 = r0->_hi;
942
julong lo1 = r1->_lo;
943
julong hi1 = r1->_hi;
948
bool bot0 = ((jlong)(lo0 ^ hi0) < 0);
949
bool bot1 = ((jlong)(lo1 ^ hi1) < 0);
953
if (lo0 == 0 && hi0 == 0) {
954
return TypeInt::CC_LE;
955
} else if ((jlong)lo0 == -1 && (jlong)hi0 == -1) {
956
return TypeInt::CC_GE;
957
} else if (lo1 == 0 && hi1 == 0) {
958
return TypeInt::CC_GE;
959
} else if ((jlong)lo1 == -1 && (jlong)hi1 == -1) {
960
return TypeInt::CC_LE;
964
assert(lo0 <= hi0 && lo1 <= hi1, "unsigned ranges are valid");
967
return TypeInt::CC_LT;
968
} else if (lo0 > hi1) {
969
return TypeInt::CC_GT;
970
} else if (hi0 == lo1 && lo0 == hi1) {
971
return TypeInt::CC_EQ;
972
} else if (lo0 >= hi1) {
973
return TypeInt::CC_GE;
974
} else if (hi0 <= lo1) {
975
return TypeInt::CC_LE;
986
const Type *CmpPNode::sub( const Type *t1, const Type *t2 ) const {
987
const TypePtr *r0 = t1->is_ptr();
988
const TypePtr *r1 = t2->is_ptr();
991
if( TypePtr::above_centerline(r0->_ptr) ||
992
TypePtr::above_centerline(r1->_ptr) )
995
if (r0 == r1 && r0->singleton()) {
997
return TypeInt::CC_EQ;
1001
const TypeOopPtr* p0 = r0->isa_oopptr();
1002
const TypeOopPtr* p1 = r1->isa_oopptr();
1003
const TypeKlassPtr* k0 = r0->isa_klassptr();
1004
const TypeKlassPtr* k1 = r1->isa_klassptr();
1005
if ((p0 && p1) || (k0 && k1)) {
1007
Node* in1 = in(1)->uncast();
1008
Node* in2 = in(2)->uncast();
1009
AllocateNode* alloc1 = AllocateNode::Ideal_allocation(in1);
1010
AllocateNode* alloc2 = AllocateNode::Ideal_allocation(in2);
1011
if (MemNode::detect_ptr_independence(in1, alloc1, in2, alloc2, nullptr)) {
1012
return TypeInt::CC_GT;
1015
bool xklass0 = p0 ? p0->klass_is_exact() : k0->klass_is_exact();
1016
bool xklass1 = p1 ? p1->klass_is_exact() : k1->klass_is_exact();
1017
bool unrelated_classes = false;
1019
if ((p0 && p0->is_same_java_type_as(p1)) ||
1020
(k0 && k0->is_same_java_type_as(k1))) {
1021
} else if ((p0 && !p1->maybe_java_subtype_of(p0) && !p0->maybe_java_subtype_of(p1)) ||
1022
(k0 && !k1->maybe_java_subtype_of(k0) && !k0->maybe_java_subtype_of(k1))) {
1023
unrelated_classes = true;
1024
} else if ((p0 && !p1->maybe_java_subtype_of(p0)) ||
1025
(k0 && !k1->maybe_java_subtype_of(k0))) {
1026
unrelated_classes = xklass1;
1027
} else if ((p0 && !p0->maybe_java_subtype_of(p1)) ||
1028
(k0 && !k0->maybe_java_subtype_of(k1))) {
1029
unrelated_classes = xklass0;
1032
if (unrelated_classes) {
1036
TypePtr::PTR jp = r0->join_ptr(r1->_ptr);
1037
if (jp != TypePtr::Null && jp != TypePtr::BotPTR) {
1038
return TypeInt::CC_GT;
1046
if( r0->singleton() ) {
1047
intptr_t bits0 = r0->get_con();
1048
if( r1->singleton() )
1049
return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
1050
return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
1051
} else if( r1->singleton() ) {
1052
intptr_t bits1 = r1->get_con();
1053
return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC;
1058
static inline Node* isa_java_mirror_load(PhaseGVN* phase, Node* n) {
1062
BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1063
n = bs->step_over_gc_barrier(n);
1065
if (n->Opcode() != Op_LoadP) return nullptr;
1067
const TypeInstPtr* tp = phase->type(n)->isa_instptr();
1068
if (!tp || tp->instance_klass() != phase->C->env()->Class_klass()) return nullptr;
1070
Node* adr = n->in(MemNode::Address);
1072
if (adr->Opcode() != Op_LoadP || !phase->type(adr)->isa_rawptr()) return nullptr;
1073
adr = adr->in(MemNode::Address);
1076
Node* k = AddPNode::Ideal_base_and_offset(adr, phase, off);
1077
if (k == nullptr) return nullptr;
1078
const TypeKlassPtr* tkp = phase->type(k)->isa_klassptr();
1079
if (!tkp || off != in_bytes(Klass::java_mirror_offset())) return nullptr;
1085
static inline Node* isa_const_java_mirror(PhaseGVN* phase, Node* n) {
1088
if (!n->is_Con()) return nullptr;
1090
const TypeInstPtr* tp = phase->type(n)->isa_instptr();
1091
if (!tp) return nullptr;
1093
ciType* mirror_type = tp->java_mirror_type();
1096
if (!mirror_type) return nullptr;
1100
if (mirror_type->is_classless()) {
1101
return phase->makecon(TypePtr::NULL_PTR);
1105
assert(mirror_type->is_klass(), "mirror_type should represent a Klass*");
1106
return phase->makecon(TypeKlassPtr::make(mirror_type->as_klass(), Type::trust_interfaces));
1116
Node *CmpPNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
1130
Node* k1 = isa_java_mirror_load(phase, in(1));
1131
Node* k2 = isa_java_mirror_load(phase, in(2));
1132
Node* conk2 = isa_const_java_mirror(phase, in(2));
1134
if (k1 && (k2 || conk2)) {
1136
Node* rhs = (k2 != nullptr) ? k2 : conk2;
1137
set_req_X(1, lhs, phase);
1138
set_req_X(2, rhs, phase);
1144
const TypeKlassPtr* t2 = phase->type(in(2))->isa_klassptr();
1145
if (t2 == nullptr || !t2->klass_is_exact())
1148
ciKlass* superklass = t2->exact_klass();
1152
if (ldk1->is_DecodeNKlass()) {
1154
if (ldk1->Opcode() != Op_LoadNKlass )
1156
} else if (ldk1->Opcode() != Op_LoadKlass )
1159
Node* adr1 = ldk1->in(MemNode::Address);
1161
Node* ldk2 = AddPNode::Ideal_base_and_offset(adr1, phase, con2);
1162
if (ldk2 == nullptr)
1164
if (con2 == oopDesc::klass_offset_in_bytes()) {
1167
if (superklass->is_interface() ||
1168
superklass->is_abstract()) {
1170
this->set_req(2, phase->makecon(TypePtr::NULL_PTR));
1177
if (ldk2->is_DecodeNKlass()) {
1179
if (ldk2->in(1)->Opcode() != Op_LoadNKlass )
1181
} else if (ldk2->Opcode() != Op_LoadKlass)
1185
if (con2 != (intptr_t) superklass->super_check_offset())
1198
while (superklass->is_obj_array_klass()) {
1199
ciType* elem = superklass->as_obj_array_klass()->element_type();
1200
superklass = elem->as_klass();
1202
if (superklass->is_instance_klass()) {
1203
ciInstanceKlass* ik = superklass->as_instance_klass();
1204
if (ik->has_subklass() || ik->is_interface()) return nullptr;
1206
if (!ik->is_final()) {
1207
phase->C->dependencies()->assert_leaf_type(ik);
1212
this->set_req_X(1, ldk2, phase);
1221
const Type *CmpNNode::sub( const Type *t1, const Type *t2 ) const {
1222
ShouldNotReachHere();
1223
return bottom_type();
1227
Node *CmpNNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
1235
const Type* CmpFNode::Value(PhaseGVN* phase) const {
1236
const Node* in1 = in(1);
1237
const Node* in2 = in(2);
1239
const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
1240
if( t1 == Type::TOP ) return Type::TOP;
1241
const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
1242
if( t2 == Type::TOP ) return Type::TOP;
1246
const TypeF *tf1 = t1->isa_float_constant();
1247
const TypeF *tf2 = t2->isa_float_constant();
1248
if( !tf1 || !tf2 ) return TypeInt::CC;
1251
if( tf1->is_nan() || tf2->is_nan() )
1252
return TypeInt::CC_LT;
1254
if( tf1->_f < tf2->_f ) return TypeInt::CC_LT;
1255
if( tf1->_f > tf2->_f ) return TypeInt::CC_GT;
1256
assert( tf1->_f == tf2->_f, "do not understand FP behavior" );
1257
return TypeInt::CC_EQ;
1265
const Type* CmpDNode::Value(PhaseGVN* phase) const {
1266
const Node* in1 = in(1);
1267
const Node* in2 = in(2);
1269
const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
1270
if( t1 == Type::TOP ) return Type::TOP;
1271
const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
1272
if( t2 == Type::TOP ) return Type::TOP;
1276
const TypeD *td1 = t1->isa_double_constant();
1277
const TypeD *td2 = t2->isa_double_constant();
1278
if( !td1 || !td2 ) return TypeInt::CC;
1281
if( td1->is_nan() || td2->is_nan() )
1282
return TypeInt::CC_LT;
1284
if( td1->_d < td2->_d ) return TypeInt::CC_LT;
1285
if( td1->_d > td2->_d ) return TypeInt::CC_GT;
1286
assert( td1->_d == td2->_d, "do not understand FP behavior" );
1287
return TypeInt::CC_EQ;
1291
Node *CmpDNode::Ideal(PhaseGVN *phase, bool can_reshape){
1301
if( in(idx_f2d)->Opcode() != Op_ConvF2D )
1303
int idx_con = 3-idx_f2d;
1305
if( ConvertCmpD2CmpF &&
1306
in(idx_f2d)->Opcode() == Op_ConvF2D &&
1307
in(idx_con)->Opcode() == Op_ConD ) {
1308
const TypeD *t2 = in(idx_con)->bottom_type()->is_double_constant();
1309
double t2_value_as_double = t2->_d;
1310
float t2_value_as_float = (float)t2_value_as_double;
1311
if( t2_value_as_double == (double)t2_value_as_float ) {
1314
Node *new_in1 = in(idx_f2d)->in(1);
1315
Node *new_in2 = phase->makecon( TypeF::make(t2_value_as_float) );
1316
if( idx_f2d != 1 ) {
1317
Node *tmp = new_in1;
1321
CmpFNode *new_cmp = (Opcode() == Op_CmpD3)
1322
? new CmpF3Node( new_in1, new_in2 )
1323
: new CmpFNode ( new_in1, new_in2 ) ;
1335
const Type *BoolTest::cc2logical( const Type *CC ) const {
1336
if( CC == Type::TOP ) return Type::TOP;
1337
if( CC->base() != Type::Int ) return TypeInt::BOOL;
1338
const TypeInt *ti = CC->is_int();
1339
if( ti->is_con() ) {
1341
int tmp = ((ti->get_con()&3) == (_test&3)) ? 1 : 0;
1342
if( _test & 4 ) tmp = 1-tmp;
1343
return TypeInt::make(tmp);
1346
if( CC == TypeInt::CC_GE ) {
1347
if( _test == ge ) return TypeInt::ONE;
1348
if( _test == lt ) return TypeInt::ZERO;
1350
if( CC == TypeInt::CC_LE ) {
1351
if( _test == le ) return TypeInt::ONE;
1352
if( _test == gt ) return TypeInt::ZERO;
1355
return TypeInt::BOOL;
1360
void BoolTest::dump_on(outputStream *st) const {
1361
const char *msg[] = {"eq","gt","of","lt","ne","le","nof","ge"};
1362
st->print("%s", msg[_test]);
1367
BoolTest::mask BoolTest::merge(BoolTest other) const {
1368
const mask res[illegal+1][illegal+1] = {
1370
{eq, never, illegal, never, never, eq, illegal, eq, never, illegal},
1371
{never, gt, illegal, never, gt, never, illegal, gt, never, illegal},
1372
{illegal, illegal, illegal, illegal, illegal, illegal, illegal, illegal, never, illegal},
1373
{never, never, illegal, lt, lt, lt, illegal, never, never, illegal},
1374
{never, gt, illegal, lt, ne, lt, illegal, gt, never, illegal},
1375
{eq, never, illegal, lt, lt, le, illegal, eq, never, illegal},
1376
{illegal, illegal, illegal, illegal, illegal, illegal, illegal, illegal, never, illegal},
1377
{eq, gt, illegal, never, gt, eq, illegal, ge, never, illegal},
1378
{never, never, never, never, never, never, never, never, never, illegal},
1379
{illegal, illegal, illegal, illegal, illegal, illegal, illegal, illegal, illegal, illegal}};
1380
return res[_test][other._test];
1384
uint BoolNode::hash() const { return (Node::hash() << 3)|(_test._test+1); }
1385
uint BoolNode::size_of() const { return sizeof(BoolNode); }
1388
bool BoolNode::cmp( const Node &n ) const {
1389
const BoolNode *b = (const BoolNode *)&n;
1390
return (_test._test == b->_test._test);
1394
Node* BoolNode::make_predicate(Node* test_value, PhaseGVN* phase) {
1395
if (test_value->is_Con()) return test_value;
1396
if (test_value->is_Bool()) return test_value;
1397
if (test_value->is_CMove() &&
1398
test_value->in(CMoveNode::Condition)->is_Bool()) {
1399
BoolNode* bol = test_value->in(CMoveNode::Condition)->as_Bool();
1400
const Type* ftype = phase->type(test_value->in(CMoveNode::IfFalse));
1401
const Type* ttype = phase->type(test_value->in(CMoveNode::IfTrue));
1402
if (ftype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ttype)) {
1404
} else if (ttype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ftype)) {
1405
return phase->transform( bol->negate(phase) );
1410
Node* cmp = new CmpINode(test_value, phase->intcon(0));
1411
cmp = phase->transform(cmp);
1412
Node* bol = new BoolNode(cmp, BoolTest::ne);
1413
return phase->transform(bol);
1417
Node* BoolNode::as_int_value(PhaseGVN* phase) {
1419
Node* cmov = CMoveNode::make(nullptr, this,
1420
phase->intcon(0), phase->intcon(1),
1422
return phase->transform(cmov);
1426
BoolNode* BoolNode::negate(PhaseGVN* phase) {
1427
return new BoolNode(in(1), _test.negate());
1433
Node* BoolNode::fold_cmpI(PhaseGVN* phase, SubNode* cmp, Node* cmp1, int cmp_op,
1434
int cmp1_op, const TypeInt* cmp2_type) {
1436
if((_test._test == BoolTest::eq || _test._test == BoolTest::ne) &&
1437
(cmp_op == Op_CmpI) && (cmp1_op == Op_AddI || cmp1_op == Op_SubI)) {
1439
const TypeInt* r0 = phase->type(cmp1->in(1))->isa_int();
1440
const TypeInt* r1 = phase->type(cmp1->in(2))->isa_int();
1441
if ((r0 != nullptr) && (r0 != TypeInt::INT) &&
1442
(r1 != nullptr) && (r1 != TypeInt::INT) &&
1443
(cmp2_type != TypeInt::INT)) {
1445
jlong lo_long = r0->_lo;
1446
jlong hi_long = r0->_hi;
1447
if (cmp1_op == Op_AddI) {
1455
int lo_int = (int)lo_long;
1456
int hi_int = (int)hi_long;
1457
bool underflow = lo_long != (jlong)lo_int;
1458
bool overflow = hi_long != (jlong)hi_int;
1459
if ((underflow != overflow) && (hi_int < lo_int)) {
1462
int w = MAX2(r0->_widen, r1->_widen);
1463
const TypeInt* tr1 = TypeInt::make(min_jint, hi_int, w);
1464
const TypeInt* tr2 = TypeInt::make(lo_int, max_jint, w);
1466
const Type* sub_tr1 = cmp->sub(tr1, cmp2_type);
1467
const Type* sub_tr2 = cmp->sub(tr2, cmp2_type);
1468
if (sub_tr1 == TypeInt::CC_LT && sub_tr2 == TypeInt::CC_GT) {
1471
return ConINode::make((_test._test == BoolTest::eq) ? 0 : 1);
1479
static bool is_counted_loop_cmp(Node *cmp) {
1480
Node *n = cmp->in(1)->in(1);
1481
return n != nullptr &&
1483
n->in(0) != nullptr &&
1484
n->in(0)->is_CountedLoop() &&
1485
n->in(0)->as_CountedLoop()->phi() == n;
1489
Node *BoolNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1493
if( !cmp->is_Sub() ) return nullptr;
1494
int cop = cmp->Opcode();
1495
if( cop == Op_FastLock || cop == Op_FastUnlock ||
1496
cmp->is_SubTypeCheck() || cop == Op_VectorTest ) {
1499
Node *cmp1 = cmp->in(1);
1500
Node *cmp2 = cmp->in(2);
1501
if( !cmp1 ) return nullptr;
1503
if (_test._test == BoolTest::overflow || _test._test == BoolTest::no_overflow) {
1507
const int cmp1_op = cmp1->Opcode();
1508
const int cmp2_op = cmp2->Opcode();
1515
if (con->is_Con() && !cmp2->is_Con() && cmp2_op != Op_OpaqueZeroTripGuard &&
1517
cop != Op_CmpD && cop != Op_CmpF &&
1520
!is_counted_loop_exit_test() ) {
1525
cmp->swap_edges(1, 2);
1526
cmp = phase->transform( cmp );
1527
return new BoolNode( cmp, _test.commute() );
1531
if (cop == Op_CmpI &&
1532
(_test._test == BoolTest::eq || _test._test == BoolTest::ne) &&
1533
cmp1_op == Op_CMoveI && cmp2->find_int_con(1) == 0) {
1535
if (cmp1->in(CMoveNode::Condition)->is_Bool() &&
1536
cmp1->in(CMoveNode::IfTrue)->find_int_con(1) == 0 &&
1537
cmp1->in(CMoveNode::IfFalse)->find_int_con(0) != 0) {
1538
BoolNode* target = cmp1->in(CMoveNode::Condition)->as_Bool();
1539
return new BoolNode(target->in(1),
1540
(_test._test == BoolTest::eq) ? target->_test._test :
1541
target->_test.negate());
1546
if (cop == Op_CmpI &&
1547
(_test._test == BoolTest::eq || _test._test == BoolTest::ne) &&
1548
cmp1_op == Op_AndI && cmp2_op == Op_ConI &&
1549
cmp1->in(2)->Opcode() == Op_ConI) {
1550
const TypeInt *t12 = phase->type(cmp2)->isa_int();
1551
const TypeInt *t112 = phase->type(cmp1->in(2))->isa_int();
1552
if (t12 && t12->is_con() && t112 && t112->is_con() &&
1553
t12->get_con() == t112->get_con() && is_power_of_2(t12->get_con())) {
1554
Node *ncmp = phase->transform(new CmpINode(cmp1, phase->intcon(0)));
1555
return new BoolNode(ncmp, _test.negate());
1560
if (cop == Op_CmpL &&
1561
(_test._test == BoolTest::eq || _test._test == BoolTest::ne) &&
1562
cmp1_op == Op_AndL && cmp2_op == Op_ConL &&
1563
cmp1->in(2)->Opcode() == Op_ConL) {
1564
const TypeLong *t12 = phase->type(cmp2)->isa_long();
1565
const TypeLong *t112 = phase->type(cmp1->in(2))->isa_long();
1566
if (t12 && t12->is_con() && t112 && t112->is_con() &&
1567
t12->get_con() == t112->get_con() && is_power_of_2(t12->get_con())) {
1568
Node *ncmp = phase->transform(new CmpLNode(cmp1, phase->longcon(0)));
1569
return new BoolNode(ncmp, _test.negate());
1575
if (cop == Op_CmpI &&
1576
cmp1_op == Op_AddI &&
1577
phase->type(cmp1->in(2)) == TypeInt::MIN &&
1578
!is_cloop_condition(this)) {
1579
if (cmp2_op == Op_ConI) {
1580
Node* ncmp2 = phase->intcon(java_add(cmp2->get_int(), min_jint));
1581
Node* ncmp = phase->transform(new CmpUNode(cmp1->in(1), ncmp2));
1582
return new BoolNode(ncmp, _test._test);
1583
} else if (cmp2_op == Op_AddI &&
1584
phase->type(cmp2->in(2)) == TypeInt::MIN &&
1585
!is_cloop_condition(this)) {
1586
Node* ncmp = phase->transform(new CmpUNode(cmp1->in(1), cmp2->in(1)));
1587
return new BoolNode(ncmp, _test._test);
1593
if (cop == Op_CmpL &&
1594
cmp1_op == Op_AddL &&
1595
phase->type(cmp1->in(2)) == TypeLong::MIN &&
1596
!is_cloop_condition(this)) {
1597
if (cmp2_op == Op_ConL) {
1598
Node* ncmp2 = phase->longcon(java_add(cmp2->get_long(), min_jlong));
1599
Node* ncmp = phase->transform(new CmpULNode(cmp1->in(1), ncmp2));
1600
return new BoolNode(ncmp, _test._test);
1601
} else if (cmp2_op == Op_AddL &&
1602
phase->type(cmp2->in(2)) == TypeLong::MIN &&
1603
!is_cloop_condition(this)) {
1604
Node* ncmp = phase->transform(new CmpULNode(cmp1->in(1), cmp2->in(1)));
1605
return new BoolNode(ncmp, _test._test);
1612
const TypeInt* cmp2_type = phase->type(cmp2)->isa_int();
1613
if (cmp2_type == nullptr) return nullptr;
1615
if( cmp2_type == TypeInt::ZERO &&
1616
cmp1_op == Op_XorI &&
1617
j_xor->in(1) != j_xor &&
1618
phase->type( j_xor->in(1) ) == TypeInt::BOOL &&
1619
phase->type( j_xor->in(2) ) == TypeInt::ONE &&
1620
(_test._test == BoolTest::eq ||
1621
_test._test == BoolTest::ne) ) {
1622
Node *ncmp = phase->transform(new CmpINode(j_xor->in(1),cmp2));
1623
return new BoolNode( ncmp, _test.negate() );
1628
if (cop == Op_CmpU &&
1629
cmp1_op == Op_AndI) {
1630
Node* bound = nullptr;
1631
if (_test._test == BoolTest::le) {
1633
} else if (_test._test == BoolTest::lt &&
1634
cmp2->Opcode() == Op_AddI &&
1635
cmp2->in(2)->find_int_con(0) == 1) {
1636
bound = cmp2->in(1);
1638
if (cmp1->in(2) == bound || cmp1->in(1) == bound) {
1639
return ConINode::make(1);
1645
if (cop == Op_CmpU &&
1646
_test._test == BoolTest::lt &&
1647
cmp1_op == Op_AndI) {
1648
Node* l = cmp1->in(1);
1649
Node* r = cmp1->in(2);
1650
for (int repeat = 0; repeat < 2; repeat++) {
1651
bool match = r->Opcode() == Op_AddI && r->in(2)->find_int_con(0) == -1 &&
1656
Node* ncmp = cmp2->Opcode() == Op_LoadRange
1657
? phase->transform(new CmpUNode(cmp2, phase->intcon(0)))
1658
: phase->transform(new CmpINode(cmp2, phase->intcon(0)));
1659
return new BoolNode(ncmp, BoolTest::gt);
1670
if (cop == Op_CmpU &&
1671
cmp1_op != Op_LoadRange &&
1672
(((_test._test == BoolTest::lt || _test._test == BoolTest::ge) &&
1673
cmp2->find_int_con(-1) == 1) ||
1674
((_test._test == BoolTest::le || _test._test == BoolTest::gt) &&
1675
cmp2->find_int_con(-1) == 0))) {
1676
Node* ncmp = phase->transform(new CmpINode(cmp1, phase->intcon(0)));
1677
return new BoolNode(ncmp, _test.is_less() ? BoolTest::eq : BoolTest::ne);
1685
if (cop == Op_CmpI &&
1686
cmp1_op == Op_LoadRange &&
1687
cmp2->find_int_con(-1) == 0) {
1688
if (_test._test == BoolTest::le || _test._test == BoolTest::eq) {
1689
Node* ncmp = phase->transform(new CmpUNode(cmp1, cmp2));
1690
return new BoolNode(ncmp, BoolTest::le);
1691
} else if (_test._test == BoolTest::ne) {
1692
Node* ncmp = phase->transform(new CmpUNode(cmp1, cmp2));
1693
return new BoolNode(ncmp, BoolTest::gt);
1700
if( cmp2_type == TypeInt::ZERO &&
1701
cmp1_op == Op_Conv2B &&
1702
(_test._test == BoolTest::eq ||
1703
_test._test == BoolTest::ne) ) {
1704
Node *ncmp = phase->transform(phase->type(c2b->in(1))->isa_int()
1705
? (Node*)new CmpINode(c2b->in(1),cmp2)
1706
: (Node*)new CmpPNode(c2b->in(1),phase->makecon(TypePtr::NULL_PTR))
1708
return new BoolNode( ncmp, _test._test );
1714
if ((_test._test == BoolTest::eq || _test._test == BoolTest::ne) &&
1716
(cmp1_op == Op_SubI) &&
1717
( cmp2_type == TypeInt::ZERO ) ) {
1718
Node *ncmp = phase->transform( new CmpINode(cmp1->in(1),cmp1->in(2)));
1719
return new BoolNode( ncmp, _test._test );
1723
if ((_test._test == BoolTest::eq || _test._test == BoolTest::ne) &&
1725
cmp1_op == Op_AddI &&
1726
cmp1->in(2) != nullptr &&
1727
phase->type(cmp1->in(2))->isa_int() &&
1728
phase->type(cmp1->in(2))->is_int()->is_con() &&
1729
cmp2_type == TypeInt::ZERO &&
1730
!is_counted_loop_cmp(cmp)
1732
const TypeInt* cmp1_in2 = phase->type(cmp1->in(2))->is_int();
1733
Node *ncmp = phase->transform( new CmpINode(cmp1->in(1),phase->intcon(-cmp1_in2->_hi)));
1734
return new BoolNode( ncmp, _test._test );
1740
if ((_test._test == BoolTest::eq || _test._test == BoolTest::ne) &&
1742
(cmp2_type == TypeInt::ZERO) &&
1743
(cmp1_op == Op_Phi)) {
1745
PhiNode *phi = cmp1->as_Phi();
1746
int idx_true = phi->is_diamond_phi();
1747
if (idx_true != 0) {
1749
Node *tin = phi->in(idx_true);
1750
Node *fin = phi->in(3 - idx_true);
1751
if ((tin->Opcode() == Op_SubI) &&
1752
(phase->type(tin->in(1)) == TypeInt::ZERO) &&
1753
(tin->in(2) == fin)) {
1755
Node *ncmp = phase->transform(new CmpINode(fin, cmp2));
1756
return new BoolNode(ncmp, _test._test);
1758
if ((fin->Opcode() == Op_SubI) &&
1759
(phase->type(fin->in(1)) == TypeInt::ZERO) &&
1760
(fin->in(2) == tin)) {
1762
Node *ncmp = phase->transform(new CmpINode(tin, cmp2));
1763
return new BoolNode(ncmp, _test._test);
1771
if( cop == Op_CmpI &&
1772
cmp1_op == Op_SubI &&
1773
cmp2_type == TypeInt::ZERO &&
1774
phase->type( cmp1->in(1) ) == TypeInt::ZERO &&
1775
phase->type( cmp1->in(2) )->higher_equal(TypeInt::SYMINT) ) {
1776
Node *ncmp = phase->transform( new CmpINode(cmp1->in(2),cmp2));
1777
return new BoolNode( ncmp, _test.commute() );
1781
return fold_cmpI(phase, cmp->as_Sub(), cmp1, cop, cmp1_op, cmp2_type);
1832
const Type* BoolNode::Value(PhaseGVN* phase) const {
1833
return _test.cc2logical( phase->type( in(1) ) );
1839
void BoolNode::dump_spec(outputStream *st) const {
1848
bool BoolNode::is_counted_loop_exit_test() {
1849
for( DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++ ) {
1850
Node* use = fast_out(i);
1851
if (use->is_CountedLoopEnd()) {
1860
const Type* AbsNode::Value(PhaseGVN* phase) const {
1861
const Type* t1 = phase->type(in(1));
1862
if (t1 == Type::TOP) return Type::TOP;
1864
switch (t1->base()) {
1866
const TypeInt* ti = t1->is_int();
1868
return TypeInt::make(uabs(ti->get_con()));
1873
const TypeLong* tl = t1->is_long();
1875
return TypeLong::make(uabs(tl->get_con()));
1879
case Type::FloatCon:
1880
return TypeF::make(abs(t1->getf()));
1881
case Type::DoubleCon:
1882
return TypeD::make(abs(t1->getd()));
1887
return bottom_type();
1891
Node* AbsNode::Identity(PhaseGVN* phase) {
1894
if (phase->type(in1)->higher_equal(TypeInt::POS) ||
1895
phase->type(in1)->higher_equal(TypeLong::POS)) {
1899
if (in1->Opcode() == Opcode()) {
1906
Node* AbsNode::Ideal(PhaseGVN* phase, bool can_reshape) {
1909
if (in1->is_Sub() && phase->type(in1->in(1))->is_zero_type()) {
1910
set_req_X(1, in1->in(2), phase);
1919
const Type* SqrtDNode::Value(PhaseGVN* phase) const {
1920
const Type *t1 = phase->type( in(1) );
1921
if( t1 == Type::TOP ) return Type::TOP;
1922
if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
1923
double d = t1->getd();
1924
if( d < 0.0 ) return Type::DOUBLE;
1925
return TypeD::make( sqrt( d ) );
1928
const Type* SqrtFNode::Value(PhaseGVN* phase) const {
1929
const Type *t1 = phase->type( in(1) );
1930
if( t1 == Type::TOP ) return Type::TOP;
1931
if( t1->base() != Type::FloatCon ) return Type::FLOAT;
1932
float f = t1->getf();
1933
if( f < 0.0f ) return Type::FLOAT;
1934
return TypeF::make( (float)sqrt( (double)f ) );
1937
const Type* ReverseINode::Value(PhaseGVN* phase) const {
1938
const Type *t1 = phase->type( in(1) );
1939
if (t1 == Type::TOP) {
1942
const TypeInt* t1int = t1->isa_int();
1943
if (t1int && t1int->is_con()) {
1944
jint res = reverse_bits(t1int->get_con());
1945
return TypeInt::make(res);
1947
return bottom_type();
1950
const Type* ReverseLNode::Value(PhaseGVN* phase) const {
1951
const Type *t1 = phase->type( in(1) );
1952
if (t1 == Type::TOP) {
1955
const TypeLong* t1long = t1->isa_long();
1956
if (t1long && t1long->is_con()) {
1957
jlong res = reverse_bits(t1long->get_con());
1958
return TypeLong::make(res);
1960
return bottom_type();
1963
Node* ReverseINode::Identity(PhaseGVN* phase) {
1964
if (in(1)->Opcode() == Op_ReverseI) {
1965
return in(1)->in(1);
1970
Node* ReverseLNode::Identity(PhaseGVN* phase) {
1971
if (in(1)->Opcode() == Op_ReverseL) {
1972
return in(1)->in(1);