Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8213419

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

XMLWordPrintable

    • b21

        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.

              roland Roland Westrelin
              roland Roland Westrelin
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: