[PUSHED] ranger: Fix operator_div with VREL_LT [PR126934]

Andrea Pinski <[email protected]>
Newsgroups gmane.comp.gcc.patches
Message-ID <[email protected]>
The problem here (which I missed during the review) is
that when we don't set the rel_range to 0, the rel_range
will be undefined (rather than varying) so when we do
an intersection with that the lhs becomes undefined.
That is wrong.  This fixes the problem by instead
doing an early return if either of the ops are not
nonnegative.

Pushed as obvious after bootstrap/test on x86_64-linux-gnu.

	PR tree-optimization/126934

gcc/ChangeLog:

	* range-op.cc (operator_div::op1_op2_relation_effect): Fix
	for ops range being negative with VREL_LT.

gcc/testsuite/ChangeLog:

	* gcc.dg/torture/pr126934-1.c: New test.

Signed-off-by: Andrea Pinski <[email protected]>
---
 gcc/range-op.cc                           |  8 ++++----
 gcc/testsuite/gcc.dg/torture/pr126934-1.c | 23 +++++++++++++++++++++++
 2 files changed, 27 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr126934-1.c

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index bb055623872..1918ef5f9b1 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -2647,10 +2647,10 @@ operator_div::op1_op2_relation_effect (irange &lhs_range,
     /* op1/op2 = 0 if op1 < op2 and both op1 and op2
        are known positives.  */
     case VREL_LT:
-      if (TYPE_UNSIGNED (type)
-	  || (wi::ge_p (op1_range.lower_bound (), 0, SIGNED)
-	      && wi::ge_p (op2_range.lower_bound (), 0, SIGNED)))
-	rel_range.set_zero (type);
+      if (!op1_range.nonnegative_p ()
+	   || !op2_range.nonnegative_p ())
+	return false;
+      rel_range.set_zero (type);
       break;
     default:
       return false;
diff --git a/gcc/testsuite/gcc.dg/torture/pr126934-1.c b/gcc/testsuite/gcc.dg/torture/pr126934-1.c
new file mode 100644
index 00000000000..f4404dbecd1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr126934-1.c
@@ -0,0 +1,23 @@
+/* { dg-do run } */
+/* PR tree-optimization/126934 */
+
+__attribute__((noinline))
+int ff(int a, signed char c)
+{
+  int t = c;
+  int t1 = c+60;
+  if (a)
+    return t/t1;
+  return 1000;
+}
+
+int main ()
+{
+  if (ff(1,-127) != 1)
+    __builtin_abort ();
+  if (ff(1,1) != 0)
+    __builtin_abort ();
+  if (ff(1,4) != 0)
+    __builtin_abort ();
+}
+
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.