diff mbox series

Drop overflow from constants while building ranges in ranger.

Message ID 20201105161852.551111-1-aldyh@redhat.com
State New
Headers show
Series Drop overflow from constants while building ranges in ranger. | expand

Commit Message

Aldy Hernandez Nov. 5, 2020, 4:18 p.m. UTC
Sometimes the overflow flag will leak into the IL.  Drop it while
creating ranges.

There are various places we could plug this.  This patch just plugs things
at get_tree_range which is the entry point for ranges from tree expressions.
It fixes the PR, and probably fixes the ranger entirely, but we may need
to revisit this.

For example, I looked to see if there were other places that created
ranges with TREE_OVERFLOW set, and there are various.  For example,
the following code pattern appears multiple times in vr-values.c:

  else if (is_gimple_min_invariant (op0))
    vr0.set (op0);

This can pick up TREE_OVERFLOW from the IL if present.  However, the
ranger won't see them so we're good.

At some point we should audit all this.  Or perhaps just nuke all
TREE_OVERFLOW's at irange::set.

For now, this will do.

Pushed.

gcc/ChangeLog:

	PR tree-optimization/97721
	* gimple-range.cc (get_tree_range): Drop overflow from constants.

gcc/testsuite/ChangeLog:

	* gcc.dg/pr97721.c: New test.
---
 gcc/gimple-range.cc            |  2 ++
 gcc/testsuite/gcc.dg/pr97721.c | 13 +++++++++++++
 2 files changed, 15 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/pr97721.c
diff mbox series

Patch

diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index ef65e00cc1d..0c8ec40448f 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -165,6 +165,8 @@  get_tree_range (irange &r, tree expr)
   switch (TREE_CODE (expr))
     {
       case INTEGER_CST:
+	if (TREE_OVERFLOW_P (expr))
+	  expr = drop_tree_overflow (expr);
 	r.set (expr, expr);
 	return true;
 
diff --git a/gcc/testsuite/gcc.dg/pr97721.c b/gcc/testsuite/gcc.dg/pr97721.c
new file mode 100644
index 00000000000..c2a2848ba13
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr97721.c
@@ -0,0 +1,13 @@ 
+// { dg-do compile }
+// { dg-options "-O -fno-tree-dominator-opts" }
+
+int ot;
+
+void
+z6 (char *tw)
+{ 
+  while (ot >= 0)
+    --ot;
+
+  __builtin_strcpy (&tw[ot], tw);
+}