Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-7560

the ICode optimizer doesn't DCE-away trivial branches

    Details

    • Type: Bug
    • Status: CLOSED
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:

      Description

      The discussion at https://github.com/scala/scala/pull/2620
      uncovered that the ICode-based optimizer's DCE doesn't eliminate a redundant conditional jump,
      where both branches lead to one and the same instruction.

      The example showing the above is test/files/jvm/bytecode-test-example/Foo_1.scala reproduced below:

      class Foo_1 {
        def foo(x: AnyRef): Int = {
          val bool = x == null
          if (x != null)
            1
          else
            0
        }
      }
      

      With GenASM and -optimise we get the two conditional jumps that bytecode-test-example.check expects:

        public foo(Ljava/lang/Object;)I
         L0
          ALOAD 1
          IFNONNULL L1
         L1
          ALOAD 1
          IFNONNULL L2
         L3
          ICONST_0
          GOTO L4
         L2
          ICONST_1
         L4
          IRETURN
         L5
          LOCALVARIABLE this LFoo_1; L0 L5 0
          LOCALVARIABLE x Ljava/lang/Object; L0 L5 1
          MAXSTACK = 1
          MAXLOCALS = 2
      

      including a useless

          ALOAD 1
          IFNONNULL L1
         L1
      

      (useless because, whether the conditional jump is taken or not, L1 is the target anyway)

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              magarcia Miguel Garcia
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: