[gcc r12-6222] tree-optimization/103816 - detect offset overflow in SLP group analysis

Richard Biener rguenth@gcc.gnu.org
Wed Jan 5 10:56:51 GMT 2022


https://gcc.gnu.org/g:1021b72bf6542f3c08e5404b65063216ee1b06f7

commit r12-6222-g1021b72bf6542f3c08e5404b65063216ee1b06f7
Author: Richard Biener <rguenther@suse.de>
Date:   Wed Jan 5 10:14:52 2022 +0100

    tree-optimization/103816 - detect offset overflow in SLP group analysis
    
    This makes sure to detect overflow when computing DR_GROUP_GAP
    and DR_GROUP_SIZE more thoroughly so artificial testcases like the
    added one are not fooling the existing check.
    
    2022-01-05  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/103816
            * tree-vect-data-refs.c (vect_analyze_group_access_1): Also
            check DR_GROUP_GAP compute for overflow and representability.
    
            * gcc.dg/torture/pr103816.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr103816.c | 10 ++++++++++
 gcc/tree-vect-data-refs.c               | 15 ++++++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr103816.c b/gcc/testsuite/gcc.dg/torture/pr103816.c
new file mode 100644
index 00000000000..769036a1af8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr103816.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-w" } */
+
+extern struct {
+  unsigned char a;
+  unsigned char b;
+  unsigned char c;
+  unsigned char d;
+} g[];
+void main() { g[0].b = (g[0].b & g[4].b) * g[2305843009213693952ULL].c; }
diff --git a/gcc/tree-vect-data-refs.c b/gcc/tree-vect-data-refs.c
index 2b3ec6289de..dd20ed974af 100644
--- a/gcc/tree-vect-data-refs.c
+++ b/gcc/tree-vect-data-refs.c
@@ -2721,7 +2721,20 @@ vect_analyze_group_access_1 (vec_info *vinfo, dr_vec_info *dr_info)
           /* Check that the distance between two accesses is equal to the type
              size. Otherwise, we have gaps.  */
           diff = (TREE_INT_CST_LOW (DR_INIT (data_ref))
-                  - TREE_INT_CST_LOW (prev_init)) / type_size;
+		  - TREE_INT_CST_LOW (prev_init)) / type_size;
+	  if (diff < 1 || diff > UINT_MAX)
+	    {
+	      /* For artificial testcases with array accesses with large
+		 constant indices we can run into overflow issues which
+		 can end up fooling the groupsize constraint below so
+		 check the individual gaps (which are represented as
+		 unsigned int) as well.  */
+	      if (dump_enabled_p ())
+		dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+				 "interleaved access with gap larger "
+				 "than representable\n");
+	      return false;
+	    }
 	  if (diff != 1)
 	    {
 	      /* FORNOW: SLP of accesses with gaps is not supported.  */


More information about the Gcc-cvs mailing list