public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-1484] range-ops: (nonzero | X) is nonzero
@ 2021-06-15 16:41 Aldy Hernandez
0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2021-06-15 16:41 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:4602714382f7a4603290b1ceb3121d9187debdb9
commit r12-1484-g4602714382f7a4603290b1ceb3121d9187debdb9
Author: Aldy Hernandez <aldyh@redhat.com>
Date: Mon Jun 14 12:51:48 2021 +0200
range-ops: (nonzero | X) is nonzero
For bitwise or, nonzero|X is always nonzero. Make sure we don't drop to
varying in this case.
gcc/ChangeLog:
* range-op.cc (operator_bitwise_or::wi_fold): Make sure
nonzero|X is nonzero.
(range_op_bitwise_and_tests): Add tests for above.
Diff:
---
gcc/range-op.cc | 31 ++++++++++++++++++++++++++-----
1 file changed, 26 insertions(+), 5 deletions(-)
diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 742e54686b4..e805f26a333 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -2534,11 +2534,20 @@ operator_bitwise_or::wi_fold (irange &r, tree type,
new_lb = wi::max (new_lb, lh_lb, sign);
if (wi::lt_p (rh_ub, 0, sign))
new_lb = wi::max (new_lb, rh_lb, sign);
- // If the limits got swapped around, return varying.
- if (wi::gt_p (new_lb, new_ub,sign))
- r.set_varying (type);
- else
- value_range_with_overflow (r, type, new_lb, new_ub);
+ // If the limits got swapped around, return a conservative range.
+ if (wi::gt_p (new_lb, new_ub, sign))
+ {
+ // Make sure that nonzero|X is nonzero.
+ if (wi::gt_p (lh_lb, 0, sign)
+ || wi::gt_p (rh_lb, 0, sign)
+ || wi::lt_p (lh_ub, 0, sign)
+ || wi::lt_p (rh_ub, 0, sign))
+ r.set_nonzero (type);
+ else
+ r.set_varying (type);
+ return;
+ }
+ value_range_with_overflow (r, type, new_lb, new_ub);
}
bool
@@ -3744,6 +3753,18 @@ range_op_bitwise_and_tests ()
i1 = int_range<1> (integer_type_node);
op_bitwise_and.op1_range (res, integer_type_node, i1, i2);
ASSERT_TRUE (res == int_range<1> (integer_type_node));
+
+ // (NONZERO | X) is nonzero.
+ i1.set_nonzero (integer_type_node);
+ i2.set_varying (integer_type_node);
+ op_bitwise_or.fold_range (res, integer_type_node, i1, i2);
+ ASSERT_TRUE (res.nonzero_p ());
+
+ // (NEGATIVE | X) is nonzero.
+ i1 = int_range<1> (INT (-5), INT (-3));
+ i2.set_varying (integer_type_node);
+ op_bitwise_or.fold_range (res, integer_type_node, i1, i2);
+ ASSERT_FALSE (res.contains_p (INT (0)));
}
void
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-06-15 16:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-15 16:41 [gcc r12-1484] range-ops: (nonzero | X) is nonzero Aldy Hernandez
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).