public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-7408] tree-optimization/104700 - adjust constant handling in PRE
@ 2022-02-28 9:34 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2022-02-28 9:34 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:37b583b9d7719f663656ce65ac822c11471fb540
commit r12-7408-g37b583b9d7719f663656ce65ac822c11471fb540
Author: Richard Biener <rguenther@suse.de>
Date: Mon Feb 28 08:36:25 2022 +0100
tree-optimization/104700 - adjust constant handling in PRE
The following refactors find_or_generate_expression to more properly
handle constant valued SSA names thereby simplifying the code and
avoiding ICEing after the last change to NARY processing.
2022-02-28 Richard Biener <rguenther@suse.de>
PR tree-optimization/104700
* tree-ssa-pre.cc (get_or_alloc_expr_for): Remove and inline
into ...
(find_or_generate_expression): ... here, simplifying code.
* gcc.dg/pr104700-2.c: New testcase.
* gcc.dg/torture/pr104700-1.c: Likewise.
Diff:
---
gcc/testsuite/gcc.dg/pr104700-2.c | 21 +++++++++++++++++
gcc/testsuite/gcc.dg/torture/pr104700-1.c | 38 +++++++++++++++++++++++++++++++
gcc/tree-ssa-pre.cc | 26 +++++++++------------
3 files changed, 70 insertions(+), 15 deletions(-)
diff --git a/gcc/testsuite/gcc.dg/pr104700-2.c b/gcc/testsuite/gcc.dg/pr104700-2.c
new file mode 100644
index 00000000000..e0759cca70f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr104700-2.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-tree-ccp -fno-tree-dce -fno-tree-vrp" } */
+
+int a, b;
+int main() {
+ int c = 2, d, e = 0;
+ if (a)
+ e = 2;
+ int f, g = -(1L | (e && f && f & e));
+ if (g)
+ L:
+ g = c;
+ c = 0;
+ d = e * g;
+ if (d)
+ goto L;
+ while (e) {
+ int i = (a && b) * i;
+ }
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/torture/pr104700-1.c b/gcc/testsuite/gcc.dg/torture/pr104700-1.c
new file mode 100644
index 00000000000..7b864d6628b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr104700-1.c
@@ -0,0 +1,38 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-ftree-pre" } */
+
+int printf(const char *, ...);
+int a, b, c = 2, d, e, *f, g;
+void o() {
+ unsigned h = 1;
+ int j = -1, k, l = 1, m = 2, i;
+ while (c < 2)
+ ;
+L1:
+ k = h;
+ h = -1;
+ if (k < 2 && !c) {
+ printf("%d", k);
+ goto L1;
+ }
+ if (!j)
+ l = printf("0");
+ if (g)
+ k = 0;
+ if (a && k)
+ goto L2;
+ while (f) {
+ m = a;
+ d = i;
+ i = e;
+ f = &j;
+ L2:
+ if (d == l && !m)
+ l = b;
+ }
+ unsigned *n[1] = {&h};
+}
+int main() {
+ o();
+ return 0;
+}
diff --git a/gcc/tree-ssa-pre.cc b/gcc/tree-ssa-pre.cc
index d6c83a72dd8..ca034ff7153 100644
--- a/gcc/tree-ssa-pre.cc
+++ b/gcc/tree-ssa-pre.cc
@@ -1197,18 +1197,6 @@ get_or_alloc_expr_for_constant (tree constant)
return newexpr;
}
-/* Get or allocate a pre_expr for a piece of GIMPLE, and return it.
- Currently only supports constants and SSA_NAMES. */
-static pre_expr
-get_or_alloc_expr_for (tree t)
-{
- if (TREE_CODE (t) == SSA_NAME)
- return get_or_alloc_expr_for_name (t);
- else if (is_gimple_min_invariant (t))
- return get_or_alloc_expr_for_constant (t);
- gcc_unreachable ();
-}
-
/* Return the folded version of T if T, when folded, is a gimple
min_invariant or an SSA name. Otherwise, return T. */
@@ -2779,8 +2767,16 @@ create_component_ref_by_pieces (basic_block block, vn_reference_t ref,
static tree
find_or_generate_expression (basic_block block, tree op, gimple_seq *stmts)
{
- pre_expr expr = get_or_alloc_expr_for (op);
- unsigned int lookfor = get_expr_value_id (expr);
+ /* Constants are always leaders. */
+ if (is_gimple_min_invariant (op))
+ return op;
+
+ gcc_assert (TREE_CODE (op) == SSA_NAME);
+ vn_ssa_aux_t info = VN_INFO (op);
+ unsigned int lookfor = info->value_id;
+ if (value_id_constant_p (lookfor))
+ return info->valnum;
+
pre_expr leader = bitmap_find_leader (AVAIL_OUT (block), lookfor);
if (leader)
{
@@ -2808,7 +2804,7 @@ find_or_generate_expression (basic_block block, tree op, gimple_seq *stmts)
its operand values. */
if (temp->kind == NARY)
return create_expression_by_pieces (block, temp, stmts,
- get_expr_type (expr));
+ TREE_TYPE (op));
}
/* Defer. */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-02-28 9:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-28 9:34 [gcc r12-7408] tree-optimization/104700 - adjust constant handling in 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).