gcc/Backport-re-PR-tree-optimization-84552-Compile-time-.patch
2023-12-05 14:46:11 +08:00

71 lines
2.1 KiB
Diff

From e0e3ff695ab4f56d3a69e42303a9af13a23fcc15 Mon Sep 17 00:00:00 2001
From: xiezhiheng <xiezhiheng@huawei.com>
Date: Tue, 5 Dec 2023 14:25:14 +0800
Subject: [PATCH] [Backport] re PR tree-optimization/84552 (Compile time hog w/
-O2 -floop-nest-optimize -fno-tree-copy-prop -fno-tree-fre
-fno-tree-loop-ivcanon)
Reference: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=24545562ca5ece2615f8178ad6c6eb0be4fe6b3f
---
gcc/testsuite/gcc.dg/graphite/pr84552.c | 23 +++++++++++++++++++++++
gcc/tree-scalar-evolution.c | 6 +++++-
2 files changed, 28 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/graphite/pr84552.c
diff --git a/gcc/testsuite/gcc.dg/graphite/pr84552.c b/gcc/testsuite/gcc.dg/graphite/pr84552.c
new file mode 100644
index 000000000..15cbb0848
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/graphite/pr84552.c
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -floop-nest-optimize -fno-tree-copy-prop -fno-tree-fre -fno-tree-loop-ivcanon" } */
+
+int cx;
+
+int
+e6 (int pj, int xe)
+{
+ for (cx = 0; cx < 2; ++cx)
+ while (xe < 1)
+ {
+ for (cx = 0; cx < 2; ++cx)
+ pj *= 2;
+
+ if (cx != 0)
+ goto o3;
+
+ ++xe;
+ }
+
+o3:
+ return pj;
+}
diff --git a/gcc/tree-scalar-evolution.c b/gcc/tree-scalar-evolution.c
index cbd17e864..790050a20 100644
--- a/gcc/tree-scalar-evolution.c
+++ b/gcc/tree-scalar-evolution.c
@@ -280,6 +280,7 @@ along with GCC; see the file COPYING3. If not see
#include "params.h"
#include "tree-ssa-propagate.h"
#include "gimple-fold.h"
+#include "tree-into-ssa.h"
static tree analyze_scalar_evolution_1 (struct loop *, tree, tree);
static tree analyze_scalar_evolution_for_address_of (struct loop *loop,
@@ -1532,7 +1533,10 @@ static tree
follow_copies_to_constant (tree var)
{
tree res = var;
- while (TREE_CODE (res) == SSA_NAME)
+ while (TREE_CODE (res) == SSA_NAME
+ /* We face not updated SSA form in multiple places and this walk
+ may end up in sibling loops so we have to guard it. */
+ && !name_registered_for_update_p (res))
{
gimple *def = SSA_NAME_DEF_STMT (res);
if (gphi *phi = dyn_cast <gphi *> (def))
--
2.19.1