re PR tree-optimization/89430 (A missing ifcvt optimization to generate csel)
authorJiangning Liu <jiangning.liu@amperecomputing.com>
Fri, 12 Jul 2019 16:28:43 +0000 (16:28 +0000)
committerJeff Law <law@gcc.gnu.org>
Fri, 12 Jul 2019 16:28:43 +0000 (10:28 -0600)
2019-07-12  Jiangning Liu  <jiangning.liu@amperecomputing.com>

PR tree-optimization/89430
* tree-ssa-phiopt.c (cond_store_replacement): Support conditional
store elimination for local variable without address escape.

PR tree-optimization/89430
* gcc.dg/tree-ssa/pr89430-1.c: New test.
* gcc.dg/tree-ssa/pr89430-2.c: New test.
* gcc.dg/tree-ssa/pr89430-3.c: New test.
* gcc.dg/tree-ssa/pr89430-4.c: New test.
* gcc.dg/tree-ssa/pr89430-5.c: New test.
* gcc.dg/tree-ssa/pr89430-6.c: New test.

From-SVN: r273449

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/pr89430-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr89430-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr89430-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr89430-4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr89430-5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr89430-6.c [new file with mode: 0644]
gcc/tree-ssa-phiopt.c

index 4f32256c8d83375017b59ce76e70fe8896386974..8923216198c55bec135d1a480519e30f46bf6f5b 100644 (file)
@@ -1,3 +1,9 @@
+2019-07-12  Jiangning Liu  <jiangning.liu@amperecomputing.com>
+
+       PR tree-optimization/89430
+       * tree-ssa-phiopt.c (cond_store_replacement): Support conditional
+       store elimination for local variable without address escape.
+
 2019-07-12  Jeff Law  <law@redhat.com>
 
        * config/c6x/c6x.c (c6x_section_type): Clear SECTION_NOTYPE
index e948a715679676490c3481f97ca882967d8b0631..71813089358f5ca408f757129758660f3d6e85de 100644 (file)
@@ -1,3 +1,13 @@
+2019-07-08  Jiangning Liu  <jiangning.liu@amperecomputing.com>
+
+       PR tree-optimization/89430
+       * gcc.dg/tree-ssa/pr89430-1.c: New test.
+       * gcc.dg/tree-ssa/pr89430-2.c: New test.
+       * gcc.dg/tree-ssa/pr89430-3.c: New test.
+       * gcc.dg/tree-ssa/pr89430-4.c: New test.
+       * gcc.dg/tree-ssa/pr89430-5.c: New test.
+       * gcc.dg/tree-ssa/pr89430-6.c: New test.
+
 2019-07-12  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/91145
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr89430-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr89430-1.c
new file mode 100644 (file)
index 0000000..8ee1850
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-cselim-details" } */
+
+unsigned test(unsigned k, unsigned b) {
+        unsigned a[2];
+        if (b < a[k]) {
+                a[k] = b;
+        }
+        return a[0]+a[1];
+}
+
+/* { dg-final { scan-tree-dump "Conditional store replacement" "cselim" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr89430-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr89430-2.c
new file mode 100644 (file)
index 0000000..9b96875
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-cselim-details" } */
+
+int c;
+unsigned test(unsigned k, unsigned b) {
+        unsigned a[2];
+       a[k] = c;
+        if (b < a[k]) {
+                a[k] = b;
+        }
+        return a[0]+a[1];
+}
+
+/* { dg-final { scan-tree-dump "Conditional store replacement" "cselim" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr89430-3.c b/gcc/testsuite/gcc.dg/tree-ssa/pr89430-3.c
new file mode 100644 (file)
index 0000000..0fac9f9
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-cselim-details" } */
+
+unsigned a[2];
+unsigned test(unsigned k, unsigned b) {
+        if (b < a[k]) {
+                a[k] = b;
+        }
+        return a[0]+a[1];
+}
+
+/* { dg-final { scan-tree-dump-not "Conditional store replacement" "cselim" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr89430-4.c b/gcc/testsuite/gcc.dg/tree-ssa/pr89430-4.c
new file mode 100644 (file)
index 0000000..54b8c11
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-cselim-details" } */
+
+int *p;
+unsigned test(unsigned k, unsigned b) {
+        unsigned a[2];
+       p = a;
+        if (b < a[k]) {
+                a[k] = b;
+        }
+        return a[0]+a[1];
+}
+
+/* { dg-final { scan-tree-dump-not "Conditional store replacement" "cselim" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr89430-5.c b/gcc/testsuite/gcc.dg/tree-ssa/pr89430-5.c
new file mode 100644 (file)
index 0000000..b2d0411
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-cselim-details" } */
+
+int test(int b, int k) {
+    struct {
+        int data[2];
+    } a;
+
+    if (b < a.data[k]) {
+        a.data[k] = b;
+    }
+
+    return a.data[0] + a.data[1];
+}
+
+/* { dg-final { scan-tree-dump "Conditional store replacement" "cselim" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr89430-6.c b/gcc/testsuite/gcc.dg/tree-ssa/pr89430-6.c
new file mode 100644 (file)
index 0000000..8d3c4f7
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-cselim-details" } */
+
+int test(int b, int k) {
+    typedef struct {
+           int x;
+    } SS;
+    struct {
+        SS data[2];
+    } a;
+
+    if (b < a.data[k].x) {
+        a.data[k].x = b;
+    }
+
+    return a.data[0].x + a.data[1].x;
+}
+
+/* { dg-final { scan-tree-dump "Conditional store replacement" "cselim" } } */
index 7088ff9199882c34d8e0db1dbdab1850c9e460d0..a514ed81ef9968ce71e8345231bc9c604a7cbff0 100644 (file)
@@ -2196,7 +2196,8 @@ get_non_trapping (void)
 
    We check that MIDDLE_BB contains only one store, that that store
    doesn't trap (not via NOTRAP, but via checking if an access to the same
-   memory location dominates us) and that the store has a "simple" RHS.  */
+   memory location dominates us, or the store is to a local addressable
+   object) and that the store has a "simple" RHS.  */
 
 static bool
 cond_store_replacement (basic_block middle_bb, basic_block join_bb,
@@ -2218,8 +2219,9 @@ cond_store_replacement (basic_block middle_bb, basic_block join_bb,
   locus = gimple_location (assign);
   lhs = gimple_assign_lhs (assign);
   rhs = gimple_assign_rhs1 (assign);
-  if (TREE_CODE (lhs) != MEM_REF
-      || TREE_CODE (TREE_OPERAND (lhs, 0)) != SSA_NAME
+  if ((TREE_CODE (lhs) != MEM_REF
+       && TREE_CODE (lhs) != ARRAY_REF
+       && TREE_CODE (lhs) != COMPONENT_REF)
       || !is_gimple_reg_type (TREE_TYPE (lhs)))
     return false;
 
@@ -2227,7 +2229,13 @@ cond_store_replacement (basic_block middle_bb, basic_block join_bb,
      TREE_THIS_NOTRAP here, but in that case we also could move stores,
      whose value is not available readily, which we want to avoid.  */
   if (!nontrap->contains (lhs))
-    return false;
+    {
+      /* If LHS is a local variable without address-taken, we could
+        always safely move down the store.  */
+      tree base = get_base_address (lhs);
+      if (!auto_var_p (base) || TREE_ADDRESSABLE (base))
+       return false;
+    }
 
   /* Now we've checked the constraints, so do the transformation:
      1) Remove the single store.  */
@@ -2280,6 +2288,14 @@ cond_store_replacement (basic_block middle_bb, basic_block join_bb,
   else
     gsi_insert_before (&gsi, new_stmt, GSI_NEW_STMT);
 
+  if (dump_file && (dump_flags & TDF_DETAILS))
+    {
+      fprintf (dump_file, "\nConditional store replacement happened!");
+      fprintf (dump_file, "\nReplaced the store with a load.");
+      fprintf (dump_file, "\nInserted a new PHI statement in joint block:\n");
+      print_gimple_stmt (dump_file, new_stmt, 0, TDF_VOPS|TDF_MEMSYMS);
+    }
+
   return true;
 }