https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128123
Bug ID: 128123
Summary: [17 Regression] wrong code at -O1 with ordered
comparison of vector_mask values (-fgimple)
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: yuki.tanaka at defaultcase dot de
Target Milestone: ---
typedef int v4si __attribute__((vector_size (16)));
typedef v4si v4sib __attribute__((vector_mask));
__attribute__((noipa)) v4si a(v4si x, v4si y)
{
v4sib m1 = x < y;
v4sib m2 = x > y;
return (v4si) (m1 < m2);
}
__attribute__((noipa)) v4si b(v4si x, v4si y)
{
v4sib m1 = x < y;
v4sib m2 = x > y;
return (v4si) (m1 <= m2);
}
int main (void)
{
v4si x = { 1, 2, 3, 4 }, y = { 2, 2, 2, 5 };
v4si r = a(x, y), s = b(x, y);
for (int i = 0; i < 4; i++)
if (r[i] != -(x[i] < y[i]) || s[i] != -(x[i] <= y[i]))
__builtin_abort();
return 0;
}
With -O{1,2,3,s} -fgimple GCC 17 aborts on x86-64, GCC 16.1 does not. -O0 is
fine.
Compiler Explorer, -O2 -fgimple (GCC 16.1 vs. GCC 17):
x86-64 GCC 16.1:
"a":
movdqa xmm2, xmm1
pcmpgtd xmm2, xmm0
pcmpgtd xmm0, xmm1
pcmpgtd xmm0, xmm2
ret
"b":
movdqa xmm2, xmm1
pcmpgtd xmm2, xmm0
pcmpgtd xmm0, xmm1
pcmpgtd xmm2, xmm0
pxor xmm0, xmm0
pcmpeqd xmm0, xmm2
ret
x86-64 GCC 17.0.0:
"a":
pcmpgtd xmm0, xmm1
ret
"b":
pcmpgtd xmm1, xmm0
pxor xmm0, xmm0
pcmpeqd xmm0, xmm1
ret
Possibly related to r17-4001-gbbc2517fe41 ("match/fold: Add LT/GT/LE/GE to
combine_comparisons [PR117193]").