From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id E31F3385AC29; Mon, 30 Jan 2023 09:51:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E31F3385AC29 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675072276; bh=ZI6YWA/ZjZrjcHzYgLvGF910V6ARw24ysi4ayhujYZA=; h=From:To:Subject:Date:From; b=kD2hcQiNVJRL4dldUa2k/BaFW4c/1/96WmQqJ81Jkz1quyUb+WgZV7LvRwUwAHzGn GKt8ehOKBsCa3u/+2u+doZ9KGulC09zHpnLYRmkFOVPKQclkCnw9q2UHjpDQIRDd8Y AfFTCssNQEHCK2JRtmHRJghy79LEIKLXPnh/jap4= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5492] tree-optimization/108574 - wrong-code with PRE PHI node processing X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: 3cd08f7168c196d7a481b9ed9f4289fd1f14eea8 X-Git-Newrev: 7ac3e69e311351b70407d7f87a0169c4d463e57b Message-Id: <20230130095116.E31F3385AC29@sourceware.org> Date: Mon, 30 Jan 2023 09:51:16 +0000 (GMT) List-Id: https://gcc.gnu.org/g:7ac3e69e311351b70407d7f87a0169c4d463e57b commit r13-5492-g7ac3e69e311351b70407d7f87a0169c4d463e57b Author: Richard Biener Date: Mon Jan 30 09:25:23 2023 +0100 tree-optimization/108574 - wrong-code with PRE PHI node processing The PR108523 was too optimistic in replacing the same value with an equivalence from a possibly not taken edge. The following rectifies this and instead refrains from using the equivalence in the problematic cases. PR tree-optimization/108574 * tree-ssa-sccvn.cc (visit_phi): Instead of swapping sameval and def, ignore the equivalence if there's the danger of oscillating between two values. * gcc.dg/torture/pr108574-1.c: New testcase. * gcc.dg/torture/pr108574-2.c: Likewise. * gcc.dg/torture/pr108574-3.c: Likewise. Diff: --- gcc/testsuite/gcc.dg/torture/pr108574-1.c | 19 +++++++++++++++++++ gcc/testsuite/gcc.dg/torture/pr108574-2.c | 25 +++++++++++++++++++++++++ gcc/testsuite/gcc.dg/torture/pr108574-3.c | 27 +++++++++++++++++++++++++++ gcc/tree-ssa-sccvn.cc | 11 +++++------ 4 files changed, 76 insertions(+), 6 deletions(-) diff --git a/gcc/testsuite/gcc.dg/torture/pr108574-1.c b/gcc/testsuite/gcc.dg/torture/pr108574-1.c new file mode 100644 index 00000000000..7066b5ee2a2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr108574-1.c @@ -0,0 +1,19 @@ +/* { dg-do run } */ + +int a = 1, b, c = 2, d; +int main() { + if (b) + goto L2; + L1: + { + int e = c; + a = 1 % a; + while (e && 1 <= d) + ; + d >= b; + L2: + if (1 >= e) + goto L1; + } + return 0; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr108574-2.c b/gcc/testsuite/gcc.dg/torture/pr108574-2.c new file mode 100644 index 00000000000..1e38d087646 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr108574-2.c @@ -0,0 +1,25 @@ +/* { dg-do run } */ + +int a, b, c, d, e, f, g = -1, h; +void l() { + if (!e) + goto i; + for (; g; g++) { + b = ~d; + int j = 0, k = 1; + if (k && (b || f)) + j = b; + i: + a = ~j; + } +} +int main() { + h = 3; + for (; h; h--) { + e = 1; + int m = ~a, n = 1 % m; + c = n; + l(); + } + return 0; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr108574-3.c b/gcc/testsuite/gcc.dg/torture/pr108574-3.c new file mode 100644 index 00000000000..3c9146e31ac --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr108574-3.c @@ -0,0 +1,27 @@ +/* { dg-do run } */ + +int a = 3557301289, d; +char b, f; +unsigned short c = 241; +short e, g; +static void h() { + if (!a) + goto i; + b = a; + for (; a < 2; a = b) { + unsigned short j; + if (c || !g) { + j = c; + i: + e = j; + } + f = j; + d = ~(f & ~2880764155); + while (d > -2316069) + ; + } +} +int main() { + h(); + return 0; +} diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index edb553b07cb..028bedbc9a0 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -5908,7 +5908,8 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p) if (! val && vnresult && vnresult->predicated_values) { val = vn_nary_op_get_predicated_value (vnresult, e->src); - if (val && integer_truep (val)) + if (val && integer_truep (val) + && !(sameval_e && (sameval_e->flags & EDGE_DFS_BACK))) { if (dump_file && (dump_flags & TDF_DETAILS)) { @@ -5919,8 +5920,6 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p) fprintf (dump_file, " are equal on edge %d -> %d\n", e->src->index, e->dest->index); } - if (sameval_e && (sameval_e->flags & EDGE_DFS_BACK)) - sameval = def; continue; } /* If on all previous edges the value was equal to def @@ -5928,7 +5927,8 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p) if (EDGE_COUNT (bb->preds) == 2 && (val = vn_nary_op_get_predicated_value (vnresult, EDGE_PRED (bb, 0)->src)) - && integer_truep (val)) + && integer_truep (val) + && !(e->flags & EDGE_DFS_BACK)) { if (dump_file && (dump_flags & TDF_DETAILS)) { @@ -5940,8 +5940,7 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p) EDGE_PRED (bb, 0)->src->index, EDGE_PRED (bb, 0)->dest->index); } - if (!(e->flags & EDGE_DFS_BACK)) - sameval = def; + sameval = def; continue; } }