aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2022-02-28 08:36:25 +0100
committerRichard Biener <rguenther@suse.de>2022-02-28 10:34:25 +0100
commit37b583b9d7719f663656ce65ac822c11471fb540 (patch)
tree688009606fb37efc520d70c7b49e75c4154c1c64 /gcc
parentf485b0ed7d06482d2f212ff0d9f5519a4f2c9a15 (diff)
downloadgcc-37b583b9d7719f663656ce65ac822c11471fb540.zip
gcc-37b583b9d7719f663656ce65ac822c11471fb540.tar.gz
gcc-37b583b9d7719f663656ce65ac822c11471fb540.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/gcc.dg/pr104700-2.c21
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr104700-1.c38
-rw-r--r--gcc/tree-ssa-pre.cc26
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 0000000..e0759cc
--- /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 0000000..7b864d6
--- /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 d6c83a7..ca034ff 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. */