aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2020-10-08 13:18:57 +0200
committerRichard Biener <rguenther@suse.de>2020-10-08 14:22:28 +0200
commit629e0547af33221a925f38757b52a9284148b68a (patch)
tree346ef3990a12adf0022f382cb1d920a47f5af6aa /gcc
parent2bdf324fb33d67f0850139040df0c0390258ab38 (diff)
downloadgcc-629e0547af33221a925f38757b52a9284148b68a.zip
gcc-629e0547af33221a925f38757b52a9284148b68a.tar.gz
gcc-629e0547af33221a925f38757b52a9284148b68a.tar.bz2
tree-optimization/97330 - fix bad load sinking
This fixes bad placement of sunk loads. 2020-10-08 Richard Biener <rguenther@suse.de> PR tree-optimization/97330 * tree-ssa-sink.c (statement_sink_location): Avoid skipping PHIs when they dominate the insert location. * gcc.dg/torture/pr97330-1.c: New testcase. * gcc.dg/torture/pr97330-2.c: Likewise.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr97330-1.c19
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr97330-2.c14
-rw-r--r--gcc/tree-ssa-sink.c4
3 files changed, 36 insertions, 1 deletions
diff --git a/gcc/testsuite/gcc.dg/torture/pr97330-1.c b/gcc/testsuite/gcc.dg/torture/pr97330-1.c
new file mode 100644
index 0000000..7dce5bd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr97330-1.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+
+typedef int a;
+typedef char b;
+int c;
+void d(e, f, dst, g, avail, h) int e;
+b *f, *dst;
+a g, avail;
+int h;
+{
+ b i = *f;
+ if (e)
+ goto j;
+ while (avail) {
+ *dst = i;
+ j:
+ avail -= c;
+ }
+}
diff --git a/gcc/testsuite/gcc.dg/torture/pr97330-2.c b/gcc/testsuite/gcc.dg/torture/pr97330-2.c
new file mode 100644
index 0000000..a064483
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr97330-2.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+
+int a, b, d;
+char c, e;
+void f(void) {
+ char g = c;
+ if (b)
+ goto h;
+ while (d) {
+ e = c;
+ h:
+ d -= a;
+ }
+}
diff --git a/gcc/tree-ssa-sink.c b/gcc/tree-ssa-sink.c
index ba8e557..207aae2 100644
--- a/gcc/tree-ssa-sink.c
+++ b/gcc/tree-ssa-sink.c
@@ -391,8 +391,10 @@ statement_sink_location (gimple *stmt, basic_block frombb,
if (gimple_code (use_stmt) == GIMPLE_PHI)
{
/* In case the PHI node post-dominates the current insert location
- we can disregard it. */
+ we can disregard it. But make sure it is not dominating
+ it as well as can happen in a CFG cycle. */
if (commondom != bb
+ && !dominated_by_p (CDI_DOMINATORS, commondom, bb)
&& dominated_by_p (CDI_POST_DOMINATORS, commondom, bb))
continue;
bb = EDGE_PRED (bb, PHI_ARG_INDEX_FROM_USE (use_p))->src;