https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128129

            Bug ID: 128129
           Summary: [14/15/16/17 Regression] wrong code with NaN: !(a < b)
                    && a != b folded to a > b (canonicalize_bool ignores
                    NaNs)
           Product: gcc
           Version: 12.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lzy20000419 at outlook dot com
  Target Milestone: ---

The following program aborts at -O1 and above. It should return 0.


int sink;
__attribute__((noipa)) int f(double a, double b, int k)
{
  _Bool v;
  if (k) { v = a < b; sink = 1; }
  else   { v = a < b; sink = 2; }
  if (!v)
    if (a != b)
      return 1;
  return 0;
}
int main(void)
{
  double nan = __builtin_nan ("");
  if (f (nan, 1.0, 1) != 1)   /* !(NaN < 1) && NaN != 1 is true */
    __builtin_abort ();
  return 0;
}
$ gcc -O1 t.c && ./a.out Aborted

Expected: exit 0. -O0 and -fsignaling-nans are fine, clang is fine.

The ifcombine dump says "optimizing two comparisons to a_5(D) > b_6(D)". It
should be a u> b.

It works with 7.5 and fails with 8.1 through 16.2 and current trunk (also -O2,
-O3, -Os), so it's a regression since GCC 8.

https://godbolt.org/z/P5nccxnqo (left gcc 7.5, right trunk)

Disclaimer: This test case was generated by a fuzzer, and the report was
written with LLM assistance.

Reply via email to