re PR tree-optimization/91482 (__builtin_assume_aligned should not break write combining)
authorRichard Biener <rguenther@suse.de>
Wed, 21 Aug 2019 11:45:34 +0000 (11:45 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 21 Aug 2019 11:45:34 +0000 (11:45 +0000)
2019-08-21  Richard Biener  <rguenther@suse.de>

PR tree-optimization/91482
* tree-ssa-ccp.c (ccp_folder::fold_stmt): Remove useless
BUILT_IN_ASSUME_ALIGNED calls.

* gcc.dg/tree-ssa/pr91482.c: New testcase.

From-SVN: r274796

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/pr91482.c [new file with mode: 0644]
gcc/tree-ssa-ccp.c

index c17d0e14c4f8dc7228cc9954d67d2c8110d825c7..7550e422dadd7e2eed72df58ebe59e3cd90e34fc 100644 (file)
@@ -1,3 +1,9 @@
+2019-08-21  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/91482
+       * tree-ssa-ccp.c (ccp_folder::fold_stmt): Remove useless
+       BUILT_IN_ASSUME_ALIGNED calls.
+
 2019-08-21  Richard Biener  <rguenther@suse.de>
 
        PR target/91498
index 0bd613334a9a5c869d01d6c82f07824e66c327df..e8d22d1844df3de8d651f16cf27f63a3c8736b95 100644 (file)
@@ -1,3 +1,8 @@
+2019-08-21  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/91482
+       * gcc.dg/tree-ssa/pr91482.c: New testcase.
+
 2019-08-21  Eric Botcazou  <ebotcazou@adacore.com>
 
        * c-c++-common/dump-ada-spec-15.c: New test.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr91482.c b/gcc/testsuite/gcc.dg/tree-ssa/pr91482.c
new file mode 100644 (file)
index 0000000..7d6a724
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ccp1 -fdump-tree-store-merging" } */
+
+void write64 (void *p)
+{
+  unsigned *p1 = (unsigned *) __builtin_assume_aligned (p, 8);
+  *p1++ = 0;
+  unsigned *p2 = (unsigned *) __builtin_assume_aligned (p1, 4);
+  *p2++ = 1;
+}
+
+/* { dg-final { scan-tree-dump-times "__builtin_assume_aligned" 1 "ccp1" } } */
+/* { dg-final { scan-tree-dump "New sequence of 1 stores to replace old one of 2 stores" "store-merging" { target lp64 } } } */
index 458b2184d3f4191b5fa0a925d6c639b4b1b7479c..5af3810e8f0df911554b3287be0b0d4511ed765c 100644 (file)
@@ -2315,6 +2315,32 @@ ccp_folder::fold_stmt (gimple_stmt_iterator *gsi)
              }
           }
 
+       /* If there's no extra info from an assume_aligned call,
+          drop it so it doesn't act as otherwise useless dataflow
+          barrier.  */
+       if (gimple_call_builtin_p (stmt, BUILT_IN_ASSUME_ALIGNED))
+         {
+           tree ptr = gimple_call_arg (stmt, 0);
+           ccp_prop_value_t ptrval = get_value_for_expr (ptr, true);
+           if (ptrval.lattice_val == CONSTANT
+               && TREE_CODE (ptrval.value) == INTEGER_CST
+               && ptrval.mask != 0)
+             {
+               ccp_prop_value_t val
+                 = bit_value_assume_aligned (stmt, NULL_TREE, ptrval, false);
+               unsigned int ptralign = least_bit_hwi (ptrval.mask.to_uhwi ());
+               unsigned int align = least_bit_hwi (val.mask.to_uhwi ());
+               if (ptralign == align
+                   && ((TREE_INT_CST_LOW (ptrval.value) & (align - 1))
+                       == (TREE_INT_CST_LOW (val.value) & (align - 1))))
+                 {
+                   bool res = update_call_from_tree (gsi, ptr);
+                   gcc_assert (res);
+                   return true;
+                 }
+             }
+         }
+
        /* Propagate into the call arguments.  Compared to replace_uses_in
           this can use the argument slot types for type verification
           instead of the current argument type.  We also can safely