re PR tree-optimization/82697 (Wrong optimization with aliasing and "if")
authorRichard Biener <rguenther@suse.de>
Tue, 24 Oct 2017 13:51:45 +0000 (13:51 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 24 Oct 2017 13:51:45 +0000 (13:51 +0000)
2017-10-24  Richard Biener  <rguenther@suse.de>

PR tree-optimization/82697
* tree-ssa-phiopt.c (cond_store_replacement): Use alias-set
zero for conditional load and unconditional store.

* gcc.dg/torture/pr82697.c: New testcase.

From-SVN: r254047

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr82697.c [new file with mode: 0644]
gcc/tree-ssa-phiopt.c

index ce02caa6d2440fd4e9a8191e600787887d82d92e..63bb64fafeb76deacdb9894e0733bd0681cc962d 100644 (file)
@@ -1,3 +1,9 @@
+2017-10-24  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/82697
+       * tree-ssa-phiopt.c (cond_store_replacement): Use alias-set
+       zero for conditional load and unconditional store.
+
 2017-10-24  H.J. Lu  <hongjiu.lu@intel.com>
 
        * doc/install.texi: Document bootstrap-cet.
index a8a4a119886f0c2f2e8a28cf7c9e1cd0f011b704..18794e49c641bd846eb9973d0c714d8ca961375a 100644 (file)
@@ -1,3 +1,8 @@
+2017-10-24  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/82697
+       * gcc.dg/torture/pr82697.c: New testcase.
+
 2017-10-24  Mukesh Kapoor  <mukesh.kapoor@oracle.com>
            Paolo Carlini  <paolo.carlini@oracle.com>
 
diff --git a/gcc/testsuite/gcc.dg/torture/pr82697.c b/gcc/testsuite/gcc.dg/torture/pr82697.c
new file mode 100644 (file)
index 0000000..57da8a2
--- /dev/null
@@ -0,0 +1,23 @@
+/* { dg-do run } */
+
+__attribute__((noinline,noclone))
+void test(int *pi, long *pl, int f)
+{
+  *pl = 0;
+
+  *pi = 1;
+
+  if (f)
+    *pl = 2;
+}
+
+int main()
+{
+  void *p = __builtin_malloc(sizeof (long));
+
+  test(p, p, 0);
+
+  if (*(int *)p != 1)
+    __builtin_abort ();
+  return 0;
+}
index d0570c3fa9c1981bca00c645935624cfc7df3531..6e0e18689dab15eb932e8d7d7c28564271ea2b53 100644 (file)
@@ -1912,9 +1912,24 @@ cond_store_replacement (basic_block middle_bb, basic_block join_bb,
   gsi_remove (&gsi, true);
   release_defs (assign);
 
+  /* Make both store and load use alias-set zero as we have to
+     deal with the case of the store being a conditional change
+     of the dynamic type.  */
+  lhs = unshare_expr (lhs);
+  tree *basep = &lhs;
+  while (handled_component_p (*basep))
+    basep = &TREE_OPERAND (*basep, 0);
+  if (TREE_CODE (*basep) == MEM_REF
+      || TREE_CODE (*basep) == TARGET_MEM_REF)
+    TREE_OPERAND (*basep, 1)
+      = fold_convert (ptr_type_node, TREE_OPERAND (*basep, 1));
+  else
+    *basep = build2 (MEM_REF, TREE_TYPE (*basep),
+                    build_fold_addr_expr (*basep),
+                    build_zero_cst (ptr_type_node));
+
   /* 2) Insert a load from the memory of the store to the temporary
         on the edge which did not contain the store.  */
-  lhs = unshare_expr (lhs);
   name = make_temp_ssa_name (TREE_TYPE (lhs), NULL, "cstore");
   new_stmt = gimple_build_assign (name, lhs);
   gimple_set_location (new_stmt, locus);