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

multiply -> shift reduction fails with complex control flow

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 9, 10
    • hotspot

      This was found during the course of Compact String work. This manifests in Integer.toString and Long.toString changes there.
      It boils down to this. When there is a strength reduction opportunity to reduce multiplication to shift, it fails when we have a
      non-trivial control flow preceding the argument. The breakage would only happen if the alternative branch is not folded into
      uncommon trap.

          int idx;
          boolean flag;

          @Benchmark
          public void mult() {
              doMult();
          }

          @CompilerControl(CompilerControl.Mode.DONT_INLINE)
          private int doMult() {
              int mult = flag ? 1 : 2;
              return idx * mult;
          }

      Complete benchmark, some performance data and generated code:
        http://cr.openjdk.java.net/~shade/8130273/StrengthReduction.java

      Runnable JAR:
        http://cr.openjdk.java.net/~shade/8130273/benchmarks.jar

            Unassigned Unassigned
            shade Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: