]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/105618 - restore load sinking
authorRichard Biener <rguenther@suse.de>
Tue, 17 May 2022 07:45:02 +0000 (09:45 +0200)
committerRichard Biener <rguenther@suse.de>
Tue, 17 May 2022 08:45:45 +0000 (10:45 +0200)
The PR97330 fix caused some missed sinking of loads out of loops
the following patch re-instantiates.

2022-05-17  Richard Biener  <rguenther@suse.de>

PR tree-optimization/105618
* tree-ssa-sink.cc (statement_sink_location): For virtual
PHI uses ignore those defining the used virtual operand.

* gcc.dg/tree-ssa/ssa-sink-19.c: New testcase.

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

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-19.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-19.c
new file mode 100644 (file)
index 0000000..e98d13f
--- /dev/null
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-sink1-details -fdump-tree-cddce2-details" } */
+
+static int b=4;
+int c;
+
+int
+main()
+{
+  int e[5] = {1,1,1,1,1};
+  for (; b >= 0; b--) {
+    c = e[b];
+  }
+  return 0;
+}
+
+/* We should sink e[b] out of the loop which is possible after
+   applying store motion to c and b.  */
+/* { dg-final { scan-tree-dump "Sinking # VUSE" "sink1" } } */
+/* And remove the loop after final value replacement.  */
+/* { dg-final { scan-tree-dump "fix_loop_structure: removing loop" "cddce2" } } */
index 1c226406febd0eb177948840bc5b25a7420a42d4..8ce4403ddc8ff84190c34c45647e4ccd666d2efc 100644 (file)
@@ -390,6 +390,9 @@ statement_sink_location (gimple *stmt, basic_block frombb,
                 with the use.  */
              if (gimple_code (use_stmt) == GIMPLE_PHI)
                {
+                 /* If the PHI defines the virtual operand, ignore it.  */
+                 if (gimple_phi_result (use_stmt) == gimple_vuse (stmt))
+                   continue;
                  /* In case the PHI node post-dominates the current insert
                     location we can disregard it.  But make sure it is not
                     dominating it as well as can happen in a CFG cycle.  */