diff mbox series

[COMMITTED] Change integral divide by zero to produce UNDEFINED range.

Message ID b1ed6389-7fe9-1933-5e49-c1633e5400e1@redhat.com
State New
Headers show
Series [COMMITTED] Change integral divide by zero to produce UNDEFINED range. | expand

Commit Message

Andrew MacLeod July 30, 2021, 7:12 p.m. UTC
This patch changes divide by 0 to produce an UNDEFINED range rather than 
VARYING.   This can help in propagating values by ignoring / 0 results 
rather than bailing.

Bootstrapped on x86_64-pc-linux-gnu and powerpc64-unknown-linux-gnu with 
no regressions.  Pushed.

Andrew
diff mbox series

Patch

From ebbcdd7fae1f802763850e4afedfdfa09cf10e1a Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
Date: Wed, 28 Jul 2021 13:14:22 -0400
Subject: [PATCH 2/3] Change integral divide by zero to produce UNDEFINED.

Instead of VARYING, we can get better results by treating divide by zero
as producing an undefined result.

	gcc/
	* range-op.cc (operator_div::wi_fold): Return UNDEFINED for [0, 0] divisor.

	gcc/testsuite/
	* gcc.dg/tree-ssa/pr61839_2.c: Adjust.
---
 gcc/range-op.cc                           | 9 +--------
 gcc/testsuite/gcc.dg/tree-ssa/pr61839_2.c | 3 +--
 2 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index b1fb25c77f8..69228882930 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -1785,13 +1785,6 @@  operator_div::wi_fold (irange &r, tree type,
 		       const wide_int &lh_lb, const wide_int &lh_ub,
 		       const wide_int &rh_lb, const wide_int &rh_ub) const
 {
-  // If we know we will divide by zero...
-  if (rh_lb == 0 && rh_ub == 0)
-    {
-      r.set_varying (type);
-      return;
-    }
-
   const wide_int dividend_min = lh_lb;
   const wide_int dividend_max = lh_ub;
   const wide_int divisor_min = rh_lb;
@@ -1818,7 +1811,7 @@  operator_div::wi_fold (irange &r, tree type,
   // If we're definitely dividing by zero, there's nothing to do.
   if (wi_zero_p (type, divisor_min, divisor_max))
     {
-      r.set_varying (type);
+      r.set_undefined ();
       return;
     }
 
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr61839_2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr61839_2.c
index cfec54de991..f1b8feb4e9d 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr61839_2.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr61839_2.c
@@ -45,9 +45,8 @@  int bar2 ()
   return 0;
 }
 
-
 /* Dont optimize 972195717 / 0 in function foo.  */
-/* { dg-final { scan-tree-dump-times "972195717 / " 1  "evrp" } } */
+/* { dg-final { scan-tree-dump-times "972195717 / " 0  "evrp" } } */
 /* Dont optimize 972195717 % 0 in function bar.  */
 /* { dg-final { scan-tree-dump-times "972195717 % " 1 "evrp" } } */
 /* May optimize in function bar2, but EVRP doesn't perform this yet.  */
-- 
2.17.2