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

C2: Excessively strict assert in PhaseIdealLoop::do_unroll

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • None
    • hotspot
    • None

      In PhaseIdealLoop::do_unroll the assert
      ```
      assert(trip_count > 0 && (julong)trip_count < (julong)max_juint/2, "sanity");
      ```
      is too strict and should be `<=` instead of `<` (at least).

      Reasoning:
      with:
      ```
          int new_stride_con = stride_con * 2;
          int stride_m = new_stride_con - (stride_con > 0 ? 1 : -1);
          jlong trip_count = (limit_con - init_con + stride_m)/new_stride_con;
      ```

      if
      limit_con = max_int = 2^31 - 1
      init_con = min_int + 1 = -2^31 + 1
      stride_con = 1
      then
      stride_m = 2
      and trip_count = (2^31 - 1 - (-2^31 + 1) + 1)/2 = (2^32 - 1) / 2 = 2^31 - 1/2 = max_juint/2 + 1/2 (so = max_juint/2 in integer arithmetic)

      This was observed on compiler/c2/Test6850611.java with -XX:+StressLoopPeeling

      It is not clear to me if the case `init_con = min_int = -2^31` is possible, but I don't see why not. That would lead to trip_count = 2^31 = max_juint/2 + 1. In this case, a correct assert would be
      ```
      assert(trip_count > 0 && (julong)trip_count <= (julong)max_juint/2 + 1, "sanity");
      ```

            mchevalier Marc Chevalier
            mchevalier Marc Chevalier
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: