From patchwork Thu Jul 21 09:05:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 101 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e252:0:0:0:0:0 with SMTP id bl18csp1344129wrb; Thu, 21 Jul 2022 02:06:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ugJRE1Y6n7SAlLzF6S5mPUR2OA83qrFCnaQdemy+cx4ppI+iQZSP4+6XLGatJ8JnzDspP6 X-Received: by 2002:a17:907:271b:b0:72b:64f0:e508 with SMTP id w27-20020a170907271b00b0072b64f0e508mr40531390ejk.275.1658394398429; Thu, 21 Jul 2022 02:06:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658394398; cv=none; d=google.com; s=arc-20160816; b=tqIzcRNLmM42IgG/6PLU2MNwGi2ZW8ah6RQYnll3KoDkjxAls0Zvs6/mP9vcD4bA+P VidMmIFY8RHXclcreMF7sRfa5aaREx3Ltjf7jsygsMRwz8kzRkDrb62TQIgZqHSIJbHi IUKaLUvXLn37E4astGWVjwH2DQNz9x4xw8kJ/HjG4cDOvn4VL0reCR3yN4ZTN6TInCK4 n3adQMGeE0V1FX0URa/xReLseCkcV/5chSQLTNnt2TSEfRxIvrqJQ44CSgNnhQMcb0ZD SyvcfWQrzlj0PZPdFTPqO0+RI4bXG92kfuuQq3Pxa0EgnjmWe9hdkH+/RpPWLK+HCzFz gdiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :message-id:mime-version:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=O04JAuzujM6Iw0CqJLJYFursfSRYh3p0iiCnxdvVi6g=; b=p8d+B7O4a6M2ZIG861mqAwJ1sbA/duCkVKsDTCvshP9RkxAi7CeQNxG2mYnT+YQgA0 ozUtHKPLYsL+KWv8duSoJLGWbR2qxiq1IEWJyEbaigI6kT1lDaOm8WtqWFMqh7+Mwk9Q gFcgB2wAmc5/WllqhwsaRGW5JmoSkhe2WZz2Cc/ZAnP0cvcw4VHDV0WtVVkMtYZOho93 k3DJcN3bX1qT3w7ht/uNTEf6aYn59+PCCEV6qW2lv6C8kwJFEb0VgJ8+J/1kQIEWNZY7 kXx9kQ4wqgHFPRLF8RxMMn+2KJU4LgDPgwcrsZIIHRL91BT8H9XO23NxmPBJ0DSohu8G bwLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rseT6J3f; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id h6-20020a056402280600b0043acab6b407si1887252ede.424.2022.07.21.02.06.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 02:06:38 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rseT6J3f; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 0281D3858C2F for ; Thu, 21 Jul 2022 09:06:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0281D3858C2F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1658394397; bh=O04JAuzujM6Iw0CqJLJYFursfSRYh3p0iiCnxdvVi6g=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=rseT6J3f6ZQ8PjTWEAq5GVlVo2SlQMqvwLzXtRyvbVP6puqxjLcnejPmZ3DsVDtAt L/QzNPIut2CmUmR2pJQzWS8+rhAL5AuSB0pOMlfXDig48DVrPCpshJR2nF04QrVh+u aPWvA0OJMRIdCuNgEkfGW+iE4QTIWCuzEu/bTkv0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 866933858D28 for ; Thu, 21 Jul 2022 09:05:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 866933858D28 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 8C2C920FDB; Thu, 21 Jul 2022 09:05:53 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6DCFD13A1B; Thu, 21 Jul 2022 09:05:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id otxkGfEW2WJuLAAAMHmgww (envelope-from ); Thu, 21 Jul 2022 09:05:53 +0000 Date: Thu, 21 Jul 2022 11:05:53 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/106365 - DSE of LEN_STORE and MASK_STORE MIME-Version: 1.0 Message-Id: <20220721090553.6DCFD13A1B@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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: Richard Biener via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: Richard Biener Cc: richard.sandiford@arm.com 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?1738952564662185710?= X-GMAIL-MSGID: =?utf-8?q?1738952564662185710?= The following enhances DSE to handle LEN_STORE (optimally) and MASK_STORE (conservatively). Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. Kewen is testing on powerpc. Handling MASK_STORE_LANES in a similar way to MASK_STORE is probably possible but I couldn't figure a way to generate one for testing. STORE_LANES is probably handled already since it's ECF_CONST. PR tree-optimization/106365 * tree-ssa-dse.cc (initialize_ao_ref_for_dse): Handle LEN_STORE, add mode to initialize a may-def and handle MASK_STORE that way. (dse_optimize_stmt): Query may-defs. Handle internal functions LEN_STORE and MASK_STORE similar to how we handle memory builtins but without byte tracking. --- gcc/tree-ssa-dse.cc | 55 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/gcc/tree-ssa-dse.cc b/gcc/tree-ssa-dse.cc index 8d1739a4510..34cfd1a8802 100644 --- a/gcc/tree-ssa-dse.cc +++ b/gcc/tree-ssa-dse.cc @@ -93,7 +93,9 @@ static bitmap need_eh_cleanup; static bitmap need_ab_cleanup; /* STMT is a statement that may write into memory. Analyze it and - initialize WRITE to describe how STMT affects memory. + initialize WRITE to describe how STMT affects memory. When + MAY_DEF_OK is true then the function initializes WRITE to what + the stmt may define. Return TRUE if the statement was analyzed, FALSE otherwise. @@ -101,7 +103,7 @@ static bitmap need_ab_cleanup; can be achieved by analyzing more statements. */ static bool -initialize_ao_ref_for_dse (gimple *stmt, ao_ref *write) +initialize_ao_ref_for_dse (gimple *stmt, ao_ref *write, bool may_def_ok = false) { /* It's advantageous to handle certain mem* functions. */ if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) @@ -146,6 +148,32 @@ initialize_ao_ref_for_dse (gimple *stmt, ao_ref *write) break; } } + else if (is_gimple_call (stmt) + && gimple_call_internal_p (stmt)) + { + switch (gimple_call_internal_fn (stmt)) + { + case IFN_LEN_STORE: + ao_ref_init_from_ptr_and_size + (write, gimple_call_arg (stmt, 0), + int_const_binop (MINUS_EXPR, + gimple_call_arg (stmt, 2), + gimple_call_arg (stmt, 4))); + return true; + case IFN_MASK_STORE: + /* We cannot initialize a must-def ao_ref (in all cases) but we + can provide a may-def variant. */ + if (may_def_ok) + { + ao_ref_init_from_ptr_and_size + (write, gimple_call_arg (stmt, 0), + TYPE_SIZE_UNIT (TREE_TYPE (gimple_call_arg (stmt, 2)))); + return true; + } + break; + default:; + } + } else if (tree lhs = gimple_get_lhs (stmt)) { if (TREE_CODE (lhs) != SSA_NAME) @@ -1328,8 +1356,10 @@ dse_optimize_stmt (function *fun, gimple_stmt_iterator *gsi, sbitmap live_bytes) ao_ref ref; /* If this is not a store we can still remove dead call using - modref summary. */ - if (!initialize_ao_ref_for_dse (stmt, &ref)) + modref summary. Note we specifically allow ref to be initialized + to a conservative may-def since we are looking for followup stores + to kill all of it. */ + if (!initialize_ao_ref_for_dse (stmt, &ref, true)) { dse_optimize_call (gsi, live_bytes); return; @@ -1398,6 +1428,23 @@ dse_optimize_stmt (function *fun, gimple_stmt_iterator *gsi, sbitmap live_bytes) return; } } + else if (is_gimple_call (stmt) + && gimple_call_internal_p (stmt)) + { + switch (gimple_call_internal_fn (stmt)) + { + case IFN_LEN_STORE: + case IFN_MASK_STORE: + { + enum dse_store_status store_status; + store_status = dse_classify_store (&ref, stmt, false, live_bytes); + if (store_status == DSE_STORE_DEAD) + delete_dead_or_redundant_call (gsi, "dead"); + return; + } + default:; + } + } bool by_clobber_p = false;