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

C2 SuperWord: IGVN commute swap_edges can prevent vectorization

XMLWordPrintable

      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
          128 kB
          Emanuel Peter
        2. Test2.java
          0.8 kB
          Emanuel Peter

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

              Created:
              Updated: