[Bug tree-optimization/126455] New: Wrong folding of (a < b) ^ (a > b) to a != b for FP vectors

"ktkachov at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126455

            Bug ID: 126455
           Summary: Wrong folding of (a < b) ^ (a > b) to a != b for FP
                    vectors
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ktkachov at gcc dot gnu.org
  Target Milestone: ---
            Target: aarch64

Consider the testcase:
#include <stdio.h>

typedef float v4sf __attribute__((vector_size (16)));
typedef int   v4si __attribute__((vector_size (16)));

__attribute__((noipa)) v4si vec_xor (v4sf a, v4sf b) { return (a < b) ^ (a >
b); }
__attribute__((noipa)) v4si vec_ior (v4sf a, v4sf b) { return (a < b) | (a >
b); }
__attribute__((noipa)) int  scl_xor (float a, float b) { return (a < b) ^ (a >
b); }

int
main (void)
{
  float n = __builtin_nanf ("");
  v4sf a = { n, n, n, n }, b = { 1, 1, 1, 1 };
  v4si x = vec_xor (a, b);
  v4si o = vec_ior (a, b);
  int s = scl_xor (n, 1.0f);
  int bad = 0;

  printf ("vector ^ : %d  (must be 0)\n", x[0]);
  printf ("vector | : %d  (must be 0)\n", o[0]);
  printf ("scalar ^ : %d  (must be 0)\n", s);

  if (x[0] != 0) { printf ("FAIL: vector exclusive or\n"); bad = 1; }
  if (o[0] != 0) { printf ("FAIL: vector inclusive or\n"); bad = 1; }
  if (s != 0)    { printf ("FAIL: scalar\n"); bad = 1; }
  return bad;
}

with -O2 this gives different results between GCC and LLVM.
Expected, and what the scalar version gives:

```
vector ^ : 0  (must be 0)
vector | : 0  (must be 0)
scalar ^ : 0  (must be 0)
```

Observed:

```
vector ^ : -1  (must be 0)
FAIL: vector exclusive or
```

This fold should only happen under -ffinite-math-only IMO
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.