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

Make Min/MaxINode::Ideal transformation symmetric

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 20
    • hotspot

      Consider

      https://github.com/openjdk/jdk/blob/master/test/hotspot/jtreg/compiler/c2/irTests/MaxMinINodeIdealizationTests.java

      Existing tests for the optimization check only one order of nodes, e.g.

          // Transform max(x + c0, max(y + c1, z)) to max(add(x, c2), z) if x == y, where c2 = MAX2(c0, c1).
          // c0,c1,c2 are constants. x,y,z can be any valid c2 nodes. In this example, x and y are
          // RShiftI nodes and z is a ConI.
          @Test
          @IR(counts = {IRNode.MAX_I, "1",
                        IRNode.ADD , "1",
                       })
          public int testMax1(int i) {
              return Math.max(((i >> 1) + 100), Math.max(((i >> 1) + 150), 200));
          }

      If Max inputs are swapped, the optimization fails, e.g.

          @Test
          @IR(counts = {IRNode.MAX_I, "1",
                        IRNode.ADD , "1",
                       })
          public int testMax1i(int i) {
              return Math.max(((i >> 1) + 100), Math.max(200, ((i >> 1) + 150)));
          }

      That happens because Ideal() looks for Add only as a first input but that is not guaranteed.

        // Get left input & constant
        Node* x = l;
        jint x_off = 0;
        if (x->Opcode() == Op_AddI...

            Unassigned Unassigned
            dchuyko Dmitry Chuyko
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: