diff options
author | Ajit Kumar Agarwal <aagarwa1@linux.ibm.com> | 2024-05-08 09:21:27 -0500 |
---|---|---|
committer | Ajit Kumar Agarwal <aagarwa1@linux.ibm.com> | 2024-05-08 09:23:45 -0500 |
commit | f4b86ab09dfe258c4780fcc7567ca8a275c96e7a (patch) | |
tree | 321c92523ef91f72ff7fcbf6c8922aba59946fb9 | |
parent | 3ee30d7981987b86bd6a9a2675e26fadec48e5cd (diff) | |
download | gcc-f4b86ab09dfe258c4780fcc7567ca8a275c96e7a.zip gcc-f4b86ab09dfe258c4780fcc7567ca8a275c96e7a.tar.gz gcc-f4b86ab09dfe258c4780fcc7567ca8a275c96e7a.tar.bz2 |
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 <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.
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-21.c | 15 | ||||
-rw-r--r-- | 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 0000000..d3b79ca --- /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 880d6f7..2f90acb 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; } |