From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 0D3E9385558F; Thu, 16 Feb 2023 14:35:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0D3E9385558F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676558145; bh=oS/+LavPCBczukQmZXWW4dJS3UkguTdRYlmnAUTJdSo=; h=From:To:Subject:Date:From; b=X8DSHgAfgfo/MeWdCZEkCHbhzwfepuXKJOABhwCqp+4/pChiKY13Ogrva5HuGSI88 AQ7AtaQYoUchduqi3gkjDDIGnz6xxRowc7tTDc2bZTOM9ib3tUgfNrvLQ8/5Eqmgak Lw5htOuSSK+Rnz9CQLAgDoDwIysgEqNuTXRXJW2M= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-6083] tree-ssa-dse: Fix up handling of lhs of internal calls [PR108657] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 7478278f88ba1753e68d6962b7f38d1be5b43d56 X-Git-Newrev: 866555b170016c49beb869a78cbecdeb07c63135 Message-Id: <20230216143545.0D3E9385558F@sourceware.org> Date: Thu, 16 Feb 2023 14:35:45 +0000 (GMT) List-Id: https://gcc.gnu.org/g:866555b170016c49beb869a78cbecdeb07c63135 commit r13-6083-g866555b170016c49beb869a78cbecdeb07c63135 Author: Jakub Jelinek Date: Thu Feb 16 15:35:05 2023 +0100 tree-ssa-dse: Fix up handling of lhs of internal calls [PR108657] The r13-1778 PR106378 tree-ssa-dse change didn't just add special support for IFN_LEN_STORE and IFN_MASK_STORE internal function calls as I believe was intended, but given that the function was if (is builtin) { ... } else if (lhs present and non-SSA_NAME) { ... } return false; and it added a new else if (is internal builtin) { ... } in between the two, the last if used to be done before on all stmts with non-SSA_NAME lhs except for calls to builtin functions, but newly isn't done also for calls to internal functions. In the testcase the important internal function is .DEFERRED_INIT, which often has non-SSA_NAME lhs, and the change resulted in them no longer being DSEd, so a block with nothing in it left but var = .DEFERRED_INIT () and var = {CLOBBER} was unrolled several times. The following patch does the lhs handling for all stmts with non-SSA_NAME lhs unless initialize_ao_ref_for_dse handled those specially already and returned (which is the case for various mem* builtins which don't have such lhs, for some cases of calloc which again is fine,and since r13-1778 also for IFN_LEN_STORE call and some IFN_MASK_STORE calls. As IFN_MASK_STORE doesn't have a lhs, the break for the !may_def_ok case doesn't seem to change anything, and because we've handled internal fns that way in the past, I think it is the right thing to do that again. That said, if it is inappropriate for some new ifn, I guess it could be added to the switch and just return false; for it instead of break;. 2023-02-16 Jakub Jelinek PR tree-optimization/108657 * tree-ssa-dse.cc (initialize_ao_ref_for_dse): If lhs of stmt exists and is not a SSA_NAME, call ao_ref_init even if the stmt is a call to internal or builtin function. * gcc.dg/pr108657.c: New test. Diff: --- gcc/testsuite/gcc.dg/pr108657.c | 31 +++++++++++++++++++++++++++++++ gcc/tree-ssa-dse.cc | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/gcc.dg/pr108657.c b/gcc/testsuite/gcc.dg/pr108657.c new file mode 100644 index 00000000000..37d0b8e863f --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr108657.c @@ -0,0 +1,31 @@ +/* PR tree-optimization/108657 */ +/* { dg-do run } */ +/* { dg-options "-O3 -ftrivial-auto-var-init=zero" } */ + +int c, e, f; +static int *d = &c; + +__attribute__((noipa)) void +foo (void) +{ + if (c != 1) + __builtin_abort (); +} + +int +main () +{ + for (c = 1; c >= 0; c--) + { + e = 0; + for (int j = 0; j <= 2; j++) + { + short k[1]; + if (e) + break; + e ^= f; + } + } + *d = 1; + foo (); +} diff --git a/gcc/tree-ssa-dse.cc b/gcc/tree-ssa-dse.cc index 46ab57d5754..4f8a44fbba0 100644 --- a/gcc/tree-ssa-dse.cc +++ b/gcc/tree-ssa-dse.cc @@ -177,7 +177,7 @@ initialize_ao_ref_for_dse (gimple *stmt, ao_ref *write, bool may_def_ok = false) default:; } } - else if (tree lhs = gimple_get_lhs (stmt)) + if (tree lhs = gimple_get_lhs (stmt)) { if (TREE_CODE (lhs) != SSA_NAME) {