[llvm-bugs] [Bug 39195] New: Clang no longer optimizing patterns to horizontal add/sub after r343727

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Oct 5 18:13:28 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=39195

            Bug ID: 39195
           Summary: Clang no longer optimizing patterns to horizontal
                    add/sub after r343727
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: douglas_yung at playstation.sony.com
                CC: llvm-bugs at lists.llvm.org

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 '-'.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20181006/4a25ae05/attachment-0001.html>


More information about the llvm-bugs mailing list