35
36 // Portions of code courtesy of Clifford Click
37
38 // Classic Add functionality. This covers all the usual 'add' behaviors for
39 // an algebraic ring. Add-integer, add-float, add-double, and binary-or are
40 // all inherited from this class. The various identity values are supplied
41 // by virtual functions.
42
43
44 //=============================================================================
45 //------------------------------hash-------------------------------------------
46 // Hash function over AddNodes. Needs to be commutative; i.e., I swap
47 // (commute) inputs to AddNodes willy-nilly so the hash function must return
48 // the same value in the presence of edge swapping.
49 uint AddNode::hash() const {
50 return (uintptr_t)in(1) + (uintptr_t)in(2) + Opcode();
51 }
52
53 //------------------------------Identity---------------------------------------
54 // If either input is a constant 0, return the other input.
55 Node *AddNode::Identity( PhaseTransform *phase ) {
56 const Type *zero = add_id(); // The additive identity
57 if( phase->type( in(1) )->higher_equal( zero ) ) return in(2);
58 if( phase->type( in(2) )->higher_equal( zero ) ) return in(1);
59 return this;
60 }
61
62 //------------------------------commute----------------------------------------
63 // Commute operands to move loads and constants to the right.
64 static bool commute( Node *add, int con_left, int con_right ) {
65 Node *in1 = add->in(1);
66 Node *in2 = add->in(2);
67
68 // Convert "1+x" into "x+1".
69 // Right is a constant; leave it
70 if( con_right ) return false;
71 // Left is a constant; move it right.
72 if( con_left ) {
73 add->swap_edges(1, 2);
74 return true;
75 }
187 addx->set_req(1, in(1));
188 addx->set_req(2, add2->in(1));
189 addx = phase->transform(addx);
190 set_req(1, addx);
191 set_req(2, a22);
192 progress = this;
193 PhaseIterGVN *igvn = phase->is_IterGVN();
194 if (add2->outcnt() == 0 && igvn) {
195 // add disconnected.
196 igvn->_worklist.push(add2);
197 }
198 }
199 }
200
201 return progress;
202 }
203
204 //------------------------------Value-----------------------------------------
205 // An add node sums it's two _in. If one input is an RSD, we must mixin
206 // the other input's symbols.
207 const Type *AddNode::Value( PhaseTransform *phase ) const {
208 // Either input is TOP ==> the result is TOP
209 const Type *t1 = phase->type( in(1) );
210 const Type *t2 = phase->type( in(2) );
211 if( t1 == Type::TOP ) return Type::TOP;
212 if( t2 == Type::TOP ) return Type::TOP;
213
214 // Either input is BOTTOM ==> the result is the local BOTTOM
215 const Type *bot = bottom_type();
216 if( (t1 == bot) || (t2 == bot) ||
217 (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )
218 return bot;
219
220 // Check for an addition involving the additive identity
221 const Type *tadd = add_of_identity( t1, t2 );
222 if( tadd ) return tadd;
223
224 return add_ring(t1,t2); // Local flavor of type addition
225 }
226
227 //------------------------------add_identity-----------------------------------
309 if( op1 == Op_URShiftI && op2 == Op_ConI &&
310 in1->in(2)->Opcode() == Op_ConI ) {
311 jint z = phase->type( in1->in(2) )->is_int()->get_con() & 0x1f; // only least significant 5 bits matter
312 jint y = phase->type( in2 )->is_int()->get_con();
313
314 if( z < 5 && -5 < y && y < 0 ) {
315 const Type *t_in11 = phase->type(in1->in(1));
316 if( t_in11 != Type::TOP && (t_in11->is_int()->_lo >= -(y << z)) ) {
317 Node *a = phase->transform( new AddINode( in1->in(1), phase->intcon(y<<z) ) );
318 return new URShiftINode( a, in1->in(2) );
319 }
320 }
321 }
322
323 return AddNode::Ideal(phase, can_reshape);
324 }
325
326
327 //------------------------------Identity---------------------------------------
328 // Fold (x-y)+y OR y+(x-y) into x
329 Node *AddINode::Identity( PhaseTransform *phase ) {
330 if( in(1)->Opcode() == Op_SubI && phase->eqv(in(1)->in(2),in(2)) ) {
331 return in(1)->in(1);
332 }
333 else if( in(2)->Opcode() == Op_SubI && phase->eqv(in(2)->in(2),in(1)) ) {
334 return in(2)->in(1);
335 }
336 return AddNode::Identity(phase);
337 }
338
339
340 //------------------------------add_ring---------------------------------------
341 // Supplied function returns the sum of the inputs. Guaranteed never
342 // to be passed a TOP or BOTTOM type, these are filtered out by
343 // pre-check.
344 const Type *AddINode::add_ring( const Type *t0, const Type *t1 ) const {
345 const TypeInt *r0 = t0->is_int(); // Handy access
346 const TypeInt *r1 = t1->is_int();
347 int lo = java_add(r0->_lo, r1->_lo);
348 int hi = java_add(r0->_hi, r1->_hi);
349 if( !(r0->is_con() && r1->is_con()) ) {
426 // Convert "(0-y)+x" into "(x-y)"
427 if( op1 == Op_SubL && phase->type(in1->in(1)) == TypeInt::ZERO )
428 return new SubLNode( in2, in1->in(2) );
429
430 // Convert "X+X+X+X+X...+X+Y" into "k*X+Y" or really convert "X+(X+Y)"
431 // into "(X<<1)+Y" and let shift-folding happen.
432 if( op2 == Op_AddL &&
433 in2->in(1) == in1 &&
434 op1 != Op_ConL &&
435 0 ) {
436 Node *shift = phase->transform(new LShiftLNode(in1,phase->intcon(1)));
437 return new AddLNode(shift,in2->in(2));
438 }
439
440 return AddNode::Ideal(phase, can_reshape);
441 }
442
443
444 //------------------------------Identity---------------------------------------
445 // Fold (x-y)+y OR y+(x-y) into x
446 Node *AddLNode::Identity( PhaseTransform *phase ) {
447 if( in(1)->Opcode() == Op_SubL && phase->eqv(in(1)->in(2),in(2)) ) {
448 return in(1)->in(1);
449 }
450 else if( in(2)->Opcode() == Op_SubL && phase->eqv(in(2)->in(2),in(1)) ) {
451 return in(2)->in(1);
452 }
453 return AddNode::Identity(phase);
454 }
455
456
457 //------------------------------add_ring---------------------------------------
458 // Supplied function returns the sum of the inputs. Guaranteed never
459 // to be passed a TOP or BOTTOM type, these are filtered out by
460 // pre-check.
461 const Type *AddLNode::add_ring( const Type *t0, const Type *t1 ) const {
462 const TypeLong *r0 = t0->is_long(); // Handy access
463 const TypeLong *r1 = t1->is_long();
464 jlong lo = java_add(r0->_lo, r1->_lo);
465 jlong hi = java_add(r0->_hi, r1->_hi);
466 if( !(r0->is_con() && r1->is_con()) ) {
544 // We must be adding 2 double constants.
545 return TypeD::make( t0->getd() + t1->getd() );
546 }
547
548 //------------------------------Ideal------------------------------------------
549 Node *AddDNode::Ideal(PhaseGVN *phase, bool can_reshape) {
550 if( IdealizedNumerics && !phase->C->method()->is_strict() ) {
551 return AddNode::Ideal(phase, can_reshape); // commutative and associative transforms
552 }
553
554 // Floating point additions are not associative because of boundary conditions (infinity)
555 return commute(this,
556 phase->type( in(1) )->singleton(),
557 phase->type( in(2) )->singleton() ) ? this : NULL;
558 }
559
560
561 //=============================================================================
562 //------------------------------Identity---------------------------------------
563 // If one input is a constant 0, return the other input.
564 Node *AddPNode::Identity( PhaseTransform *phase ) {
565 return ( phase->type( in(Offset) )->higher_equal( TypeX_ZERO ) ) ? in(Address) : this;
566 }
567
568 //------------------------------Idealize---------------------------------------
569 Node *AddPNode::Ideal(PhaseGVN *phase, bool can_reshape) {
570 // Bail out if dead inputs
571 if( phase->type( in(Address) ) == Type::TOP ) return NULL;
572
573 // If the left input is an add of a constant, flatten the expression tree.
574 const Node *n = in(Address);
575 if (n->is_AddP() && n->in(Base) == in(Base)) {
576 const AddPNode *addp = n->as_AddP(); // Left input is an AddP
577 assert( !addp->in(Address)->is_AddP() ||
578 addp->in(Address)->as_AddP() != addp,
579 "dead loop in AddPNode::Ideal" );
580 // Type of left input's right input
581 const Type *t = phase->type( addp->in(Offset) );
582 if( t == Type::TOP ) return NULL;
583 const TypeX *t12 = t->is_intptr_t();
584 if( t12->is_con() ) { // Left input is an add of a constant?
642
643 //------------------------------bottom_type------------------------------------
644 // Bottom-type is the pointer-type with unknown offset.
645 const Type *AddPNode::bottom_type() const {
646 if (in(Address) == NULL) return TypePtr::BOTTOM;
647 const TypePtr *tp = in(Address)->bottom_type()->isa_ptr();
648 if( !tp ) return Type::TOP; // TOP input means TOP output
649 assert( in(Offset)->Opcode() != Op_ConP, "" );
650 const Type *t = in(Offset)->bottom_type();
651 if( t == Type::TOP )
652 return tp->add_offset(Type::OffsetTop);
653 const TypeX *tx = t->is_intptr_t();
654 intptr_t txoffset = Type::OffsetBot;
655 if (tx->is_con()) { // Left input is an add of a constant?
656 txoffset = tx->get_con();
657 }
658 return tp->add_offset(txoffset);
659 }
660
661 //------------------------------Value------------------------------------------
662 const Type *AddPNode::Value( PhaseTransform *phase ) const {
663 // Either input is TOP ==> the result is TOP
664 const Type *t1 = phase->type( in(Address) );
665 const Type *t2 = phase->type( in(Offset) );
666 if( t1 == Type::TOP ) return Type::TOP;
667 if( t2 == Type::TOP ) return Type::TOP;
668
669 // Left input is a pointer
670 const TypePtr *p1 = t1->isa_ptr();
671 // Right input is an int
672 const TypeX *p2 = t2->is_intptr_t();
673 // Add 'em
674 intptr_t p2offset = Type::OffsetBot;
675 if (p2->is_con()) { // Left input is an add of a constant?
676 p2offset = p2->get_con();
677 }
678 return p1->add_offset(p2offset);
679 }
680
681 //------------------------Ideal_base_and_offset--------------------------------
682 // Split an oop pointer into a base and offset.
716 if (count == length) {
717 // give up
718 return -1;
719 }
720 addr = addr->in(AddPNode::Address);
721 }
722 if (addr != base) {
723 return -1;
724 }
725 return count;
726 }
727
728 //------------------------------match_edge-------------------------------------
729 // Do we Match on this edge index or not? Do not match base pointer edge
730 uint AddPNode::match_edge(uint idx) const {
731 return idx > Base;
732 }
733
734 //=============================================================================
735 //------------------------------Identity---------------------------------------
736 Node *OrINode::Identity( PhaseTransform *phase ) {
737 // x | x => x
738 if (phase->eqv(in(1), in(2))) {
739 return in(1);
740 }
741
742 return AddNode::Identity(phase);
743 }
744
745 //------------------------------add_ring---------------------------------------
746 // Supplied function returns the sum of the inputs IN THE CURRENT RING. For
747 // the logical operations the ring's ADD is really a logical OR function.
748 // This also type-checks the inputs for sanity. Guaranteed never to
749 // be passed a TOP or BOTTOM type, these are filtered out by pre-check.
750 const Type *OrINode::add_ring( const Type *t0, const Type *t1 ) const {
751 const TypeInt *r0 = t0->is_int(); // Handy access
752 const TypeInt *r1 = t1->is_int();
753
754 // If both args are bool, can figure out better types
755 if ( r0 == TypeInt::BOOL ) {
756 if ( r1 == TypeInt::ONE) {
757 return TypeInt::ONE;
758 } else if ( r1 == TypeInt::BOOL ) {
759 return TypeInt::BOOL;
760 }
761 } else if ( r0 == TypeInt::ONE ) {
762 if ( r1 == TypeInt::BOOL ) {
763 return TypeInt::ONE;
764 }
765 }
766
767 // If either input is not a constant, just return all integers.
768 if( !r0->is_con() || !r1->is_con() )
769 return TypeInt::INT; // Any integer, but still no symbols.
770
771 // Otherwise just OR them bits.
772 return TypeInt::make( r0->get_con() | r1->get_con() );
773 }
774
775 //=============================================================================
776 //------------------------------Identity---------------------------------------
777 Node *OrLNode::Identity( PhaseTransform *phase ) {
778 // x | x => x
779 if (phase->eqv(in(1), in(2))) {
780 return in(1);
781 }
782
783 return AddNode::Identity(phase);
784 }
785
786 //------------------------------add_ring---------------------------------------
787 const Type *OrLNode::add_ring( const Type *t0, const Type *t1 ) const {
788 const TypeLong *r0 = t0->is_long(); // Handy access
789 const TypeLong *r1 = t1->is_long();
790
791 // If either input is not a constant, just return all integers.
792 if( !r0->is_con() || !r1->is_con() )
793 return TypeLong::LONG; // Any integer, but still no symbols.
794
795 // Otherwise just OR them bits.
796 return TypeLong::make( r0->get_con() | r1->get_con() );
797 }
|
35
36 // Portions of code courtesy of Clifford Click
37
38 // Classic Add functionality. This covers all the usual 'add' behaviors for
39 // an algebraic ring. Add-integer, add-float, add-double, and binary-or are
40 // all inherited from this class. The various identity values are supplied
41 // by virtual functions.
42
43
44 //=============================================================================
45 //------------------------------hash-------------------------------------------
46 // Hash function over AddNodes. Needs to be commutative; i.e., I swap
47 // (commute) inputs to AddNodes willy-nilly so the hash function must return
48 // the same value in the presence of edge swapping.
49 uint AddNode::hash() const {
50 return (uintptr_t)in(1) + (uintptr_t)in(2) + Opcode();
51 }
52
53 //------------------------------Identity---------------------------------------
54 // If either input is a constant 0, return the other input.
55 Node* AddNode::Identity(PhaseGVN* phase) {
56 const Type *zero = add_id(); // The additive identity
57 if( phase->type( in(1) )->higher_equal( zero ) ) return in(2);
58 if( phase->type( in(2) )->higher_equal( zero ) ) return in(1);
59 return this;
60 }
61
62 //------------------------------commute----------------------------------------
63 // Commute operands to move loads and constants to the right.
64 static bool commute( Node *add, int con_left, int con_right ) {
65 Node *in1 = add->in(1);
66 Node *in2 = add->in(2);
67
68 // Convert "1+x" into "x+1".
69 // Right is a constant; leave it
70 if( con_right ) return false;
71 // Left is a constant; move it right.
72 if( con_left ) {
73 add->swap_edges(1, 2);
74 return true;
75 }
187 addx->set_req(1, in(1));
188 addx->set_req(2, add2->in(1));
189 addx = phase->transform(addx);
190 set_req(1, addx);
191 set_req(2, a22);
192 progress = this;
193 PhaseIterGVN *igvn = phase->is_IterGVN();
194 if (add2->outcnt() == 0 && igvn) {
195 // add disconnected.
196 igvn->_worklist.push(add2);
197 }
198 }
199 }
200
201 return progress;
202 }
203
204 //------------------------------Value-----------------------------------------
205 // An add node sums it's two _in. If one input is an RSD, we must mixin
206 // the other input's symbols.
207 const Type* AddNode::Value(PhaseGVN* phase) const {
208 // Either input is TOP ==> the result is TOP
209 const Type *t1 = phase->type( in(1) );
210 const Type *t2 = phase->type( in(2) );
211 if( t1 == Type::TOP ) return Type::TOP;
212 if( t2 == Type::TOP ) return Type::TOP;
213
214 // Either input is BOTTOM ==> the result is the local BOTTOM
215 const Type *bot = bottom_type();
216 if( (t1 == bot) || (t2 == bot) ||
217 (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )
218 return bot;
219
220 // Check for an addition involving the additive identity
221 const Type *tadd = add_of_identity( t1, t2 );
222 if( tadd ) return tadd;
223
224 return add_ring(t1,t2); // Local flavor of type addition
225 }
226
227 //------------------------------add_identity-----------------------------------
309 if( op1 == Op_URShiftI && op2 == Op_ConI &&
310 in1->in(2)->Opcode() == Op_ConI ) {
311 jint z = phase->type( in1->in(2) )->is_int()->get_con() & 0x1f; // only least significant 5 bits matter
312 jint y = phase->type( in2 )->is_int()->get_con();
313
314 if( z < 5 && -5 < y && y < 0 ) {
315 const Type *t_in11 = phase->type(in1->in(1));
316 if( t_in11 != Type::TOP && (t_in11->is_int()->_lo >= -(y << z)) ) {
317 Node *a = phase->transform( new AddINode( in1->in(1), phase->intcon(y<<z) ) );
318 return new URShiftINode( a, in1->in(2) );
319 }
320 }
321 }
322
323 return AddNode::Ideal(phase, can_reshape);
324 }
325
326
327 //------------------------------Identity---------------------------------------
328 // Fold (x-y)+y OR y+(x-y) into x
329 Node* AddINode::Identity(PhaseGVN* phase) {
330 if( in(1)->Opcode() == Op_SubI && phase->eqv(in(1)->in(2),in(2)) ) {
331 return in(1)->in(1);
332 }
333 else if( in(2)->Opcode() == Op_SubI && phase->eqv(in(2)->in(2),in(1)) ) {
334 return in(2)->in(1);
335 }
336 return AddNode::Identity(phase);
337 }
338
339
340 //------------------------------add_ring---------------------------------------
341 // Supplied function returns the sum of the inputs. Guaranteed never
342 // to be passed a TOP or BOTTOM type, these are filtered out by
343 // pre-check.
344 const Type *AddINode::add_ring( const Type *t0, const Type *t1 ) const {
345 const TypeInt *r0 = t0->is_int(); // Handy access
346 const TypeInt *r1 = t1->is_int();
347 int lo = java_add(r0->_lo, r1->_lo);
348 int hi = java_add(r0->_hi, r1->_hi);
349 if( !(r0->is_con() && r1->is_con()) ) {
426 // Convert "(0-y)+x" into "(x-y)"
427 if( op1 == Op_SubL && phase->type(in1->in(1)) == TypeInt::ZERO )
428 return new SubLNode( in2, in1->in(2) );
429
430 // Convert "X+X+X+X+X...+X+Y" into "k*X+Y" or really convert "X+(X+Y)"
431 // into "(X<<1)+Y" and let shift-folding happen.
432 if( op2 == Op_AddL &&
433 in2->in(1) == in1 &&
434 op1 != Op_ConL &&
435 0 ) {
436 Node *shift = phase->transform(new LShiftLNode(in1,phase->intcon(1)));
437 return new AddLNode(shift,in2->in(2));
438 }
439
440 return AddNode::Ideal(phase, can_reshape);
441 }
442
443
444 //------------------------------Identity---------------------------------------
445 // Fold (x-y)+y OR y+(x-y) into x
446 Node* AddLNode::Identity(PhaseGVN* phase) {
447 if( in(1)->Opcode() == Op_SubL && phase->eqv(in(1)->in(2),in(2)) ) {
448 return in(1)->in(1);
449 }
450 else if( in(2)->Opcode() == Op_SubL && phase->eqv(in(2)->in(2),in(1)) ) {
451 return in(2)->in(1);
452 }
453 return AddNode::Identity(phase);
454 }
455
456
457 //------------------------------add_ring---------------------------------------
458 // Supplied function returns the sum of the inputs. Guaranteed never
459 // to be passed a TOP or BOTTOM type, these are filtered out by
460 // pre-check.
461 const Type *AddLNode::add_ring( const Type *t0, const Type *t1 ) const {
462 const TypeLong *r0 = t0->is_long(); // Handy access
463 const TypeLong *r1 = t1->is_long();
464 jlong lo = java_add(r0->_lo, r1->_lo);
465 jlong hi = java_add(r0->_hi, r1->_hi);
466 if( !(r0->is_con() && r1->is_con()) ) {
544 // We must be adding 2 double constants.
545 return TypeD::make( t0->getd() + t1->getd() );
546 }
547
548 //------------------------------Ideal------------------------------------------
549 Node *AddDNode::Ideal(PhaseGVN *phase, bool can_reshape) {
550 if( IdealizedNumerics && !phase->C->method()->is_strict() ) {
551 return AddNode::Ideal(phase, can_reshape); // commutative and associative transforms
552 }
553
554 // Floating point additions are not associative because of boundary conditions (infinity)
555 return commute(this,
556 phase->type( in(1) )->singleton(),
557 phase->type( in(2) )->singleton() ) ? this : NULL;
558 }
559
560
561 //=============================================================================
562 //------------------------------Identity---------------------------------------
563 // If one input is a constant 0, return the other input.
564 Node* AddPNode::Identity(PhaseGVN* phase) {
565 return ( phase->type( in(Offset) )->higher_equal( TypeX_ZERO ) ) ? in(Address) : this;
566 }
567
568 //------------------------------Idealize---------------------------------------
569 Node *AddPNode::Ideal(PhaseGVN *phase, bool can_reshape) {
570 // Bail out if dead inputs
571 if( phase->type( in(Address) ) == Type::TOP ) return NULL;
572
573 // If the left input is an add of a constant, flatten the expression tree.
574 const Node *n = in(Address);
575 if (n->is_AddP() && n->in(Base) == in(Base)) {
576 const AddPNode *addp = n->as_AddP(); // Left input is an AddP
577 assert( !addp->in(Address)->is_AddP() ||
578 addp->in(Address)->as_AddP() != addp,
579 "dead loop in AddPNode::Ideal" );
580 // Type of left input's right input
581 const Type *t = phase->type( addp->in(Offset) );
582 if( t == Type::TOP ) return NULL;
583 const TypeX *t12 = t->is_intptr_t();
584 if( t12->is_con() ) { // Left input is an add of a constant?
642
643 //------------------------------bottom_type------------------------------------
644 // Bottom-type is the pointer-type with unknown offset.
645 const Type *AddPNode::bottom_type() const {
646 if (in(Address) == NULL) return TypePtr::BOTTOM;
647 const TypePtr *tp = in(Address)->bottom_type()->isa_ptr();
648 if( !tp ) return Type::TOP; // TOP input means TOP output
649 assert( in(Offset)->Opcode() != Op_ConP, "" );
650 const Type *t = in(Offset)->bottom_type();
651 if( t == Type::TOP )
652 return tp->add_offset(Type::OffsetTop);
653 const TypeX *tx = t->is_intptr_t();
654 intptr_t txoffset = Type::OffsetBot;
655 if (tx->is_con()) { // Left input is an add of a constant?
656 txoffset = tx->get_con();
657 }
658 return tp->add_offset(txoffset);
659 }
660
661 //------------------------------Value------------------------------------------
662 const Type* AddPNode::Value(PhaseGVN* phase) const {
663 // Either input is TOP ==> the result is TOP
664 const Type *t1 = phase->type( in(Address) );
665 const Type *t2 = phase->type( in(Offset) );
666 if( t1 == Type::TOP ) return Type::TOP;
667 if( t2 == Type::TOP ) return Type::TOP;
668
669 // Left input is a pointer
670 const TypePtr *p1 = t1->isa_ptr();
671 // Right input is an int
672 const TypeX *p2 = t2->is_intptr_t();
673 // Add 'em
674 intptr_t p2offset = Type::OffsetBot;
675 if (p2->is_con()) { // Left input is an add of a constant?
676 p2offset = p2->get_con();
677 }
678 return p1->add_offset(p2offset);
679 }
680
681 //------------------------Ideal_base_and_offset--------------------------------
682 // Split an oop pointer into a base and offset.
716 if (count == length) {
717 // give up
718 return -1;
719 }
720 addr = addr->in(AddPNode::Address);
721 }
722 if (addr != base) {
723 return -1;
724 }
725 return count;
726 }
727
728 //------------------------------match_edge-------------------------------------
729 // Do we Match on this edge index or not? Do not match base pointer edge
730 uint AddPNode::match_edge(uint idx) const {
731 return idx > Base;
732 }
733
734 //=============================================================================
735 //------------------------------Identity---------------------------------------
736 Node* OrINode::Identity(PhaseGVN* phase) {
737 // x | x => x
738 if (phase->eqv(in(1), in(2))) {
739 return in(1);
740 }
741
742 return AddNode::Identity(phase);
743 }
744
745 //------------------------------add_ring---------------------------------------
746 // Supplied function returns the sum of the inputs IN THE CURRENT RING. For
747 // the logical operations the ring's ADD is really a logical OR function.
748 // This also type-checks the inputs for sanity. Guaranteed never to
749 // be passed a TOP or BOTTOM type, these are filtered out by pre-check.
750 const Type *OrINode::add_ring( const Type *t0, const Type *t1 ) const {
751 const TypeInt *r0 = t0->is_int(); // Handy access
752 const TypeInt *r1 = t1->is_int();
753
754 // If both args are bool, can figure out better types
755 if ( r0 == TypeInt::BOOL ) {
756 if ( r1 == TypeInt::ONE) {
757 return TypeInt::ONE;
758 } else if ( r1 == TypeInt::BOOL ) {
759 return TypeInt::BOOL;
760 }
761 } else if ( r0 == TypeInt::ONE ) {
762 if ( r1 == TypeInt::BOOL ) {
763 return TypeInt::ONE;
764 }
765 }
766
767 // If either input is not a constant, just return all integers.
768 if( !r0->is_con() || !r1->is_con() )
769 return TypeInt::INT; // Any integer, but still no symbols.
770
771 // Otherwise just OR them bits.
772 return TypeInt::make( r0->get_con() | r1->get_con() );
773 }
774
775 //=============================================================================
776 //------------------------------Identity---------------------------------------
777 Node* OrLNode::Identity(PhaseGVN* phase) {
778 // x | x => x
779 if (phase->eqv(in(1), in(2))) {
780 return in(1);
781 }
782
783 return AddNode::Identity(phase);
784 }
785
786 //------------------------------add_ring---------------------------------------
787 const Type *OrLNode::add_ring( const Type *t0, const Type *t1 ) const {
788 const TypeLong *r0 = t0->is_long(); // Handy access
789 const TypeLong *r1 = t1->is_long();
790
791 // If either input is not a constant, just return all integers.
792 if( !r0->is_con() || !r1->is_con() )
793 return TypeLong::LONG; // Any integer, but still no symbols.
794
795 // Otherwise just OR them bits.
796 return TypeLong::make( r0->get_con() | r1->get_con() );
797 }
|