public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-6834] tree-optimization/107569 - avoid wrecking earlier folding in FRE/PRE
@ 2023-03-23 16:22 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-03-23 16:22 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:41ade3399bd1ec9927be1bb818965831232eda4b
commit r13-6834-g41ade3399bd1ec9927be1bb818965831232eda4b
Author: Richard Biener <rguenther@suse.de>
Date: Thu Mar 23 14:52:01 2023 +0100
tree-optimization/107569 - avoid wrecking earlier folding in FRE/PRE
The following avoids picking up dead code left over from folding
during FRE/PRE, effectively undoing propagations.
PR tree-optimization/107569
* tree-ssa-sccvn.cc (eliminate_dom_walker::eliminate_stmt):
Do not push SSA names with zero uses as available leader.
(process_bb): Likewise.
* g++.dg/opt/pr107569.C: New testcase.
Diff:
---
gcc/testsuite/g++.dg/opt/pr107569.C | 29 +++++++++++++++++++++++++++++
gcc/tree-ssa-sccvn.cc | 17 +++++++++++------
2 files changed, 40 insertions(+), 6 deletions(-)
diff --git a/gcc/testsuite/g++.dg/opt/pr107569.C b/gcc/testsuite/g++.dg/opt/pr107569.C
new file mode 100644
index 00000000000..e03941c7862
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/pr107569.C
@@ -0,0 +1,29 @@
+// { dg-do compile }
+// { dg-require-effective-target c++20 }
+// { dg-options "-O2 -fdump-tree-evrp -fdump-tree-vrp1" }
+
+namespace std
+{
+ constexpr bool isfinite (float x) { return __builtin_isfinite (x); }
+ constexpr bool isfinite (double x) { return __builtin_isfinite (x); }
+ constexpr bool isfinite (long double x) { return __builtin_isfinite (x); }
+}
+
+bool
+foo (double x)
+{
+ if (!std::isfinite (x))
+ __builtin_unreachable ();
+
+ return std::isfinite (x);
+}
+
+bool
+bar (double x)
+{
+ [[assume (std::isfinite (x))]];
+ return std::isfinite (x);
+}
+
+/* { dg-final { scan-tree-dump "return 1;" "evrp" } } */
+/* { dg-final { scan-tree-dump-times "return 1;" 2 "vrp1" } } */
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index d5b081a309f..6b8d38b270c 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -7197,10 +7197,14 @@ eliminate_dom_walker::eliminate_stmt (basic_block b, gimple_stmt_iterator *gsi)
}
/* Make new values available - for fully redundant LHS we
- continue with the next stmt above and skip this. */
- def_operand_p defp;
- FOR_EACH_SSA_DEF_OPERAND (defp, stmt, iter, SSA_OP_DEF)
- eliminate_push_avail (b, DEF_FROM_PTR (defp));
+ continue with the next stmt above and skip this.
+ But avoid picking up dead defs. */
+ tree def;
+ FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_DEF)
+ if (! has_zero_uses (def)
+ || (inserted_exprs
+ && bitmap_bit_p (inserted_exprs, SSA_NAME_VERSION (def))))
+ eliminate_push_avail (b, def);
}
/* Perform elimination for the basic-block B during the domwalk. */
@@ -8046,9 +8050,10 @@ process_bb (rpo_elim &avail, basic_block bb,
avail.eliminate_stmt (bb, &gsi);
else
/* If not eliminating, make all not already available defs
- available. */
+ available. But avoid picking up dead defs. */
FOR_EACH_SSA_TREE_OPERAND (op, gsi_stmt (gsi), i, SSA_OP_DEF)
- if (! avail.eliminate_avail (bb, op))
+ if (! has_zero_uses (op)
+ && ! avail.eliminate_avail (bb, op))
avail.eliminate_push_avail (bb, op);
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-03-23 16:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-23 16:22 [gcc r13-6834] tree-optimization/107569 - avoid wrecking earlier folding in FRE/PRE 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).