From patchwork Thu Feb 16 08:56:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 57926 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp188231wrn; Thu, 16 Feb 2023 00:57:42 -0800 (PST) X-Google-Smtp-Source: AK7set9iqMkUjut1zfpOT3SulyCZvRJoiDdfzGmb0KMonvpRv1ErJ/O2MhZe1PUDI8BtxXttxJM0 X-Received: by 2002:a17:907:72c1:b0:8b1:7569:ad58 with SMTP id du1-20020a17090772c100b008b17569ad58mr132227ejc.2.1676537862564; Thu, 16 Feb 2023 00:57:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676537862; cv=none; d=google.com; s=arc-20160816; b=P4sLXypGlyx05OktLj4mTznbNDfaeT5YcQFp38hz+5P2gKqEvHZG1i/pWj0K6dcUTD aNXXA5pKZ6jA9hnka/H3dRgsjFq9yqlyvwuCfGkcE9jalBj6RfV7vXsdMu1bbabOxTBj JHFG4iOxzaVsxrtnKrDRecPAyyN/HjmGLpIFCa0PgXC6oNGrdwJyNuXwZbT9mKqAEd4t yq7nCLbo6HSS6jWYGUiA8xHnJdRC5GglVmnXoPi6wTYTohCc8gQM/fVG6kwzLCLeUrrl uJdJMrd3uikN1qtlqASftP/CQ4XUY56cPlFEoVeqeFllo6EvVGQFtTRN4qksezRHt8YZ X9uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=nWzMk9OTHSRm9kwLGXLH8jZv9SIA/rzb8Yf68yF9WVA=; b=clitZGrNCW8g/TycP7MkpYH5saTDEyAx8kYno7njzfKTh54lQuRWCiBc2Hzvuyd+A4 QDmB1aipC4gTGH/J4aGloGg8N7af/RtQedNJKEtjnFgVxigImKbTx6hGUp1DA0orD0j3 n+PW3yFBM2UpERTH/A+GemeBi+aXfIoghpcYSub3UYpo908ph+d9934CYETem3/j2/wL 5aXy6LD52O6AKtbPLf0ZMTdes4V0Rg1xmQI2qe5/w1qIWTmFaStuzLomr5Am+LtQpVHm prvPD0phJcN7yHASGhJNkTzvlCvPAB2YqpKXn2TdEp342dnFqBhrPG5zdgTwSGkmeH3Z WrTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jYGBfUAk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id uj42-20020a170907c9aa00b008b1412e2558si1307696ejc.190.2023.02.16.00.57.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 00:57:42 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jYGBfUAk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ADE3F3858C60 for ; Thu, 16 Feb 2023 08:57:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ADE3F3858C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676537859; bh=nWzMk9OTHSRm9kwLGXLH8jZv9SIA/rzb8Yf68yF9WVA=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=jYGBfUAk7JiUnGUXBL/UzgtKwWHUt901ZYlYaQyuTyOhRSfJzCSdX/VYuPWOiXT/m fOrRQL7sPzqJhsi9+H4HsoeI98QIe3zcyBNCm1ODZI0rpca91h+vo9it9Mog31rGru 3btekIjYQ3l/Wpxb967VJl1Kzarg9QqWdjut3iy8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 502B8385841D for ; Thu, 16 Feb 2023 08:56:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 502B8385841D Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-102-O-hTTi7ePaOrOqB-g8CiHw-1; Thu, 16 Feb 2023 03:56:51 -0500 X-MC-Unique: O-hTTi7ePaOrOqB-g8CiHw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 764CB101A521; Thu, 16 Feb 2023 08:56:51 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.193.203]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AE0662026DEF; Thu, 16 Feb 2023 08:56:49 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 31G8ulZq2901431 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 16 Feb 2023 09:56:47 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 31G8ukFg2901430; Thu, 16 Feb 2023 09:56:46 +0100 Date: Thu, 16 Feb 2023 09:56:46 +0100 To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-ssa-dse: Fix up handling of lhs of internal calls [PR108657] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757977365499136577?= X-GMAIL-MSGID: =?utf-8?q?1757977365499136577?= Hi! 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;. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? That said, while this patch fixes the regression by allowing DSE of IFN_DEFERRED_INIT again, I think we probably have some latent bug in FRE where without this patch it seems to be fre5 that sees one unconditional c = 1; store, one conditional c = 0; store and in the last bb before return another c = 1; store and decides that the last store is redundant, which is not the case, the first two stores are redundant or if they can't be removed, none of them is. Richard, could you please have a look? 2023-02-15 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. Jakub --- gcc/tree-ssa-dse.cc.jj 2023-01-11 10:29:08.651161134 +0100 +++ gcc/tree-ssa-dse.cc 2023-02-15 20:03:33.647684713 +0100 @@ -177,7 +177,7 @@ initialize_ao_ref_for_dse (gimple *stmt, default:; } } - else if (tree lhs = gimple_get_lhs (stmt)) + if (tree lhs = gimple_get_lhs (stmt)) { if (TREE_CODE (lhs) != SSA_NAME) { --- gcc/testsuite/gcc.dg/pr108657.c.jj 2023-02-15 20:11:22.038804168 +0100 +++ gcc/testsuite/gcc.dg/pr108657.c 2023-02-15 20:10:37.992451199 +0100 @@ -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 (); +}