tree-dfa.c (get_ref_base_and_extent): Use range-info to refine results when processin...
authorRichard Biener <rguenther@suse.de>
Fri, 18 May 2018 10:12:20 +0000 (10:12 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 18 May 2018 10:12:20 +0000 (10:12 +0000)
2018-05-18  Richard Biener  <rguenther@suse.de>

* tree-dfa.c (get_ref_base_and_extent): Use range-info to refine
results when processing array refs with variable index.

* gcc.dg/tree-ssa/ssa-dse-35.c: New testcase.
* gcc.dg/graphite/scop-10.c: Adjust to avoid dead code.
* gcc.dg/graphite/scop-6.c: Likewise.
* gcc.dg/graphite/scop-7.c: Likewise.
* gcc.dg/graphite/scop-8.c: Likewise.
* gcc.dg/graphite/scop-9.c: Likewise.

From-SVN: r260354

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/graphite/scop-10.c
gcc/testsuite/gcc.dg/graphite/scop-6.c
gcc/testsuite/gcc.dg/graphite/scop-7.c
gcc/testsuite/gcc.dg/graphite/scop-8.c
gcc/testsuite/gcc.dg/graphite/scop-9.c
gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-35.c [new file with mode: 0644]
gcc/tree-dfa.c

index 3026df4f05730e487d019160d083a86e0a5bdfee..8a1bc05c3b9165e3db7e585baf853c0c9e3f4030 100644 (file)
@@ -1,3 +1,8 @@
+2018-05-18  Richard Biener  <rguenther@suse.de>
+
+       * tree-dfa.c (get_ref_base_and_extent): Use range-info to refine
+       results when processing array refs with variable index.
+
 2018-05-18  Toon Moene  <toon@moene.org>
 
        * doc/invoke.texi: Move -floop-unroll-and-jam documentation
index 840d9a0f49378966d1efa1f2ba7fd5f2031b512a..7d53f322505d2ca945fa3824dd14547c8577309b 100644 (file)
@@ -1,3 +1,12 @@
+2018-05-18  Richard Biener  <rguenther@suse.de>
+
+       * gcc.dg/tree-ssa/ssa-dse-35.c: New testcase.
+       * gcc.dg/graphite/scop-10.c: Adjust to avoid dead code.
+       * gcc.dg/graphite/scop-6.c: Likewise.
+       * gcc.dg/graphite/scop-7.c: Likewise.
+       * gcc.dg/graphite/scop-8.c: Likewise.
+       * gcc.dg/graphite/scop-9.c: Likewise.
+
 2018-05-18  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
        * gcc.target/aarch64/vect-init-ld1.c: New test.
index 20d53510b4ec508ddeb3837b55b97379a9d7c52c..d04183072f38624e5503a5739974a30c784786c5 100644 (file)
@@ -22,7 +22,7 @@ int toto()
         b[i+k] = b[i+k-5] + 2;
     }
 
-  return a[3][5] + b[1];
+  return a[3][5] + b[2];
 }
 
 /* { dg-final { scan-tree-dump-times "number of SCoPs: 1" 1 "graphite"} } */
index 1da486a2ddfbd041e0cf6cc5fed36a2bf8be5a5e..9bc1d9f4ccd0ef6b368eebd3485ec1b07d23256a 100644 (file)
@@ -23,7 +23,7 @@ int toto()
         b[i+k] = b[i+k-5] + 2;
     }
 
-  return a[3][5] + b[1];
+  return a[3][5] + b[2];
 }
 
 /* { dg-final { scan-tree-dump-times "number of SCoPs: 1" 1 "graphite"} } */
index 2f0a50470e912e7461531132ecf4bef22f8fbace..f4f3093fcafc9f8ef86e35281aaa4ca6953a6af8 100644 (file)
@@ -23,7 +23,7 @@ int toto()
         b[i+k] = b[i+k-5] + 2;
     }
 
-  return a[3][5] + b[1];
+  return a[3][5] + b[2];
 }
 
 /* { dg-final { scan-tree-dump-times "number of SCoPs: 1" 1 "graphite"} } */
index 3ceb5d874d604679b9a7ce9e171e0d4a9aae23f8..b06265108c6e82f6b80af796401cf345ec1a0afe 100644 (file)
@@ -23,7 +23,7 @@ int toto()
         b[i+k] = b[i+k-5] + 2;
     }
 
-  return a[3][5] + b[1];
+  return a[3][5] + b[2];
 }
 
 /* { dg-final { scan-tree-dump-times "number of SCoPs: 1" 1 "graphite"} } */
index 93888728b0ddeceae78e65a036ee4f5b1912fbd0..b19291be2f8166021bccad5f09508bafbc21c4e2 100644 (file)
@@ -18,7 +18,7 @@ int toto()
         b[i+k] = b[i+k-5] + 2;
     }
 
-  return a[3][5] + b[1];
+  return a[3][5] + b[2];
 }
 
 /* { dg-final { scan-tree-dump-times "number of SCoPs: 1" 1 "graphite"} } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-35.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-35.c
new file mode 100644 (file)
index 0000000..1f21670
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-dse1-details" } */
+
+int a[256];
+void foo (void)
+{
+  a[0] = 1;
+  for (int i = 5; i < 17; ++i)
+    a[i] = i;
+  a[0] = 2;
+}
+
+/* { dg-final { scan-tree-dump-times "Deleted dead store" 1 "dse1" } } */
index a121b880bb045affa18a7c1101c9de2272f6bb14..00aa75f47ab03e46d7ca4b1b7e44f12f4716c51c 100644 (file)
@@ -529,6 +529,49 @@ get_ref_base_and_extent (tree exp, poly_int64_pod *poffset,
                /* Remember that we have seen an array ref with a variable
                   index.  */
                seen_variable_array_ref = true;
+
+               wide_int min, max;
+               if (TREE_CODE (index) == SSA_NAME
+                   && (low_bound = array_ref_low_bound (exp),
+                       poly_int_tree_p (low_bound))
+                   && (unit_size = array_ref_element_size (exp),
+                       TREE_CODE (unit_size) == INTEGER_CST)
+                   && get_range_info (index, &min, &max) == VR_RANGE)
+                 {
+                   poly_offset_int lbound = wi::to_poly_offset (low_bound);
+                   /* Try to constrain maxsize with range information.  */
+                   offset_int omax
+                     = offset_int::from (max, TYPE_SIGN (TREE_TYPE (index)));
+                   if (known_lt (lbound, omax))
+                     {
+                       poly_offset_int rmaxsize;
+                       rmaxsize = (omax - lbound + 1)
+                           * wi::to_offset (unit_size) << LOG2_BITS_PER_UNIT;
+                       if (!known_size_p (maxsize)
+                           || known_lt (rmaxsize, maxsize))
+                         {
+                           /* If we know an upper bound below the declared
+                              one this is no longer variable.  */
+                           if (known_size_p (maxsize))
+                             seen_variable_array_ref = false;
+                           maxsize = rmaxsize;
+                         }
+                     }
+                   /* Try to adjust bit_offset with range information.  */
+                   offset_int omin
+                     = offset_int::from (min, TYPE_SIGN (TREE_TYPE (index)));
+                   if (known_le (lbound, omin))
+                     {
+                       poly_offset_int woffset
+                         = wi::sext (omin - lbound,
+                                     TYPE_PRECISION (TREE_TYPE (index)));
+                       woffset *= wi::to_offset (unit_size);
+                       woffset <<= LOG2_BITS_PER_UNIT;
+                       bit_offset += woffset;
+                       if (known_size_p (maxsize))
+                         maxsize -= woffset;
+                     }
+                 }
              }
          }
          break;