aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2021-01-29 11:17:42 +0100
committerRichard Biener <rguenther@suse.de>2021-01-29 12:09:10 +0100
commitf4e426f7bd7df279cb7aaecd91d273d9b7db338d (patch)
tree0d38d84b46427765d9f866fdf32a5675a53e2de5
parenta8c455bafdefdab0a7b8cdbcdb116c0086bae05e (diff)
downloadgcc-f4e426f7bd7df279cb7aaecd91d273d9b7db338d.zip
gcc-f4e426f7bd7df279cb7aaecd91d273d9b7db338d.tar.gz
gcc-f4e426f7bd7df279cb7aaecd91d273d9b7db338d.tar.bz2
tree-optimization/97627 - Avoid computing niters for fake edges
This avoids computing niters information for fake edges. 2021-01-29 Bin Cheng <bin.cheng@linux.alibaba.com> Richard Biener <rguenther@suse.de> PR tree-optimization/97627 * tree-ssa-loop-niter.c (number_of_iterations_exit_assumptions): Do not analyze fake edges. * g++.dg/pr97627.C: New testcase.
-rw-r--r--gcc/testsuite/g++.dg/pr97627.C44
-rw-r--r--gcc/tree-ssa-loop-niter.c5
2 files changed, 49 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/pr97627.C b/gcc/testsuite/g++.dg/pr97627.C
new file mode 100644
index 0000000..81466dc
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr97627.C
@@ -0,0 +1,44 @@
+/* PR tree-optimization/97627. */
+/* { dg-do run } */
+
+struct S { unsigned short x, y; } m = { 1, 0 };
+
+__attribute__((noipa)) void
+baz (int x, int y)
+{
+ if (x != 0 || y != 1)
+ __builtin_abort ();
+}
+
+__attribute__((noipa)) void
+bar ()
+{
+ throw 1;
+}
+
+void
+foo ()
+{
+ while (1)
+ {
+ int a = m.x + 1;
+ int b = m.y + 1;
+ for (int c = 0; c < a; c++)
+ for (int d = 0; d < b; d++)
+ baz (d, b);
+ bar ();
+ }
+}
+
+int
+main ()
+{
+ try
+ {
+ foo ();
+ }
+ catch (int)
+ {
+ }
+ return 0;
+}
diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
index 98978bc..3817ec4 100644
--- a/gcc/tree-ssa-loop-niter.c
+++ b/gcc/tree-ssa-loop-niter.c
@@ -2407,6 +2407,11 @@ number_of_iterations_exit_assumptions (class loop *loop, edge exit,
affine_iv iv0, iv1;
bool safe;
+ /* The condition at a fake exit (if it exists) does not control its
+ execution. */
+ if (exit->flags & EDGE_FAKE)
+ return false;
+
/* Nothing to analyze if the loop is known to be infinite. */
if (loop_constraint_set_p (loop, LOOP_C_INFINITE))
return false;