diff mbox series

tree-optimization/98513 - fix bug in range intersection code

Message ID nycvar.YFH.7.76.2101061020080.5547@elmra.sevgm.obk
State New
Headers show
Series tree-optimization/98513 - fix bug in range intersection code | expand

Commit Message

Richard Biener Jan. 6, 2021, 9:20 a.m. UTC
This fixes a premature optimization in the range intersection code
which assumes earlier branches have to be taken, not taking into
account that for symbolic ranges we cannot always compare endpoints.
The fix is to instantiate the compare deemed redundant (which then
fails as undecidable for the testcase).

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

2021-01-06  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/98513
	* value-range.cc (intersect_ranges): Compare the upper bounds
	for the expected relation.

	* gcc.dg/tree-ssa/pr98513.c: New testcase.
---
 gcc/testsuite/gcc.dg/tree-ssa/pr98513.c | 47 +++++++++++++++++++++++++
 gcc/value-range.cc                      |  6 ++--
 2 files changed, 51 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr98513.c
diff mbox series

Patch

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr98513.c b/gcc/testsuite/gcc.dg/tree-ssa/pr98513.c
new file mode 100644
index 00000000000..c15d6bd708e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr98513.c
@@ -0,0 +1,47 @@ 
+/* { dg-do run } */
+/* { dg-options "-O2 -fgimple" } */
+
+__attribute__((noipa))
+void __GIMPLE (ssa,startwith("evrp"))
+foo (int x, int minus_1)
+{
+  int tem;
+  unsigned int _1;
+  unsigned int _2;
+
+  __BB(2):
+  tem_4 = minus_1_3(D);
+  tem_5 = tem_4 + 2;
+  _1 = (unsigned int) x_6(D);
+  _2 = _1 + 2147483647u;
+  if (_2 > 1u)
+    goto __BB3;
+  else
+    goto __BB6;
+
+  __BB(3):
+  if (x_6(D) <= tem_5)
+    goto __BB4;
+  else
+    goto __BB6;
+
+  __BB(4):
+  if (x_6(D) > 5)
+    goto __BB5;
+  else
+    goto __BB6;
+
+  __BB(5):
+  __builtin_exit (0);
+
+  __BB(6):
+  return;
+
+}
+
+int
+main()
+{
+  foo (10, 100);
+  __builtin_abort ();
+}
diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index c404787ccd0..9c42f82a105 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -974,7 +974,8 @@  intersect_ranges (enum value_range_kind *vr0type,
     }
   else if ((operand_less_p (vr1min, *vr0max) == 1
 	    || operand_equal_p (vr1min, *vr0max, 0))
-	   && operand_less_p (*vr0min, vr1min) == 1)
+	   && operand_less_p (*vr0min, vr1min) == 1
+	   && operand_less_p (*vr0max, vr1max) == 1)
     {
       /* [  (  ]  ) or [  ](  ) */
       if (*vr0type == VR_ANTI_RANGE
@@ -1008,7 +1009,8 @@  intersect_ranges (enum value_range_kind *vr0type,
     }
   else if ((operand_less_p (*vr0min, vr1max) == 1
 	    || operand_equal_p (*vr0min, vr1max, 0))
-	   && operand_less_p (vr1min, *vr0min) == 1)
+	   && operand_less_p (vr1min, *vr0min) == 1
+	   && operand_less_p (vr1max, *vr0max) == 1)
     {
       /* (  [  )  ] or (  )[  ] */
       if (*vr0type == VR_ANTI_RANGE