The recent PR95115 change to punt in const_binop on folding operation
with non-NaN operands into NaN if flag_trapping_math broke the following
testcase, because the x * 0.0 simplification punts just if
x maybe a NaN (because NaN * 0.0 is NaN not 0.0) or if one of the operands
could be negative zero. But Inf * 0.0 or -Inf * 0.0 is also NaN, not
0.0, so when NaNs are honored we need to punt for possible infinities too.
2022-02-05 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/104389
* match.pd (x * 0 -> 0): Punt if x maybe infinite and NaNs are
honored.
* gcc.dg/pr104389.c: New test.
/* Maybe fold x * 0 to 0. The expressions aren't the same
when x is NaN, since x * 0 is also NaN. Nor are they the
same in modes with signed zeros, since multiplying a
- negative value by 0 gives -0, not +0. */
+ negative value by 0 gives -0, not +0. Nor when x is +-Inf,
+ since x * 0 is NaN. */
(simplify
(mult @0 real_zerop@1)
(if (!tree_expr_maybe_nan_p (@0)
+ && (!HONOR_NANS (type) || !tree_expr_maybe_infinite_p (@0))
&& !tree_expr_maybe_real_minus_zero_p (@0)
&& !tree_expr_maybe_real_minus_zero_p (@1))
@1))
--- /dev/null
+/* PR tree-optimization/104389 */
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+/* { dg-add-options ieee } */
+/* { dg-require-effective-target inf } */
+
+__attribute__((noipa)) double
+foo (void)
+{
+ double a = __builtin_huge_val ();
+ return a * 0.0;
+}
+
+__attribute__((noipa)) long double
+bar (void)
+{
+ return __builtin_huge_vall () * 0.0L;
+}
+
+int
+main ()
+{
+ if (!__builtin_isnan (foo ()) || !__builtin_isnanl (bar ()))
+ __builtin_abort ();
+ return 0;
+}