https://gcc.gnu.org/g:f4b86ab09dfe258c4780fcc7567ca8a275c96e7a

commit r15-327-gf4b86ab09dfe258c4780fcc7567ca8a275c96e7a
Author: Ajit Kumar Agarwal <aagar...@linux.ibm.com>
Date:   Wed May 8 09:21:27 2024 -0500

    tree-ssa-sink: Improve code sinking pass
    
    Currently, code sinking will sink code at the use points with loop having 
same
    nesting depth. The following patch improves code sinking by placing the sunk
    code in begining of the block after the labels.
    
    2024-05-08  Ajit Kumar Agarwal  <aagar...@linux.ibm.com>
    
    gcc/ChangeLog:
    
            PR tree-optimization/81953
            * tree-ssa-sink.cc (statement_sink_location):Sink statements at
            the begining of the basic block after labels.
    
    gcc/testsuite/ChangeLog:
    
            PR tree-optimization/81953
            * gcc.dg/tree-ssa/ssa-sink-21.c: New test.

Diff:
---
 gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-21.c | 15 +++++++++++++++
 gcc/tree-ssa-sink.cc                        |  5 +----
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-21.c 
b/gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-21.c
new file mode 100644
index 000000000000..d3b79ca58031
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-21.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-sink-stats" } */
+void bar();
+int j;
+void foo(int a, int b, int c, int d, int e, int f)
+{
+  int l;
+  l = a + b + c + d +e + f;
+  if (a != 5)
+    {
+      bar();
+      j = l;
+    }
+}
+/* { dg-final { scan-tree-dump 
{l_12\s+=\s+_4\s+\+\s+f_11\(D\);\n\s+bar\s+\(\)} sink1 } } */
diff --git a/gcc/tree-ssa-sink.cc b/gcc/tree-ssa-sink.cc
index 880d6f70a80a..2f90acb7ef48 100644
--- a/gcc/tree-ssa-sink.cc
+++ b/gcc/tree-ssa-sink.cc
@@ -439,10 +439,7 @@ statement_sink_location (gimple *stmt, basic_block frombb,
          if (sinkbb == frombb)
            return false;
 
-         if (sinkbb == gimple_bb (use))
-           *togsi = gsi_for_stmt (use);
-         else
-           *togsi = gsi_after_labels (sinkbb);
+         *togsi = gsi_after_labels (sinkbb);
 
          return true;
        }

Reply via email to