rtl combine should consider NaNs when generate fp min/max [PR94708]
authorHaijian Zhang <z.zhanghaijian@huawei.com>
Fri, 24 Apr 2020 00:56:25 +0000 (08:56 +0800)
committerRichard Biener <rguenther@suse.de>
Fri, 24 Apr 2020 09:25:38 +0000 (11:25 +0200)
    As discussed on PR94708, it's unsafe for rtl combine to generate fp
    min/max under -funsafe-math-optimizations, considering NaNs. In
    addition to flag_unsafe_math_optimizations check, we also need to
    do extra mode feature testing here: && !HONOR_NANS (mode)
    && !HONOR_SIGNED_ZEROS (mode)

    2020-04-24  Haijian Zhang <z.zhanghaijian@huawei.com>

    gcc/
PR rtl-optimization/94708
* combine.c (simplify_if_then_else): Add check for
!HONOR_NANS (mode) && !HONOR_SIGNED_ZEROS (mode).
    gcc/testsuite/
PR fortran/94708
* gfortran.dg/pr94708.f90: New test.

gcc/ChangeLog
gcc/combine.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr94708.f90 [new file with mode: 0644]

index cf97cfed6263eea6d01f2ed252404500b78da4c5..6032e681d7fde41f5eeb907fdc267fb0e80c14d3 100644 (file)
@@ -1,3 +1,9 @@
+2020-04-24  Haijian Zhang <z.zhanghaijian@huawei.com>
+
+       PR rtl-optimization/94708
+       * combine.c (simplify_if_then_else): Add check for
+       !HONOR_NANS (mode) && !HONOR_SIGNED_ZEROS (mode).
+
 2020-04-23  Martin Sebor  <msebor@redhat.com>
 
        PR driver/90983
index cff76cd3303483aed5476c63b191401ec2599a7e..4c324f38660807432ce2873cce18d5b398b5d4b3 100644 (file)
@@ -6643,7 +6643,10 @@ simplify_if_then_else (rtx x)
 
   /* Look for MIN or MAX.  */
 
-  if ((! FLOAT_MODE_P (mode) || flag_unsafe_math_optimizations)
+  if ((! FLOAT_MODE_P (mode)
+       || (flag_unsafe_math_optimizations
+          && !HONOR_NANS (mode)
+          && !HONOR_SIGNED_ZEROS (mode)))
       && comparison_p
       && rtx_equal_p (XEXP (cond, 0), true_rtx)
       && rtx_equal_p (XEXP (cond, 1), false_rtx)
index a955cd5f4f8a103816f378836e6328540c82e058..4b1e9e11e7c852f31b2c122d357d6f3cc8c10c9a 100644 (file)
@@ -1,3 +1,8 @@
+2020-04-24  Haijian Zhang <z.zhanghaijian@huawei.com>
+
+       PR rtl-optimization/94708
+       * gfortran.dg/pr94708.f90: New test.
+
 2020-04-23  David Edelsohn  <dje.gcc@gmail.com>
 
        * gcc.dg/torture/pr90020.c: Skip on AIX.
diff --git a/gcc/testsuite/gfortran.dg/pr94708.f90 b/gcc/testsuite/gfortran.dg/pr94708.f90
new file mode 100644 (file)
index 0000000..9b5f138
--- /dev/null
@@ -0,0 +1,13 @@
+! { dg-do compile { target aarch64*-*-* } }
+! { dg-options "-O2 -funsafe-math-optimizations -fdump-rtl-combine" }
+
+subroutine f(vara,varb,varc,res)
+      REAL, INTENT(IN) :: vara,varb,varc
+      REAL, INTENT(out) :: res
+
+      res = vara
+      if (res .lt. varb)  res = varb
+      if (res .gt. varc)  res = varc
+end subroutine
+
+! { dg-final { scan-rtl-dump-not "smin" "combine" } }