From patchwork Wed Mar 22 10:03:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 73339 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2254223wrt; Wed, 22 Mar 2023 03:04:37 -0700 (PDT) X-Google-Smtp-Source: AK7set/PeZJSpyUCHK1jB5iTCQR4s7pmFWSt2uibiFGkkL2qahbdEJ5277SH9jxFOXWMA13+NOqy X-Received: by 2002:a17:906:9bd3:b0:931:85f8:6d00 with SMTP id de19-20020a1709069bd300b0093185f86d00mr5068483ejc.47.1679479477175; Wed, 22 Mar 2023 03:04:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679479477; cv=none; d=google.com; s=arc-20160816; b=TpSmTqWJW7B3r2Y4PvS2CpaLUGX3SsuX/CUEwK/RC5n5edoqv659TswYsEmdSTTRoS /wO99aV+WTCOcf4WEx5nZ/TGxg/dMjwGhI22wcvQsnIKr38YZkOXKYxBeoEbsMBXpMRA WZPtsK9ml2QPHwXpt1n1nsMvApVydb1eh/B3t96wkwGs45zPnpAlstjOVJ7vGzFBhoOg czOyHmqLcIuLOMm5gySCkmf5xrdFmPu3sSrsq/z5LVF4kltcmxM3JTt+d7bYcyarOYU5 OtwnPoP9LQ0QhA9Ica5M57q3dIRWQ3rFWrienFuihtDiEt0wF1RAhPKh7uB50kMWPoo1 IbPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:cc:to:date:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=RfP/fX9XQ/xP9x/hb5im0KFGm/g7BsTB5W+9fFtJD80=; b=Ow5BamY56jpnJCYboXP4dy/xsNx6jhz0M/9UoH8B1noQMfekBNU7UdTrTypJ770R2J WRIzmvUSc5igwxCt6ayheV6M1rqteMewgTgEJlUuPxn3ZiqHzOSsfOMtO0ycQvWbHn+t 4gCvOYvYmj3GETWiQkFEGVN66ZZNd7T1fm5uF9+yfi3FeXKAQCiB0wXzOug+gbHm996u Fn9ha06V8jWCEhnDEUrxz9zWixDLCJqa392H+GV7BrygLjaiMOjTQeguXRMMkqJelSj+ hxB8MGK3XiMrvlht4PGaB6xHZOh/5FV+KqclE6hQ3WKoRWpZpGIxVmdsFtBKAdgfQwJM c+Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=M3Cd2bZC; 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 i20-20020a50fc14000000b004fa5cf7608esi14796115edr.258.2023.03.22.03.04.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 03:04:37 -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=M3Cd2bZC; 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 ECD873858416 for ; Wed, 22 Mar 2023 10:04:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ECD873858416 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679479476; bh=RfP/fX9XQ/xP9x/hb5im0KFGm/g7BsTB5W+9fFtJD80=; h=Date:To:cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=M3Cd2bZCN6JCVNLo7YttXDYMX3t+axclp8jkco9gYki5AnwcddmbbpoUOpQWj69Sa e3bTx9BgvicdaRJtJswUEzfwfYsdsbxdSVaLYbqWd1GP4k3R9XoAEk/SJpu4GrgFii 2v74G+QPH5tV8/CtIREGZBjYpE/Nn62a1EJrM5Z0= 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 EB5393858C1F for ; Wed, 22 Mar 2023 10:03:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EB5393858C1F Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 2E8FA20C2F; Wed, 22 Mar 2023 10:03:42 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 20B102C142; Wed, 22 Mar 2023 10:03:42 +0000 (UTC) Date: Wed, 22 Mar 2023 10:03:42 +0000 (UTC) To: gcc-patches@gcc.gnu.org cc: Jakub Jelinek Subject: [PATCH] rtl-optimization/109237 - speedup bb_is_just_return User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230322100435.ECD873858416@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761061871825224596?= X-GMAIL-MSGID: =?utf-8?q?1761061871825224596?= For the testcase bb_is_just_return is on top of the profile, changing it to walk BB insns backwards puts it off the profile. That's because in the forward walk you have to process possibly many debug insns but in a backward walk you very likely run into control insns first. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. OK? For the record, the profile was (after the delete_trivially_dead_insns fix) Samples: 289K of event 'cycles:u', Event count (approx.): 384226334976 Overhead Samples Command Shared Object Symbol 3.52% 9747 cc1 cc1 [.] bb_is_just_return # and after the fix bb_is_just_return has no recorded samples anymore. Thanks, Richard. PR rtl-optimization/109237 * cfgcleanup.cc (bb_is_just_return): Walk insns backwards. --- gcc/cfgcleanup.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/cfgcleanup.cc b/gcc/cfgcleanup.cc index 194e0e5de12..4cd33878ef3 100644 --- a/gcc/cfgcleanup.cc +++ b/gcc/cfgcleanup.cc @@ -2608,7 +2608,7 @@ bb_is_just_return (basic_block bb, rtx_insn **ret, rtx_insn **use) if (bb == EXIT_BLOCK_PTR_FOR_FN (cfun)) return false; - FOR_BB_INSNS (bb, insn) + FOR_BB_INSNS_REVERSE (bb, insn) if (NONDEBUG_INSN_P (insn)) { rtx pat = PATTERN (insn);