]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-ssa-sink: Improve code sinking pass
authorAjit Kumar Agarwal <aagarwa1@linux.ibm.com>
Wed, 8 May 2024 14:21:27 +0000 (09:21 -0500)
committerAjit Kumar Agarwal <aagarwa1@linux.ibm.com>
Wed, 8 May 2024 14:23:45 +0000 (09:23 -0500)
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  <aagarwa1@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.

gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-21.c [new file with mode: 0644]
gcc/tree-ssa-sink.cc

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 (file)
index 0000000..d3b79ca
--- /dev/null
@@ -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 } } */
index 880d6f70a80aa70cdc1393b621b4e92b3480ec29..2f90acb7ef481e0f52afaa4e31d7d4a9d56ce8c9 100644 (file)
@@ -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;
        }