public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Andrew Macleod <amacleod@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-2636] Change integral divide by zero to produce UNDEFINED.
Date: Fri, 30 Jul 2021 19:12:12 +0000 (GMT)	[thread overview]
Message-ID: <20210730191212.A9ED539730C4@sourceware.org> (raw)

https://gcc.gnu.org/g:ebbcdd7fae1f802763850e4afedfdfa09cf10e1a

commit r12-2636-gebbcdd7fae1f802763850e4afedfdfa09cf10e1a
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Wed Jul 28 13:14:22 2021 -0400

    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.

Diff:
---
 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.  */


                 reply	other threads:[~2021-07-30 19:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210730191212.A9ED539730C4@sourceware.org \
    --to=amacleod@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).