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

suboptimal loop recognition in frontend - potential performance bug

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.4.0
    • hotspot
    • beta2
    • x86
    • windows_nt
    • Verified

      For the method p in the following Java program:

      class Test {

        static int p(int n) {
          int i;
          while (n > 0)
            if (n < 3)
              i = 0;
            else
             i = 1;
          return 0;
        }

        public static void main(String[] args) {
          System.out.println(p(10));
        }

      }

      the IR's loop recognition produces suboptimal loop enter/exit nodes:

      E:\gri\work>java_g -Xcomp -XX:CompileOnly=.p -XX:+PrintIR2 Test
      VM option 'CompileOnly=.p'
      VM option '+PrintIR2'
      IR before code generation
      B6 [0, 0] -> B7
      __bci__use__tid____instr____________________________________
      . 0 0 24 std entry B7

      B7 [0, 0] -> B8
      __bci__use__tid____instr____________________________________
      . 0 0 6 goto B8

      B8 [0, 0] -> B0
      __bci__use__tid____instr____________________________________
      . 0 0 31 enter loop[0]
      . 0 0 30 goto B0

      B3 [3, 5] -> B9 B2
      __bci__use__tid____instr____________________________________
        3 1 i12 L0
        4 1 i13 3
      . 5 0 14 if i12 >= i13 then B9 else B2

      B2 [8, 10] -> B0
      __bci__use__tid____instr____________________________________
        8 1 i15 0
      . 9 0 i16 L1 := i15
      . 10 0 17 goto B0

      B9 [13, 13] -> B1
      __bci__use__tid____instr____________________________________
      . 13 0 34 exit loop[0]
      . 13 0 33 goto B1

      B1 [13, 14] -> B8
      __bci__use__tid____instr____________________________________
        13 1 i18 1
      . 14 0 i19 L1 := i18
      . 14 0 20 goto B8

      B0 [15, 16] -> B3 B10
      __bci__use__tid____instr____________________________________
        15 1 i7 L0
        16 1 i8 0
      . 16 0 9 if i7 > i8 then B3 else B10

      B10 [19, 19] -> B4
      __bci__use__tid____instr____________________________________
      . 19 0 37 exit loop[0]
      . 19 0 36 goto B4

      B4 [19, 20]
      __bci__use__tid____instr____________________________________
        19 1 i10 0
      . 20 0 i11 ireturn i10>


      In basic block B9, the loop is exited before B1 is executed; only to enter the loop again via B8. The loop should not be left at all in this branch. This may result in suboptimal code for x86 (register usage) and thus a performance regression. Note that the generated code is still correct, though.

      robert.griesemer@Eng 2000-06-16
      (problem found by Peter Moessenboeck)

            never Tom Rodriguez
            rgriesemsunw Robert Griesemer (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: