[COMMITTED,range-op-float] Implement MINUS_EXPR.

Message ID 20221109070758.1030615-2-aldyh@redhat.com
State Unresolved
Headers
Series [COMMITTED,range-op-float] Implement MINUS_EXPR. |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Aldy Hernandez Nov. 9, 2022, 7:07 a.m. UTC
  Now that the generic parts of the binary operators have been
abstracted, implementing MINUS_EXPR is a cinch.

The op[12]_range entries will be submitted as a follow-up.

gcc/ChangeLog:

	* range-op-float.cc (class foperator_minus): New.
	(floating_op_table::floating_op_table): Add MINUS_EXPR entry.
---
 gcc/range-op-float.cc | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
  

Comments

Xi Ruoyao Nov. 9, 2022, 1:49 p.m. UTC | #1
Hi Aldy,

This commit breaks the attached test case at -O2 on x86_64-linux-gnu and
loongarch64-linux-gnu :(.

The code is simplified from Glibc: the breakage causes two Glibc test
failures on loongarch64-linux-gnu.

Reverting the commit can fix the breakage.

On Wed, 2022-11-09 at 08:07 +0100, Aldy Hernandez via Gcc-patches wrote:
> Now that the generic parts of the binary operators have been
> abstracted, implementing MINUS_EXPR is a cinch.
> 
> The op[12]_range entries will be submitted as a follow-up.
> 
> gcc/ChangeLog:
> 
>         * range-op-float.cc (class foperator_minus): New.
>         (floating_op_table::floating_op_table): Add MINUS_EXPR entry.
> ---
>  gcc/range-op-float.cc | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
> 
> diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
> index 7075c25442a..d52e971f84e 100644
> --- a/gcc/range-op-float.cc
> +++ b/gcc/range-op-float.cc
> @@ -1884,6 +1884,29 @@ class foperator_plus : public
> range_operator_float
>  } fop_plus;
>  
>  
> +class foperator_minus : public range_operator_float
> +{
> +  void rv_fold (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub, bool
> &maybe_nan,
> +               tree type,
> +               const REAL_VALUE_TYPE &lh_lb,
> +               const REAL_VALUE_TYPE &lh_ub,
> +               const REAL_VALUE_TYPE &rh_lb,
> +               const REAL_VALUE_TYPE &rh_ub) const final override
> +  {
> +    frange_arithmetic (MINUS_EXPR, type, lb, lh_lb, rh_ub,
> dconstninf);
> +    frange_arithmetic (MINUS_EXPR, type, ub, lh_ub, rh_lb,
> dconstinf);
> +
> +    // [+INF] - [+INF] = NAN
> +    if (real_isinf (&lh_ub, false) && real_isinf (&rh_ub, false))
> +      maybe_nan = true;
> +    // [-INF] - [-INF] = NAN
> +    else if (real_isinf (&lh_lb, true) && real_isinf (&rh_lb, true))
> +      maybe_nan = true;
> +    else
> +      maybe_nan = false;
> +  }
> +} fop_minus;
> +
>  // Instantiate a range_op_table for floating point operations.
>  static floating_op_table global_floating_table;
>  
> @@ -1917,6 +1940,7 @@ floating_op_table::floating_op_table ()
>    set (ABS_EXPR, fop_abs);
>    set (NEGATE_EXPR, fop_negate);
>    set (PLUS_EXPR, fop_plus);
> +  set (MINUS_EXPR, fop_minus);
>  }
>  
>  // Return a pointer to the range_operator_float instance, if there is
  
Xi Ruoyao Nov. 9, 2022, 1:58 p.m. UTC | #2
On Wed, 2022-11-09 at 21:49 +0800, Xi Ruoyao wrote:
> Hi Aldy,
> 
> This commit breaks the attached test case at -O2 on x86_64-linux-gnu and
  ^^^^^^^^^^^

Ah, not this one.  I meant r13-3842 "Implement op[12]_range operators
for PLUS_EXPR and MINUS_EXPR."

> loongarch64-linux-gnu :(.
> 
> The code is simplified from Glibc: the breakage causes two Glibc test
> failures on loongarch64-linux-gnu.
> 
> Reverting the commit can fix the breakage.
            ^^^^^^^^^^ also r13-3842.

/* snip */

> > The op[12]_range entries will be submitted as a follow-up.
  
Aldy Hernandez Nov. 9, 2022, 3:45 p.m. UTC | #3
I have reverted the patch while I sort this out.

Thanks for the report and especially for the distilled test.  It's very useful.

Aldy

On Wed, Nov 9, 2022 at 2:58 PM Xi Ruoyao <xry111@xry111.site> wrote:
>
> On Wed, 2022-11-09 at 21:49 +0800, Xi Ruoyao wrote:
> > Hi Aldy,
> >
> > This commit breaks the attached test case at -O2 on x86_64-linux-gnu and
>   ^^^^^^^^^^^
>
> Ah, not this one.  I meant r13-3842 "Implement op[12]_range operators
> for PLUS_EXPR and MINUS_EXPR."
>
> > loongarch64-linux-gnu :(.
> >
> > The code is simplified from Glibc: the breakage causes two Glibc test
> > failures on loongarch64-linux-gnu.
> >
> > Reverting the commit can fix the breakage.
>             ^^^^^^^^^^ also r13-3842.
>
> /* snip */
>
> > > The op[12]_range entries will be submitted as a follow-up.
>
> --
> Xi Ruoyao <xry111@xry111.site>
> School of Aerospace Science and Technology, Xidian University
>
  

Patch

diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index 7075c25442a..d52e971f84e 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -1884,6 +1884,29 @@  class foperator_plus : public range_operator_float
 } fop_plus;
 
 
+class foperator_minus : public range_operator_float
+{
+  void rv_fold (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub, bool &maybe_nan,
+		tree type,
+		const REAL_VALUE_TYPE &lh_lb,
+		const REAL_VALUE_TYPE &lh_ub,
+		const REAL_VALUE_TYPE &rh_lb,
+		const REAL_VALUE_TYPE &rh_ub) const final override
+  {
+    frange_arithmetic (MINUS_EXPR, type, lb, lh_lb, rh_ub, dconstninf);
+    frange_arithmetic (MINUS_EXPR, type, ub, lh_ub, rh_lb, dconstinf);
+
+    // [+INF] - [+INF] = NAN
+    if (real_isinf (&lh_ub, false) && real_isinf (&rh_ub, false))
+      maybe_nan = true;
+    // [-INF] - [-INF] = NAN
+    else if (real_isinf (&lh_lb, true) && real_isinf (&rh_lb, true))
+      maybe_nan = true;
+    else
+      maybe_nan = false;
+  }
+} fop_minus;
+
 // Instantiate a range_op_table for floating point operations.
 static floating_op_table global_floating_table;
 
@@ -1917,6 +1940,7 @@  floating_op_table::floating_op_table ()
   set (ABS_EXPR, fop_abs);
   set (NEGATE_EXPR, fop_negate);
   set (PLUS_EXPR, fop_plus);
+  set (MINUS_EXPR, fop_minus);
 }
 
 // Return a pointer to the range_operator_float instance, if there is