diff options
author | Richard Biener <rguenther@suse.de> | 2025-02-17 11:40:01 +0100 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2025-02-17 14:41:25 +0100 |
commit | dfd0ced98fcf62c4d24979b74c1d52334ff62bfc (patch) | |
tree | b69eadd3c48d54da47fa316559f13333a3b30c83 | |
parent | 230678c19cb5e2f8a4855b9790794042fc6ad068 (diff) | |
download | gcc-dfd0ced98fcf62c4d24979b74c1d52334ff62bfc.zip gcc-dfd0ced98fcf62c4d24979b74c1d52334ff62bfc.tar.gz gcc-dfd0ced98fcf62c4d24979b74c1d52334ff62bfc.tar.bz2 |
tree-optimization/118895 - ICE during PRE
When we simplify a NARY during PHI translation we have to make sure
to not inject not available operands into it given that might violate
the valueization hook constraints and we'd pick up invalid
context-sensitive data in further simplification or as in this case
later ICE when we try to insert the expression.
PR tree-optimization/118895
* tree-ssa-sccvn.cc (vn_nary_build_or_lookup_1): Only allow
CSE if we can verify the result is available.
* gcc.dg/pr118895.c: New testcase.
-rw-r--r-- | gcc/testsuite/gcc.dg/pr118895.c | 13 | ||||
-rw-r--r-- | gcc/tree-ssa-sccvn.cc | 13 |
2 files changed, 21 insertions, 5 deletions
diff --git a/gcc/testsuite/gcc.dg/pr118895.c b/gcc/testsuite/gcc.dg/pr118895.c new file mode 100644 index 0000000..ca61d2c --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr118895.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +unsigned long a; +void fn1() +{ + unsigned long e = a; + int c = e; + int d = c < 100 ? c : 0; + if (d + (int)e & 608) + while (e & 608) + e <<= 1; +} diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index 8bb4578..1468406 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -366,6 +366,10 @@ static vn_ssa_aux_t last_pushed_avail; correct. */ static vn_tables_t valid_info; +/* Global RPO state for access from hooks. */ +static class eliminate_dom_walker *rpo_avail; +basic_block vn_context_bb; + /* Valueization hook for simplify_replace_tree. Valueize NAME if it is an SSA name, otherwise just return it. */ @@ -2501,7 +2505,10 @@ vn_nary_build_or_lookup_1 (gimple_match_op *res_op, bool insert, bool res = false; if (i == res_op->num_ops) { - mprts_hook = vn_lookup_simplify_result; + /* Do not leak not available operands into the simplified expression + when called from PRE context. */ + if (rpo_avail) + mprts_hook = vn_lookup_simplify_result; res = res_op->resimplify (NULL, vn_valueize); mprts_hook = NULL; } @@ -2684,10 +2691,6 @@ public: vn_avail *m_avail_freelist; }; -/* Global RPO state for access from hooks. */ -static eliminate_dom_walker *rpo_avail; -basic_block vn_context_bb; - /* Return true if BASE1 and BASE2 can be adjusted so they have the same address and adjust *OFFSET1 and *OFFSET2 accordingly. Otherwise return false. */ |