<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Clang no longer optimizing patterns to horizontal add/sub after r343727"
   href="https://bugs.llvm.org/show_bug.cgi?id=39195">39195</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang no longer optimizing patterns to horizontal add/sub after r343727
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>douglas_yung@playstation.sony.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following patterns when wrapped in a function signature of the form:

__attribute__((noinline))
__m128 add_func(__m128 a, __m128 b) {
 /* Insert snippet here */
|

should when compiled for -btver2 with optimizations yield a horizontal add
(hadd) instruction. Here are the patterns we found in our internal testing that
no longer generate a horizontal add after r343727:

===============================
1-undef:

/* add_pd_003: */
__m128d r = __builtin_shufflevector(a, b, 0, 2) + __builtin_shufflevector(a, b,
1, 3);
return __builtin_shufflevector(r, a, -1, 1);

/* add_pd_005: */
__m128d r = (__m128d){ a[0], b[0] } +(__m128d){ a[1], b[1] };
return __builtin_shufflevector(r, a, -1, 1);

/* add_pd_010: */
__m128d r = __builtin_shufflevector(a, b, 0, 2) + __builtin_shufflevector(a, b,
1, 3);
return __builtin_shufflevector(r, a, 1, -1);

/* add_pd_012: */
__m128d r = (__m128d){ a[0], b[0] } +(__m128d){ a[1], b[1] };
return __builtin_shufflevector(r, a, 1, -1);

===============================
2-undef:

/* add_ps_007: */
__m128 r = __builtin_shufflevector(a, b, 0, 2, 4, 6) +
__builtin_shufflevector(a, b, 1, 3, 5, 7);
return __builtin_shufflevector(r, a, -1, -1, 2, 3);

/* add_ps_013: */
__m128 r = (__m128){ a[0], a[2], b[0], b[2] } + (__m128){ a[1], a[3], b[1],
b[3] };
return __builtin_shufflevector(r, a, -1, -1, 2, 3);

/* add_ps_030: */
__m128 r = __builtin_shufflevector(a, b, 0, 2, 4, 6) +
__builtin_shufflevector(a, b, 1, 3, 5, 7);
return __builtin_shufflevector(r, a, 3, 2, -1, -1);

/* add_ps_036: */
__m128 r = (__m128){ a[0], a[2], b[0], b[2] } + (__m128){ a[1], a[3], b[1],
b[3] };
return __builtin_shufflevector(r, a, 3, 2, -1, -1);

===============================
3-undef:

/* add_ps_007: */
__m128 r = __builtin_shufflevector(a, b, 0, 2, 4, 6) +
__builtin_shufflevector(a, b, 1, 3, 5, 7);
return __builtin_shufflevector(r, a, -1, -1, 2, -1);
}

/* add_ps_008: */
__m128 r = __builtin_shufflevector(a, b, 0, 2, 4, 6) +
__builtin_shufflevector(a, b, 1, 3, 5, 7);
return __builtin_shufflevector(r, a, -1, -1, -1, 3);

/* add_ps_011: */
__m128 r = (__m128){ a[0], a[2], b[0], b[2] } +(__m128){ a[1], a[3], b[1], b[3]
};
return __builtin_shufflevector(r, a, -1, -1, 2, -1);

/* add_ps_012: */
__m128 r = (__m128){ a[0], a[2], b[0], b[2] } +(__m128){ a[1], a[3], b[1], b[3]
};
return __builtin_shufflevector(r, a, -1, -1, -1, 3);

/* add_ps_017: */
__m128 r = __builtin_shufflevector(a, b, 0, 2, 4, 6) +
__builtin_shufflevector(a, b, 1, 3, 5, 7);
return __builtin_shufflevector(r, a, 3, -1, -1, -1);

/* add_ps_018: */
__m128 r = __builtin_shufflevector(a, b, 0, 2, 4, 6) +
__builtin_shufflevector(a, b, 1, 3, 5, 7);
return __builtin_shufflevector(r, a, -1, 2, -1, -1);

/* add_ps_021: */
__m128 r = (__m128){ a[0], a[2], b[0], b[2] } + (__m128){ a[1], a[3], b[1],
b[3] };
return __builtin_shufflevector(r, a, 3, -1, -1, -1);

/* add_ps_022: */
__m128 r = (__m128){ a[0], a[2], b[0], b[2] } + (__m128){ a[1], a[3], b[1],
b[3] };
return __builtin_shufflevector(r, a, -1, 2, -1, -1);


When compiled using optimizations to a target that supports hadd instructions
(such as btver2), the compiler used to generate horizontal add instructions
until upstream change r343727 was made.

Note that the same regression also applies to horizontal subtraction, and you
can see the same cases of the compiler now missing this optimization in the
above examples by changing the '+' to a '-'.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>