public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-5698] range-op: Handle op?.undefined_p () in op[12]_range of comparisons [PR108647]
@ 2023-02-03 20:39 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2023-02-03 20:39 UTC (permalink / raw)
  To: gcc-cvs

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

commit r13-5698-ge753080ab8abd4021381699bc7e857f5b4a083c4
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Feb 3 21:39:16 2023 +0100

    range-op: Handle op?.undefined_p () in op[12]_range of comparisons [PR108647]
    
    As mentioned in the PR, we ICE because lhs is singleton [0, 0]
    or [1, 1] but op2 (or in other cases op1) is undefined and op?.*_bound ()
    ICEs on those because there are no pairs for UNDEFINED.
    
    The following patch makes us set r to varying or return false in those
    cases.
    
    2023-02-03  Jakub Jelinek  <jakub@redhat.com>
    
            PR tree-optimization/108647
            * range-op.cc (operator_equal::op1_range,
            operator_not_equal::op1_range): Don't test op2 bound
            equality if op2.undefined_p (), instead set_varying.
            (operator_lt::op1_range, operator_le::op1_range,
            operator_gt::op1_range, operator_ge::op1_range): Return false if
            op2.undefined_p ().
            (operator_lt::op2_range, operator_le::op2_range,
            operator_gt::op2_range, operator_ge::op2_range): Return false if
            op1.undefined_p ().
    
            * g++.dg/torture/pr108647.C: New test.

Diff:
---
 gcc/range-op.cc                         | 30 ++++++++++++++++++++++++++++--
 gcc/testsuite/g++.dg/torture/pr108647.C | 25 +++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 136b709385c..5c67bce6d3a 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -642,7 +642,8 @@ operator_equal::op1_range (irange &r, tree type,
     case BRS_FALSE:
       // If the result is false, the only time we know anything is
       // if OP2 is a constant.
-      if (wi::eq_p (op2.lower_bound(), op2.upper_bound()))
+      if (!op2.undefined_p ()
+	  && wi::eq_p (op2.lower_bound(), op2.upper_bound()))
 	{
 	  r = op2;
 	  r.invert ();
@@ -755,7 +756,8 @@ operator_not_equal::op1_range (irange &r, tree type,
     case BRS_TRUE:
       // If the result is true, the only time we know anything is if
       // OP2 is a constant.
-      if (wi::eq_p (op2.lower_bound(), op2.upper_bound()))
+      if (!op2.undefined_p ()
+	  && wi::eq_p (op2.lower_bound(), op2.upper_bound()))
 	{
 	  r = op2;
 	  r.invert ();
@@ -920,6 +922,9 @@ operator_lt::op1_range (irange &r, tree type,
 			const irange &op2,
 			relation_trio) const
 {
+  if (op2.undefined_p ())
+    return false;
+
   switch (get_bool_state (r, lhs, type))
     {
     case BRS_TRUE:
@@ -942,6 +947,9 @@ operator_lt::op2_range (irange &r, tree type,
 			const irange &op1,
 			relation_trio) const
 {
+  if (op1.undefined_p ())
+    return false;
+
   switch (get_bool_state (r, lhs, type))
     {
     case BRS_TRUE:
@@ -1031,6 +1039,9 @@ operator_le::op1_range (irange &r, tree type,
 			const irange &op2,
 			relation_trio) const
 {
+  if (op2.undefined_p ())
+    return false;
+
   switch (get_bool_state (r, lhs, type))
     {
     case BRS_TRUE:
@@ -1053,6 +1064,9 @@ operator_le::op2_range (irange &r, tree type,
 			const irange &op1,
 			relation_trio) const
 {
+  if (op1.undefined_p ())
+    return false;
+
   switch (get_bool_state (r, lhs, type))
     {
     case BRS_TRUE:
@@ -1141,6 +1155,9 @@ operator_gt::op1_range (irange &r, tree type,
 			const irange &lhs, const irange &op2,
 			relation_trio) const
 {
+  if (op2.undefined_p ())
+    return false;
+
   switch (get_bool_state (r, lhs, type))
     {
     case BRS_TRUE:
@@ -1163,6 +1180,9 @@ operator_gt::op2_range (irange &r, tree type,
 			const irange &op1,
 			relation_trio) const
 {
+  if (op1.undefined_p ())
+    return false;
+
   switch (get_bool_state (r, lhs, type))
     {
     case BRS_TRUE:
@@ -1252,6 +1272,9 @@ operator_ge::op1_range (irange &r, tree type,
 			const irange &op2,
 			relation_trio) const
 {
+  if (op2.undefined_p ())
+    return false;
+
   switch (get_bool_state (r, lhs, type))
     {
     case BRS_TRUE:
@@ -1274,6 +1297,9 @@ operator_ge::op2_range (irange &r, tree type,
 			const irange &op1,
 			relation_trio) const
 {
+  if (op1.undefined_p ())
+    return false;
+
   switch (get_bool_state (r, lhs, type))
     {
     case BRS_TRUE:
diff --git a/gcc/testsuite/g++.dg/torture/pr108647.C b/gcc/testsuite/g++.dg/torture/pr108647.C
new file mode 100644
index 00000000000..abdb92a8131
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr108647.C
@@ -0,0 +1,25 @@
+// PR tree-optimization/108647
+// { dg-do compile }
+
+bool a;
+int b, c;
+
+inline const bool &
+foo (bool &e, const bool &f)
+{
+  return f < e ? f : e;
+}
+
+void
+bar (signed char e, bool *f, bool *h, bool *g)
+{
+  for (;;)
+    if (g)
+      for (signed char j = 0; j < 6;
+	   j += ((f[0] & c ? g[0] : int(0 >= e))
+		 ? 0 : foo (g[0], g[0] > h[0]) + 1))
+	{
+	  a = 0;
+	  b = 0;
+	}
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-03 20:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-03 20:39 [gcc r13-5698] range-op: Handle op?.undefined_p () in op[12]_range of comparisons [PR108647] Jakub Jelinek

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).