RFR(S): 8213419: C2 may hang in MulLNode::Ideal()/MulINode::Ideal() with gcc 8.2.1

Roland Westrelin rwestrel at redhat.com
Tue Nov 6 14:16:07 UTC 2018


http://cr.openjdk.java.net/~roland/8213419/webrev.00/

Multiplications by constant Integer.MIN_VALUE or Long.MIN_VALUE cause C2
to hang in MulLNode::Ideal()/MulINode::Ideal() when hotspot is compiled
with gcc 8.2.1.

The hang itself happens in inlined function: 

// Returns largest i such that 2^i <= x. 
// If x < 0, the function returns 31 on a 32-bit machine and 63 on a 64-bit machine. 
// If x == 0, the function returns -1. 
inline int log2_intptr(intptr_t x) { 
  int i = -1; 
  uintptr_t p = 1; 
  while (p != 0 && p <= (uintptr_t)x) { 
    // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x) 
    i++; p *= 2; 
  } 
  // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1)) 
  // If p = 0, overflow has occurred and i = 31 or i = 63 (depending on the machine word size). 
  return i; 
} 

Looking at the assembly code p != 0 is optimized out. 

   0x00007f6494aae685 <+1157>: mov $0xffffffff,%ecx 
   0x00007f6494aae68a <+1162>: mov (%rax),%rdi 
   0x00007f6494aae68d <+1165>: mov $0x1,%eax 
   0x00007f6494aae692 <+1170>: nopw 0x0(%rax,%rax,1) 
   0x00007f6494aae698 <+1176>: add %rax,%rax 
   0x00007f6494aae69b <+1179>: add $0x1,%ecx 
   0x00007f6494aae69e <+1182>: cmp %r14,%rax 
   0x00007f6494aae6a1 <+1185>: jbe 0x7f6494aae698 <MulINode::Ideal(PhaseGVN*, bool)+1176> 

That call is preceded by: 

if( con < 0 ) { 
  con = -con; 
} 

which is undefined behavior for INT_MIN so the compiler is free to
assume con != INT_MIN and then optimizing the p != 0 test is legal.

The fix uses some utiliy functions that were added for aarch64.

Roland.


More information about the hotspot-compiler-dev mailing list