gimple-ssa-strength-reduction.c (valid_mem_ref_cand_p): New function.
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 2 Sep 2019 08:14:47 +0000 (08:14 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Mon, 2 Sep 2019 08:14:47 +0000 (08:14 +0000)
* gimple-ssa-strength-reduction.c (valid_mem_ref_cand_p): New function.
(replace_ref): Do not replace a chain of only two candidates which are
valid memory references.

From-SVN: r275297

gcc/ChangeLog
gcc/gimple-ssa-strength-reduction.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/slsr-42.c [new file with mode: 0644]

index 990c895f69dced5e2ddb967bc1a87a6535fa925d..c5857875896c6d585d53a7cf01ec4b84794dd034 100644 (file)
@@ -1,3 +1,9 @@
+2019-09-02  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gimple-ssa-strength-reduction.c (valid_mem_ref_cand_p): New function.
+       (replace_ref): Do not replace a chain of only two candidates which are
+       valid memory references.
+
 2019-09-02  Martin Liska  <mliska@suse.cz>
 
        * tree-switch-conversion.c (jump_table_cluster::find_jump_tables):
index d343da005e4a55465b8ade9a4946e5e2c4166e04..de7f36015efbb5e4c6d6eb503174619a993d5fba 100644 (file)
@@ -1999,6 +1999,23 @@ replace_ref (tree *expr, slsr_cand_t c)
   update_stmt (c->cand_stmt);
 }
 
+/* Return true if CAND_REF candidate C is a valid memory reference.  */
+
+static bool
+valid_mem_ref_cand_p (slsr_cand_t c)
+{
+  if (TREE_CODE (TREE_OPERAND (c->stride, 1)) != INTEGER_CST)
+    return false;
+
+  struct mem_address addr
+    = { NULL_TREE, c->base_expr, TREE_OPERAND (c->stride, 0),
+       TREE_OPERAND (c->stride, 1), wide_int_to_tree (sizetype, c->index) };
+
+  return
+    valid_mem_ref_p (TYPE_MODE (c->cand_type), TYPE_ADDR_SPACE (c->cand_type),
+                    &addr);
+}
+
 /* Replace CAND_REF candidate C, each sibling of candidate C, and each
    dependent of candidate C with an equivalent strength-reduced data
    reference.  */
@@ -2006,6 +2023,16 @@ replace_ref (tree *expr, slsr_cand_t c)
 static void
 replace_refs (slsr_cand_t c)
 {
+  /* Replacing a chain of only 2 candidates which are valid memory references
+     is generally counter-productive because you cannot recoup the additional
+     calculation added in front of them.  */
+  if (c->basis == 0
+      && c->dependent
+      && !lookup_cand (c->dependent)->dependent
+      && valid_mem_ref_cand_p (c)
+      && valid_mem_ref_cand_p (lookup_cand (c->dependent)))
+    return;
+
   if (dump_file && (dump_flags & TDF_DETAILS))
     {
       fputs ("Replacing reference: ", dump_file);
index 947a653d1b94c91a8ac728558bc4a7f631264d5d..b6dbf7681678bd32b1bcaad133da728382e31952 100644 (file)
@@ -1,3 +1,7 @@
+2019-09-02  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gcc.dg/tree-ssa/slsr-42.c: New test.
+
 2019-09-02  Martin Liska  <mliska@suse.cz>
 
        PR c++/91155
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/slsr-42.c b/gcc/testsuite/gcc.dg/tree-ssa/slsr-42.c
new file mode 100644 (file)
index 0000000..0495fcf
--- /dev/null
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-slsr-details" } */
+
+struct x
+{
+  int a[16];
+  int b[16];
+};
+
+void
+set (struct x *p, unsigned int n, int i)
+{
+  p->a[n] = i;
+  p->b[n] = i;
+}
+
+/* { dg-final { scan-tree-dump-not "Replacing reference: " "slsr"  { target i?86-*-* x86_64-*-* } } } */