71 */
72
73
74 //------------------------------Ideal------------------------------------------
75 // Return a node which is more "ideal" than the current node.
76 // Move constants to the right.
77 Node *CMoveNode::Ideal(PhaseGVN *phase, bool can_reshape) {
78 if( in(0) && remove_dead_region(phase, can_reshape) ) return this;
79 // Don't bother trying to transform a dead node
80 if( in(0) && in(0)->is_top() ) return NULL;
81 assert( !phase->eqv(in(Condition), this) &&
82 !phase->eqv(in(IfFalse), this) &&
83 !phase->eqv(in(IfTrue), this), "dead loop in CMoveNode::Ideal" );
84 if( phase->type(in(Condition)) == Type::TOP )
85 return NULL; // return NULL when Condition is dead
86
87 if( in(IfFalse)->is_Con() && !in(IfTrue)->is_Con() ) {
88 if( in(Condition)->is_Bool() ) {
89 BoolNode* b = in(Condition)->as_Bool();
90 BoolNode* b2 = b->negate(phase);
91 return make( phase->C, in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type );
92 }
93 }
94 return NULL;
95 }
96
97 //------------------------------is_cmove_id------------------------------------
98 // Helper function to check for CMOVE identity. Shared with PhiNode::Identity
99 Node *CMoveNode::is_cmove_id( PhaseTransform *phase, Node *cmp, Node *t, Node *f, BoolNode *b ) {
100 // Check for Cmp'ing and CMove'ing same values
101 if( (phase->eqv(cmp->in(1),f) &&
102 phase->eqv(cmp->in(2),t)) ||
103 // Swapped Cmp is OK
104 (phase->eqv(cmp->in(2),f) &&
105 phase->eqv(cmp->in(1),t)) ) {
106 // Give up this identity check for floating points because it may choose incorrect
107 // value around 0.0 and -0.0
108 if ( cmp->Opcode()==Op_CmpF || cmp->Opcode()==Op_CmpD )
109 return NULL;
110 // Check for "(t==f)?t:f;" and replace with "f"
111 if( b->_test._test == BoolTest::eq )
141 if( cmp->is_Cmp() ) {
142 Node *id = is_cmove_id( phase, cmp, in(IfTrue), in(IfFalse), b );
143 if( id ) return id;
144 }
145 }
146
147 return this;
148 }
149
150 //------------------------------Value------------------------------------------
151 // Result is the meet of inputs
152 const Type *CMoveNode::Value( PhaseTransform *phase ) const {
153 if( phase->type(in(Condition)) == Type::TOP )
154 return Type::TOP;
155 return phase->type(in(IfFalse))->meet_speculative(phase->type(in(IfTrue)));
156 }
157
158 //------------------------------make-------------------------------------------
159 // Make a correctly-flavored CMove. Since _type is directly determined
160 // from the inputs we do not need to specify it here.
161 CMoveNode *CMoveNode::make( Compile *C, Node *c, Node *bol, Node *left, Node *right, const Type *t ) {
162 switch( t->basic_type() ) {
163 case T_INT: return new CMoveINode( bol, left, right, t->is_int() );
164 case T_FLOAT: return new CMoveFNode( bol, left, right, t );
165 case T_DOUBLE: return new CMoveDNode( bol, left, right, t );
166 case T_LONG: return new CMoveLNode( bol, left, right, t->is_long() );
167 case T_OBJECT: return new CMovePNode( c, bol, left, right, t->is_oopptr() );
168 case T_ADDRESS: return new CMovePNode( c, bol, left, right, t->is_ptr() );
169 case T_NARROWOOP: return new CMoveNNode( c, bol, left, right, t );
170 default:
171 ShouldNotReachHere();
172 return NULL;
173 }
174 }
175
176 //=============================================================================
177 //------------------------------Ideal------------------------------------------
178 // Return a node which is more "ideal" than the current node.
179 // Check for conversions to boolean
180 Node *CMoveINode::Ideal(PhaseGVN *phase, bool can_reshape) {
181 // Try generic ideal's first
182 Node *x = CMoveNode::Ideal(phase, can_reshape);
183 if( x ) return x;
184
185 // If zero is on the left (false-case, no-move-case) it must mean another
186 // constant is on the right (otherwise the shared CMove::Ideal code would
187 // have moved the constant to the right). This situation is bad for Intel
188 // and a don't-care for Sparc. It's bad for Intel because the zero has to
189 // be manifested in a register with a XOR which kills flags, which are live
190 // on input to the CMoveI, leading to a situation which causes excessive
191 // spilling on Intel. For Sparc, if the zero in on the left the Sparc will
192 // zero a register via G0 and conditionally-move the other constant. If the
193 // zero is on the right, the Sparc will load the first constant with a
194 // 13-bit set-lo and conditionally move G0. See bug 4677505.
195 if( phase->type(in(IfFalse)) == TypeInt::ZERO && !(phase->type(in(IfTrue)) == TypeInt::ZERO) ) {
196 if( in(Condition)->is_Bool() ) {
197 BoolNode* b = in(Condition)->as_Bool();
198 BoolNode* b2 = b->negate(phase);
199 return make( phase->C, in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type );
200 }
201 }
202
203 // Now check for booleans
204 int flip = 0;
205
206 // Check for picking from zero/one
207 if( phase->type(in(IfFalse)) == TypeInt::ZERO && phase->type(in(IfTrue)) == TypeInt::ONE ) {
208 flip = 1 - flip;
209 } else if( phase->type(in(IfFalse)) == TypeInt::ONE && phase->type(in(IfTrue)) == TypeInt::ZERO ) {
210 } else return NULL;
211
212 // Check for eq/ne test
213 if( !in(1)->is_Bool() ) return NULL;
214 BoolNode *bol = in(1)->as_Bool();
215 if( bol->_test._test == BoolTest::eq ) {
216 } else if( bol->_test._test == BoolTest::ne ) {
217 flip = 1-flip;
218 } else return NULL;
219
|
71 */
72
73
74 //------------------------------Ideal------------------------------------------
75 // Return a node which is more "ideal" than the current node.
76 // Move constants to the right.
77 Node *CMoveNode::Ideal(PhaseGVN *phase, bool can_reshape) {
78 if( in(0) && remove_dead_region(phase, can_reshape) ) return this;
79 // Don't bother trying to transform a dead node
80 if( in(0) && in(0)->is_top() ) return NULL;
81 assert( !phase->eqv(in(Condition), this) &&
82 !phase->eqv(in(IfFalse), this) &&
83 !phase->eqv(in(IfTrue), this), "dead loop in CMoveNode::Ideal" );
84 if( phase->type(in(Condition)) == Type::TOP )
85 return NULL; // return NULL when Condition is dead
86
87 if( in(IfFalse)->is_Con() && !in(IfTrue)->is_Con() ) {
88 if( in(Condition)->is_Bool() ) {
89 BoolNode* b = in(Condition)->as_Bool();
90 BoolNode* b2 = b->negate(phase);
91 return make(in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type);
92 }
93 }
94 return NULL;
95 }
96
97 //------------------------------is_cmove_id------------------------------------
98 // Helper function to check for CMOVE identity. Shared with PhiNode::Identity
99 Node *CMoveNode::is_cmove_id( PhaseTransform *phase, Node *cmp, Node *t, Node *f, BoolNode *b ) {
100 // Check for Cmp'ing and CMove'ing same values
101 if( (phase->eqv(cmp->in(1),f) &&
102 phase->eqv(cmp->in(2),t)) ||
103 // Swapped Cmp is OK
104 (phase->eqv(cmp->in(2),f) &&
105 phase->eqv(cmp->in(1),t)) ) {
106 // Give up this identity check for floating points because it may choose incorrect
107 // value around 0.0 and -0.0
108 if ( cmp->Opcode()==Op_CmpF || cmp->Opcode()==Op_CmpD )
109 return NULL;
110 // Check for "(t==f)?t:f;" and replace with "f"
111 if( b->_test._test == BoolTest::eq )
141 if( cmp->is_Cmp() ) {
142 Node *id = is_cmove_id( phase, cmp, in(IfTrue), in(IfFalse), b );
143 if( id ) return id;
144 }
145 }
146
147 return this;
148 }
149
150 //------------------------------Value------------------------------------------
151 // Result is the meet of inputs
152 const Type *CMoveNode::Value( PhaseTransform *phase ) const {
153 if( phase->type(in(Condition)) == Type::TOP )
154 return Type::TOP;
155 return phase->type(in(IfFalse))->meet_speculative(phase->type(in(IfTrue)));
156 }
157
158 //------------------------------make-------------------------------------------
159 // Make a correctly-flavored CMove. Since _type is directly determined
160 // from the inputs we do not need to specify it here.
161 CMoveNode *CMoveNode::make(Node *c, Node *bol, Node *left, Node *right, const Type *t) {
162 switch( t->basic_type() ) {
163 case T_INT: return new CMoveINode( bol, left, right, t->is_int() );
164 case T_FLOAT: return new CMoveFNode( bol, left, right, t );
165 case T_DOUBLE: return new CMoveDNode( bol, left, right, t );
166 case T_LONG: return new CMoveLNode( bol, left, right, t->is_long() );
167 case T_OBJECT: return new CMovePNode( c, bol, left, right, t->is_oopptr() );
168 case T_ADDRESS: return new CMovePNode( c, bol, left, right, t->is_ptr() );
169 case T_NARROWOOP: return new CMoveNNode( c, bol, left, right, t );
170 default:
171 ShouldNotReachHere();
172 return NULL;
173 }
174 }
175
176 //=============================================================================
177 //------------------------------Ideal------------------------------------------
178 // Return a node which is more "ideal" than the current node.
179 // Check for conversions to boolean
180 Node *CMoveINode::Ideal(PhaseGVN *phase, bool can_reshape) {
181 // Try generic ideal's first
182 Node *x = CMoveNode::Ideal(phase, can_reshape);
183 if( x ) return x;
184
185 // If zero is on the left (false-case, no-move-case) it must mean another
186 // constant is on the right (otherwise the shared CMove::Ideal code would
187 // have moved the constant to the right). This situation is bad for Intel
188 // and a don't-care for Sparc. It's bad for Intel because the zero has to
189 // be manifested in a register with a XOR which kills flags, which are live
190 // on input to the CMoveI, leading to a situation which causes excessive
191 // spilling on Intel. For Sparc, if the zero in on the left the Sparc will
192 // zero a register via G0 and conditionally-move the other constant. If the
193 // zero is on the right, the Sparc will load the first constant with a
194 // 13-bit set-lo and conditionally move G0. See bug 4677505.
195 if( phase->type(in(IfFalse)) == TypeInt::ZERO && !(phase->type(in(IfTrue)) == TypeInt::ZERO) ) {
196 if( in(Condition)->is_Bool() ) {
197 BoolNode* b = in(Condition)->as_Bool();
198 BoolNode* b2 = b->negate(phase);
199 return make(in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type);
200 }
201 }
202
203 // Now check for booleans
204 int flip = 0;
205
206 // Check for picking from zero/one
207 if( phase->type(in(IfFalse)) == TypeInt::ZERO && phase->type(in(IfTrue)) == TypeInt::ONE ) {
208 flip = 1 - flip;
209 } else if( phase->type(in(IfFalse)) == TypeInt::ONE && phase->type(in(IfTrue)) == TypeInt::ZERO ) {
210 } else return NULL;
211
212 // Check for eq/ne test
213 if( !in(1)->is_Bool() ) return NULL;
214 BoolNode *bol = in(1)->as_Bool();
215 if( bol->_test._test == BoolTest::eq ) {
216 } else if( bol->_test._test == BoolTest::ne ) {
217 flip = 1-flip;
218 } else return NULL;
219
|