268
269 //=============================================================================
270 //------------------------------Ideal------------------------------------------
271 // Check for power-of-2 multiply, then try the regular MulNode::Ideal
272 Node *MulLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
273 // Swap constant to right
274 jlong con;
275 if ((con = in(1)->find_long_con(0)) != 0) {
276 swap_edges(1, 2);
277 // Finish rest of method to use info in 'con'
278 } else if ((con = in(2)->find_long_con(0)) == 0) {
279 return MulNode::Ideal(phase, can_reshape);
280 }
281
282 // Now we have a constant Node on the right and the constant in con
283 if (con == CONST64(0)) return NULL; // By zero is handled by Value call
284 if (con == CONST64(1)) return NULL; // By one is handled by Identity call
285
286 // Check for negative constant; if so negate the final result
287 bool sign_flip = false;
288 unsigned long abs_con = uabs(con);
289 if (abs_con != (unsigned long)con) {
290 sign_flip = true;
291 }
292
293 // Get low bit; check for being the only bit
294 Node *res = NULL;
295 unsigned long bit1 = abs_con & (0-abs_con); // Extract low bit
296 if (bit1 == abs_con) { // Found a power of 2?
297 res = new (phase->C) LShiftLNode(in(1), phase->intcon(log2_long(bit1)));
298 } else {
299
300 // Check for constant with 2 bits set
301 unsigned long bit2 = abs_con-bit1;
302 bit2 = bit2 & (0-bit2); // Extract 2nd bit
303 if (bit2 + bit1 == abs_con) { // Found all bits in con?
304 Node *n1 = phase->transform(new (phase->C) LShiftLNode(in(1), phase->intcon(log2_long(bit1))));
305 Node *n2 = phase->transform(new (phase->C) LShiftLNode(in(1), phase->intcon(log2_long(bit2))));
306 res = new (phase->C) AddLNode(n2, n1);
307
308 } else if (is_power_of_2_long(abs_con+1)) {
309 // Sleezy: power-of-2 -1. Next time be generic.
310 unsigned long temp = abs_con + 1;
311 Node *n1 = phase->transform( new (phase->C) LShiftLNode(in(1), phase->intcon(log2_long(temp))));
312 res = new (phase->C) SubLNode(n1, in(1));
313 } else {
314 return MulNode::Ideal(phase, can_reshape);
315 }
316 }
317
318 if (sign_flip) { // Need to negate result?
319 res = phase->transform(res);// Transform, before making the zero con
320 res = new (phase->C) SubLNode(phase->longcon(0),res);
321 }
322
323 return res; // Return final result
324 }
325
326 //------------------------------mul_ring---------------------------------------
327 // Compute the product type of two integer ranges into this node.
328 const Type *MulLNode::mul_ring(const Type *t0, const Type *t1) const {
329 const TypeLong *r0 = t0->is_long(); // Handy access
330 const TypeLong *r1 = t1->is_long();
|
268
269 //=============================================================================
270 //------------------------------Ideal------------------------------------------
271 // Check for power-of-2 multiply, then try the regular MulNode::Ideal
272 Node *MulLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
273 // Swap constant to right
274 jlong con;
275 if ((con = in(1)->find_long_con(0)) != 0) {
276 swap_edges(1, 2);
277 // Finish rest of method to use info in 'con'
278 } else if ((con = in(2)->find_long_con(0)) == 0) {
279 return MulNode::Ideal(phase, can_reshape);
280 }
281
282 // Now we have a constant Node on the right and the constant in con
283 if (con == CONST64(0)) return NULL; // By zero is handled by Value call
284 if (con == CONST64(1)) return NULL; // By one is handled by Identity call
285
286 // Check for negative constant; if so negate the final result
287 bool sign_flip = false;
288 julong abs_con = uabs(con);
289 if (abs_con != (julong)con) {
290 sign_flip = true;
291 }
292
293 // Get low bit; check for being the only bit
294 Node *res = NULL;
295 julong bit1 = abs_con & (0-abs_con); // Extract low bit
296 if (bit1 == abs_con) { // Found a power of 2?
297 res = new (phase->C) LShiftLNode(in(1), phase->intcon(log2_long(bit1)));
298 } else {
299
300 // Check for constant with 2 bits set
301 julong bit2 = abs_con-bit1;
302 bit2 = bit2 & (0-bit2); // Extract 2nd bit
303 if (bit2 + bit1 == abs_con) { // Found all bits in con?
304 Node *n1 = phase->transform(new (phase->C) LShiftLNode(in(1), phase->intcon(log2_long(bit1))));
305 Node *n2 = phase->transform(new (phase->C) LShiftLNode(in(1), phase->intcon(log2_long(bit2))));
306 res = new (phase->C) AddLNode(n2, n1);
307
308 } else if (is_power_of_2_long(abs_con+1)) {
309 // Sleezy: power-of-2 -1. Next time be generic.
310 julong temp = abs_con + 1;
311 Node *n1 = phase->transform( new (phase->C) LShiftLNode(in(1), phase->intcon(log2_long(temp))));
312 res = new (phase->C) SubLNode(n1, in(1));
313 } else {
314 return MulNode::Ideal(phase, can_reshape);
315 }
316 }
317
318 if (sign_flip) { // Need to negate result?
319 res = phase->transform(res);// Transform, before making the zero con
320 res = new (phase->C) SubLNode(phase->longcon(0),res);
321 }
322
323 return res; // Return final result
324 }
325
326 //------------------------------mul_ring---------------------------------------
327 // Compute the product type of two integer ranges into this node.
328 const Type *MulLNode::mul_ring(const Type *t0, const Type *t1) const {
329 const TypeLong *r0 = t0->is_long(); // Handy access
330 const TypeLong *r1 = t1->is_long();
|