relation_fold_and_or looks for relations among common operands feeding
logical ands and ors. With no knowledge of NANs, it should not attempt
to do this with floating point ssa names.
PR tree-optimization/108447
gcc/
* gimple-range-fold.cc (old_using_range::relation_fold_and_or):
Do not attempt to fold HONOR_NAN types.
gcc/testsuite/
* gcc.dg/pr108447.c: New.
if (!ssa1_dep1 || !ssa1_dep2 || !ssa2_dep1 || !ssa2_dep2)
return;
+ if (HONOR_NANS (TREE_TYPE (ssa1_dep1)))
+ return;
+
// Make sure they are the same dependencies, and detect the order of the
// relationship.
bool reverse_op2 = true;
--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+__attribute__((noipa)) int
+foo (float x, float y)
+{
+ _Bool cmp1 = x <= y;
+ _Bool cmp2 = x >= y;
+ if (cmp1 && cmp2)
+ return 1;
+ else if (!cmp1 && !cmp2)
+ return -1;
+ return 0;
+}
+
+int
+main ()
+{
+ if (foo (0.0f, __builtin_nanf ("")) != -1)
+ __builtin_abort ();
+ if (foo (__builtin_nanf (""), -42.0f) != -1)
+ __builtin_abort ();
+ if (foo (0.0f, -0.0f) != 1)
+ __builtin_abort ();
+ if (foo (42.0f, 42.0f) != 1)
+ __builtin_abort ();
+ if (foo (42.0f, -0.0f) != 0)
+ __builtin_abort ();
+ if (foo (0.0f, -42.0f) != 0)
+ __builtin_abort ();
+ return 0;
+}
+