[GCC13] PR tree-optimization/105834 - Choose better initial values for ranger.
Checks
Commit Message
As requested porting this patch from trunk resolves this PR in GCC 13.
Bootstraps on x86_64-pc-linux-gnu with no regressions. OK for the gcc
13 branch?
Andrew
From 0182a25607fa353274c27ec57ca497c00f1d1b76 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
Date: Mon, 6 Nov 2023 11:33:32 -0500
Subject: [PATCH] Choose better initial values for ranger.
Instead of defaulting to VARYING, fold the stmt using just global ranges.
PR tree-optimization/105834
gcc/
* gimple-range-cache.cc (ranger_cache::get_global_range): Call
fold_range with global query to choose an initial value.
gcc/testsuite/
* gcc.dg/pr105834.c
---
gcc/gimple-range-cache.cc | 17 ++++++++++++++++-
gcc/testsuite/gcc.dg/pr105834.c | 17 +++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/pr105834.c
@@ -846,7 +846,22 @@ ranger_cache::get_global_range (vrange &r, tree name, bool ¤t_p)
|| m_temporal->current_p (name, m_gori.depend1 (name),
m_gori.depend2 (name));
else
- m_globals.set_global_range (name, r);
+ {
+ // If no global value has been set and value is VARYING, fold the stmt
+ // using just global ranges to get a better initial value.
+ // After inlining we tend to decide some things are constant, so
+ // do not do this evaluation after inlining.
+ if (r.varying_p () && !cfun->after_inlining)
+ {
+ gimple *s = SSA_NAME_DEF_STMT (name);
+ if (gimple_get_lhs (s) == name)
+ {
+ if (!fold_range (r, s, get_global_range_query ()))
+ gimple_range_global (r, name);
+ }
+ }
+ m_globals.set_global_range (name, r);
+ }
// If the existing value was not current, mark it as always current.
if (!current_p)
new file mode 100644
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+static int a, b;
+
+void foo();
+
+int main() {
+ for (int c = 0; c < 2; c = c + (unsigned)3)
+ if (a)
+ for (;;)
+ if (c > 0)
+ b = 0;
+ if (b)
+ foo();
+}
+/* { dg-final { scan-tree-dump-not "foo" "optimized" } } */
--
2.41.0