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(-)
@@ -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;
}
@@ -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