From: Richard Biener Date: Mon, 4 Jan 2021 10:40:40 +0000 (+0100) Subject: tree-optimization/98282 - classify V_C_E as nary X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=13b80a7d1b9b712651f5ece589634a6e57c26362;p=gcc.git tree-optimization/98282 - classify V_C_E as nary This avoids running into memory reference code in compute_avail by properly classifying unfolded reference trees on constants. 2021-01-04 Richard Biener PR tree-optimization/98282 * tree-ssa-sccvn.c (vn_get_stmt_kind): Classify tcc_reference on invariants as VN_NARY. * g++.dg/opt/pr98282.C: New testcase. --- diff --git a/gcc/testsuite/g++.dg/opt/pr98282.C b/gcc/testsuite/g++.dg/opt/pr98282.C new file mode 100644 index 00000000000..545084104d5 --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/pr98282.C @@ -0,0 +1,80 @@ +// PR tree-optimization/98282 +// { dg-do compile { target c++11 } } +// { dg-options "-O2" } + +template struct g; +template struct g { typedef b c; }; +template typename g::c &&d(b &&e) { + return static_cast::c &&>(e); +} +void *operator new(__SIZE_TYPE__, void *f) { return f; } +struct h; +struct k { + using i = h *; +}; +struct D { + k::i j; +}; +struct p : D { + p(p &&) : D() {} +}; +struct r { + using l = int; + r(r &&) : ad() {} + l *ad; +}; +struct s { + static s m(); +}; +struct t { + template void operator=(ah); +}; +struct I { + template void q(o ai) { + *ai = aj(); + s::m(); + } + h aj(); +}; +template class as; +struct J { + int a; + char av; +}; +template struct aw : J { + void ax(...) {} +}; +template +struct aw, an, n...> : aw, n...> { + using az = as; + using ba = aw; + char bb; + an &bc() { return *reinterpret_cast(this); } + void ax(az *bd) { + if (bb) + new (bd) an(d(bc())); + ba::ax(bd); + } +}; +template struct as : aw, n...> { + as(); + as(as &&be) { be.ax(this); } + void operator=(as be) { be.ax(this); } +}; +struct h { + as bg; +}; +using bh = t; +struct u { + bh bj; +}; +I bk(); +template void bl() { + h a; + bk().q(&a); +} +template void bn(int) { + u b; + b.bj = bl; +} +void bp() { bn(0); } diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index d944b9565ac..19defc0cccc 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -543,7 +543,8 @@ vn_get_stmt_kind (gimple *stmt) || code == IMAGPART_EXPR || code == VIEW_CONVERT_EXPR || code == BIT_FIELD_REF) - && TREE_CODE (TREE_OPERAND (rhs1, 0)) == SSA_NAME) + && (TREE_CODE (TREE_OPERAND (rhs1, 0)) == SSA_NAME + || is_gimple_min_invariant (TREE_OPERAND (rhs1, 0)))) return VN_NARY; /* Fallthrough. */