diff mbox

Alias analysis of zero sized arrays

Message ID 1493159225.3139.189.camel@cavium.com
State New
Headers show

Commit Message

Steve Ellcey April 25, 2017, 10:27 p.m. UTC
This patch changes get_ref_base_and_extent to treat zero sized arrays
like C99 flexible arrays and assume that references to zero sized
arrays can also be made beyond the 'end' of the array.  C99 flexible
arrays are recognized by not having an INTEGER_CST limit/size and the
routine then sets maxsize to -1 for special handling.  This patch
checks for a value of 0 when we do have an INTEGER_CST limit/size and
handles it like a flexible array.

Tested with a bootstrap on aarch64 and a GCC test run with no
regressions.

I did not create a testcase because the test I have (attached) is not
runnable.  If you compile this test case for aarch64 with
'-UFLEX -O2 -fno-strict-aliasing' you will get two loads, then two
stores in the main loop.  In the original large program that this came
from, that generated bad code.  If compiled with -DFLEX instead of
-UFLEX, you get load, store, load, store and that was working.  With
this patch, both versions (-UFLEX and -DFLEX) generate the load, store,
load, store sequence.

OK for checkin?

Steve Ellcey
sellcey@cavium.com


2017-04-25  Steve Ellcey  <sellcey@cavium.com>

	* tree-dfa.c (get_ref_base_and_extent): Treat zero size array like
	a C99 flexible array.
diff mbox

Patch

diff --git a/gcc/tree-dfa.c b/gcc/tree-dfa.c
index 8ee46dc..79c3489 100644
--- a/gcc/tree-dfa.c
+++ b/gcc/tree-dfa.c
@@ -438,6 +438,10 @@  get_ref_base_and_extent (tree exp, HOST_WIDE_INT *poffset,
       && TREE_CODE (size_tree) == INTEGER_CST)
     bitsize = wi::to_offset (size_tree);
 
+  /* If zero sized array, treat it like a flexible array.  */
+  if (bitsize == 0)
+    bitsize = -1;
+
   /* Initially, maxsize is the same as the accessed element size.
      In the following it will only grow (or become -1).  */
   maxsize = bitsize;
@@ -504,7 +508,13 @@  get_ref_base_and_extent (tree exp, HOST_WIDE_INT *poffset,
 		if (maxsize != -1
 		    && csize
 		    && TREE_CODE (csize) == INTEGER_CST)
-		  maxsize = wi::to_offset (csize) - bit_offset;
+		  {
+		    maxsize = wi::to_offset (csize) - bit_offset;
+
+		    /* If zero sized array, treat it like a flexible array.  */
+		    if (maxsize == 0)
+		      maxsize = -1;
+		  }
 		else
 		  maxsize = -1;
 	      }