From patchwork Tue Feb 7 13:38:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 64451 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 26AAD3858C50 for ; Tue, 7 Feb 2023 13:39:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26AAD3858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675777140; bh=vKtBYytqNTqDDHED7mA1Qdl2BQWLbcCwCOoVxjvozac=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=XD7B3yTTEfUMHRGEz0CfGV6ez5IqwhT6h9byBSjg4OW2tqzHxneTa1TOfQwkMxlKc OXTgXT2snDVq5VIho+T94XqR7AonBIoL6U7FHAMcdC2h950/OVTxpa39Ny8K2sDteM QHMghQQRmCaKxWrllJtok9yOhSEZcVRtUmVBpH4E= 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 [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id EC3EB3858D33 for ; Tue, 7 Feb 2023 13:38:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EC3EB3858D33 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 C9207202B8 for ; Tue, 7 Feb 2023 13:38:28 +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 B735D139ED for ; Tue, 7 Feb 2023 13:38:28 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id fGOwK1RU4mPmdgAAMHmgww (envelope-from ) for ; Tue, 07 Feb 2023 13:38:28 +0000 Date: Tue, 7 Feb 2023 14:38:28 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/26854 - compile-time hog in SSA forwprop MIME-Version: 1.0 Message-Id: <20230207133828.B735D139ED@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.8 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: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The following addresses tree forward propagate : 12.41 ( 9%) seen with the compile.i testcase of this PR which points at the has_use_on_stmt function which, for SSA names with many uses is slow. The solution is to instead of immediate uses, look at stmt operands to identify whether a name has a use on a stmt. That improves SSA forwprop to tree forward propagate : 1.30 ( 0%) for this testcase. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/26854 * gimple-fold.cc (has_use_on_stmt): Look at stmt operands instead of immediate uses. --- gcc/gimple-fold.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index 379d2e930ea..935e8006413 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -5767,15 +5767,17 @@ gimple_fold_call (gimple_stmt_iterator *gsi, bool inplace) } -/* Return true whether NAME has a use on STMT. */ +/* Return true whether NAME has a use on STMT. Note this can return + false even though there's a use on STMT if SSA operands are not + up-to-date. */ static bool has_use_on_stmt (tree name, gimple *stmt) { - imm_use_iterator iter; - use_operand_p use_p; - FOR_EACH_IMM_USE_FAST (use_p, iter, name) - if (USE_STMT (use_p) == stmt) + ssa_op_iter iter; + tree op; + FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_USE) + if (op == name) return true; return false; }