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

C2 SuperWord: improve packing strategy (lookahead?)

XMLWordPrintable

      Currently, extend_pairset_with_more_pairs_by_following_use_and_def is greedy.

      This means that we can get inputs swapped, and then the inputs further up cannot be vectorized.

      In the literature, there are algorithms that try to do some "look-ahead", to generate more optimal packing.

      Related issue: JDK-8303113
      (here we even have issues with creating adjacent memops)

      --------------------- Original description: -----------------

      The attached Test2.java does not vectorize, as we can see:
      ./java -Xbatch -XX:CompileCommand=compileonly,Test2::test -XX:+TraceNewVectors -XX:+TraceSuperWord -XX:+Verbose -XX:+TraceLoopOpts -XX:UseAVX=2 Test2.java

      See the attached "swap.png", we can see that there was a edge swapping. This means that the left and right operations are shuffled, and therefore the vector input/outputs do not align any more.

       If I comment out the commute operation during IGVN, then it does vectorize:

      diff --git a/src/hotspot/share/opto/addnode.cpp b/src/hotspot/share/opto/addnode.cpp
      index cf8f58d8e23..820fa5f9c84 100644
      --- a/src/hotspot/share/opto/addnode.cpp
      +++ b/src/hotspot/share/opto/addnode.cpp
      @@ -118,11 +118,11 @@ static bool commute(PhaseGVN* phase, Node* add) {
           return true;
         }
       
      - // Otherwise, sort inputs (commutativity) to help value numbering.
      - if( in1->_idx > in2->_idx ) {
      - add->swap_edges(1, 2);
      - return true;
      - }
      + // // Otherwise, sort inputs (commutativity) to help value numbering.
      + // if( in1->_idx > in2->_idx ) {
      + // add->swap_edges(1, 2);
      + // return true;
      + // }
         return false;
       }

        1. swap.png
          swap.png
          128 kB
        2. Test2.java
          0.8 kB

            epeter Emanuel Peter
            epeter Emanuel Peter
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: