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

multiply -> shift reduction fails with complex control flow

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 9, 10
    • Fix Version/s: tbd
    • Component/s: hotspot
    • Labels:

      Description

      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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                shade Aleksey Shipilev
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: