* [PATCH][GCC13] PR tree-optimization/105834 - Choose better initial values for ranger.
@ 2023-11-06 18:15 Andrew MacLeod
2023-11-07 8:27 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Andrew MacLeod @ 2023-11-06 18:15 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 167 bytes --]
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
[-- Attachment #2: 0001-Choose-better-initial-values-for-ranger.patch --]
[-- Type: text/x-patch, Size: 2342 bytes --]
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
diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc
index e4e75943632..b09df6c81bf 100644
--- a/gcc/gimple-range-cache.cc
+++ b/gcc/gimple-range-cache.cc
@@ -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)
diff --git a/gcc/testsuite/gcc.dg/pr105834.c b/gcc/testsuite/gcc.dg/pr105834.c
new file mode 100644
index 00000000000..d0eda03ef8b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr105834.c
@@ -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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH][GCC13] PR tree-optimization/105834 - Choose better initial values for ranger.
2023-11-06 18:15 [PATCH][GCC13] PR tree-optimization/105834 - Choose better initial values for ranger Andrew MacLeod
@ 2023-11-07 8:27 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-11-07 8:27 UTC (permalink / raw)
To: Andrew MacLeod; +Cc: gcc-patches
On Mon, Nov 6, 2023 at 7:15 PM Andrew MacLeod <amacleod@redhat.com> wrote:
>
> 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?
The change caused PR110540 on trunk (still unfixed). I don't think we want to
trade one missed optimization regression for another on the branch.
Thanks,
Richard.
> Andrew
>
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-11-07 8:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-06 18:15 [PATCH][GCC13] PR tree-optimization/105834 - Choose better initial values for ranger Andrew MacLeod
2023-11-07 8:27 ` Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).