]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
2017-08-08 Richard Biener <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 8 Aug 2017 12:51:20 +0000 (12:51 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 8 Aug 2017 12:51:20 +0000 (12:51 +0000)
PR middle-end/81719
* tree-ssa-loop-niter.c: Include tree-dfa.h.
(expand_simple_operations): Also look through ADDR_EXPRs with
MEM_REF bases treating them as POINTER_PLUS_EXPR.

* g++.dg/tree-ssa/pr81719.C: New testcase.

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

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/tree-ssa/pr81719.C [new file with mode: 0644]
gcc/tree-ssa-loop-niter.c

index c88e6668c9ef602af09f7c15687358a2b7782e0f..b0a59d55164ee26c96a3ef25c9456398a2ee3615 100644 (file)
@@ -1,3 +1,10 @@
+2017-08-08  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/81719
+       * tree-ssa-loop-niter.c: Include tree-dfa.h.
+       (expand_simple_operations): Also look through ADDR_EXPRs with
+       MEM_REF bases treating them as POINTER_PLUS_EXPR.
+
 2017-08-08  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/81723
index a3f5d46ed7d9d7942e2ed50d099714210285bac9..1fec0ec1152c3178358d9550c5040051cef5e423 100644 (file)
@@ -1,3 +1,8 @@
+2017-08-08  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/81719
+       * g++.dg/tree-ssa/pr81719.C: New testcase.
+
 2017-08-08  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/81723
diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr81719.C b/gcc/testsuite/g++.dg/tree-ssa/pr81719.C
new file mode 100644 (file)
index 0000000..6e017af
--- /dev/null
@@ -0,0 +1,24 @@
+/* { dg-do compile { target c++11 } } */
+/* { dg-options "-O3 -fdump-tree-optimized" } */
+
+typedef int Items[2];
+
+struct ItemArray
+{
+  Items items;
+  int sum_x2() const;
+};
+
+int ItemArray::sum_x2() const
+{
+  int total = 0;
+  for (int item : items)
+    {
+      total += item;
+    }
+  return total;
+}
+
+/* We should be able to compute the number of iterations to two, unroll
+   the loop and end up with a single basic-block in sum_x2.  */
+/* { dg-final { scan-tree-dump-times "bb" 1 "optimized" } } */
index e0107c28dfbf7c5e3e0a6c508fa97e2f61d0a78a..0d6d1019ac63961f5c3f509e0eeec8cbae464c7e 100644 (file)
@@ -42,6 +42,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-chrec.h"
 #include "tree-scalar-evolution.h"
 #include "params.h"
+#include "tree-dfa.h"
 
 
 /* The maximum number of dominator BBs we search for conditions
@@ -1980,6 +1981,21 @@ expand_simple_operations (tree expr, tree stop)
 
       if (code == SSA_NAME)
        return expand_simple_operations (e, stop);
+      else if (code == ADDR_EXPR)
+       {
+         HOST_WIDE_INT offset;
+         tree base = get_addr_base_and_unit_offset (TREE_OPERAND (e, 0),
+                                                    &offset);
+         if (base
+             && TREE_CODE (base) == MEM_REF)
+           {
+             ee = expand_simple_operations (TREE_OPERAND (base, 0), stop);
+             return fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (expr), ee,
+                                 wide_int_to_tree (sizetype,
+                                                   mem_ref_offset (base)
+                                                   + offset));
+           }
+       }
 
       return expr;
     }