]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add -funconstrained-commons to work around PR/69368 (and others) in SPEC2006
authoralalaw01 <alalaw01@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 10 Mar 2016 12:19:45 +0000 (12:19 +0000)
committeralalaw01 <alalaw01@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 10 Mar 2016 12:19:45 +0000 (12:19 +0000)
gcc/:

        * common.opt (funconstrained-commons, flag_unconstrained_commons): New.
        * tree.c (array_at_struct_end_p): Do not limit to size of decl for
        DECL_COMMONS if flag_unconstrained_commons is set.
        * tree-dfa.c (get_ref_base_and_extent): Likewise.
        * doc/invoke.texi (Optimize Options): Add -funconstrained-commons.
        (funconstrained-commons): Document.

gcc/testsuite:

* gfortran.dg/unconstrained_commons.f: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@234106 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/common.opt
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/unconstrained_commons.f [new file with mode: 0644]
gcc/tree-dfa.c
gcc/tree.c

index ce244b19080374f5a97d9256491434799458eb7c..b6db5dec92e4c814b47b0230b37c9537407b76d3 100644 (file)
@@ -1,3 +1,13 @@
+2016-03-10  Alan Lawrence  <alan.lawrence@arm.com>
+       Jakub Jelinek <jakub@redhat.com>
+
+       * common.opt (funconstrained-commons, flag_unconstrained_commons): New.
+       * tree.c (array_at_struct_end_p): Do not limit to size of decl for
+       DECL_COMMONS if flag_unconstrained_commons is set.
+       * tree-dfa.c (get_ref_base_and_extent): Likewise.
+       * doc/invoke.texi (Optimize Options): Add -funconstrained-commons.
+       (funconstrained-commons): Document.
+
 2016-03-10  Christophe Lyon  <christophe.lyon@linaro.org>
 
        * config/aarch64/t-aarch64 (OPTIONS_H_EXTRA): Add
index e91f2257e55d45a16a5b75aeb0900cf71dfbfbca..1c8cc8ede8f38e0f8a359e45caddf6efc68c9ed8 100644 (file)
@@ -2458,6 +2458,11 @@ fsplit-paths
 Common Report Var(flag_split_paths) Init(0) Optimization
 Split paths leading to loop backedges.
 
+funconstrained-commons
+Common Var(flag_unconstrained_commons) Optimization
+Assume common declarations may be overridden with ones with a larger
+trailing array.
+
 funit-at-a-time
 Common Report Var(flag_unit_at_a_time) Init(1)
 Compile whole compilation unit at a time.
index 9580c10fc451828951e3cac9fdb60c5b9ba450fb..99ac11b771408c6751c1ddbdabdb4eeb9ec0306a 100644 (file)
@@ -408,7 +408,7 @@ Objective-C and Objective-C++ Dialects}.
 -ftree-parallelize-loops=@var{n} -ftree-pre -ftree-partial-pre -ftree-pta @gol
 -ftree-reassoc -ftree-sink -ftree-slsr -ftree-sra @gol
 -ftree-switch-conversion -ftree-tail-merge -ftree-ter @gol
--ftree-vectorize -ftree-vrp @gol
+-ftree-vectorize -ftree-vrp -funconstrained-commons @gol
 -funit-at-a-time -funroll-all-loops -funroll-loops @gol
 -funsafe-loop-optimizations -funsafe-math-optimizations -funswitch-loops @gol
 -fipa-ra -fvariable-expansion-in-unroller -fvect-cost-model -fvpt @gol
@@ -6699,6 +6699,12 @@ the loop optimizer itself cannot prove that these assumptions are valid.
 If you use @option{-Wunsafe-loop-optimizations}, the compiler warns you
 if it finds this kind of loop.
 
+@item -funconstrained-commons
+@opindex funconstrained-commons
+This option tells the compiler that variables declared in common blocks
+(e.g. Fortran) may later be overridden with longer trailing arrays. This
+prevents certain optimizations that depend on knowing the array bounds.
+
 @item -fcrossjumping
 @opindex fcrossjumping
 Perform cross-jumping transformation.
index 9ae7afd6d9b5c9675c468fe24d05970e2b15b370..f2ed2aba119a15627bcb6549cec63d44e0525c1f 100644 (file)
@@ -1,3 +1,7 @@
+2016-03-10  Alan Lawrence  <alan.lawrence@arm.com>
+
+       * gfortran.dg/unconstrained_commons.f: New.
+
 2016-03-10  Alan Modra  <amodra@gmail.com>
 
        * gcc.dg/pr69195.c: New.
diff --git a/gcc/testsuite/gfortran.dg/unconstrained_commons.f b/gcc/testsuite/gfortran.dg/unconstrained_commons.f
new file mode 100644 (file)
index 0000000..f9fc471
--- /dev/null
@@ -0,0 +1,20 @@
+! { dg-do compile }
+! { dg-options "-O3 -funconstrained-commons -fdump-tree-dom2-details" }
+
+! Test for PR69368: a single-element array in a common block, which will be
+! overridden with a larger size at link time (contrary to language spec).
+! Dominator opts considers accesses to differently-computed elements of X as
+! equivalent, unless -funconstrained-commons is passed in.
+      SUBROUTINE FOO
+      IMPLICIT DOUBLE PRECISION (X)
+      INTEGER J
+      COMMON /MYCOMMON / X(1)
+      DO 10 J=1,1024
+         X(J+1)=X(J+7)
+  10  CONTINUE
+      RETURN
+      END
+! { dg-final { scan-tree-dump-not "FIND" "dom2" } }
+! We should retain both a read and write of mycommon.x.
+! { dg-final { scan-tree-dump-times "  _\[0-9\]+ = mycommon\\.x\\\[_\[0-9\]+\\\];" 1 "dom2" } }
+! { dg-final { scan-tree-dump-times "  mycommon\\.x\\\[_\[0-9\]+\\\] = _\[0-9\]+;" 1 "dom2" } }
index 0e9805663b2f2c5bd5ab6da65c86ee4ef56ea0db..f133abc79bda1d1fbb317019d3af6a1f6a6ee98e 100644 (file)
@@ -612,9 +612,22 @@ get_ref_base_and_extent (tree exp, HOST_WIDE_INT *poffset,
 
   if (DECL_P (exp))
     {
+      if (flag_unconstrained_commons
+         && TREE_CODE (exp) == VAR_DECL && DECL_COMMON (exp))
+       {
+         tree sz_tree = TYPE_SIZE (TREE_TYPE (exp));
+         /* If size is unknown, or we have read to the end, assume there
+            may be more to the structure than we are told.  */
+         if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
+             || (seen_variable_array_ref
+                 && (sz_tree == NULL_TREE
+                     || TREE_CODE (sz_tree) != INTEGER_CST
+                     || (bit_offset + maxsize == wi::to_offset (sz_tree)))))
+           maxsize = -1;
+       }
       /* If maxsize is unknown adjust it according to the size of the
          base decl.  */
-      if (maxsize == -1
+      else if (maxsize == -1
          && DECL_SIZE (exp)
          && TREE_CODE (DECL_SIZE (exp)) == INTEGER_CST)
        maxsize = wi::to_offset (DECL_SIZE (exp)) - bit_offset;
index b8333d45d047cc0c37ee5733bd0c75282c21888d..7d0cb035b233b880ad3245910eeb1277d5b42dba 100644 (file)
@@ -12952,8 +12952,10 @@ array_at_struct_end_p (tree ref)
     }
 
   /* If the reference is based on a declared entity, the size of the array
-     is constrained by its given domain.  */
-  if (DECL_P (ref))
+     is constrained by its given domain.  (Do not trust commons PR/69368).  */
+  if (DECL_P (ref)
+      && !(flag_unconstrained_commons
+          && TREE_CODE (ref) == VAR_DECL && DECL_COMMON (ref)))
     return false;
 
   return true;