From patchwork Mon Nov 1 09:54:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 46897 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 07ED33858427 for ; Mon, 1 Nov 2021 09:57:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 07ED33858427 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1635760669; bh=oife8g/XvobKWRBXQ67bYP9Gq3a9We3gFQ2ZA/cpNgw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=IlO8aGX57a0NM5oZXlnOf1j9DTYutYAEgPgFzyBVfL1r5hb4ef8fu3snYj2vd4VyW rQisEKtAoO8SnL7IUs4ADKQOZ2UWlk/o6oHpAWTmU++fpaADrUeOWT5Fo/2pYiOyzg pPrkmzwjI/XVKXv+TB9Pg7xh6KfQXpjnmoS3kKmA= 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 13F06385800B for ; Mon, 1 Nov 2021 09:55:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 13F06385800B Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-528-xRKtbeUvPmi0vzjt-1Jtmw-1; Mon, 01 Nov 2021 05:55:18 -0400 X-MC-Unique: xRKtbeUvPmi0vzjt-1Jtmw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A33F3BBEE8; Mon, 1 Nov 2021 09:55:17 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.157]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2B1E65C22B; Mon, 1 Nov 2021 09:55:16 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.16.1/8.15.2) with ESMTPS id 1A19tEZU727462 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 1 Nov 2021 10:55:14 +0100 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.16.1/8.16.1/Submit) id 1A19tE8l727461; Mon, 1 Nov 2021 10:55:14 +0100 To: Jeff Law Subject: [PATCH] Add debug counters to back threader. Date: Mon, 1 Nov 2021 10:54:44 +0100 Message-Id: <20211101095443.727405-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez Cc: GCC patches Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Chasing down stage3 miscomparisons is never fun, and having no way to distinguish between jump threads registered by a particular pass, is even harder. This patch adds debug counters for the individual back threading passes. I've left the ethread pass alone, as that one is usually benign, but we could easily add it if needed. The fact that we can only pass one boolean argument to the passes infrastructure has us do all sorts of gymnastics to differentiate between the various back threading passes. Tested on x86-64 Linux. OK? gcc/ChangeLog: * dbgcnt.def: Add debug counter for back_thread[12] and back_threadfull[12]. * passes.def: Pass "first" argument to each back threading pass. * tree-ssa-threadbackward.c (back_threader::back_threader): Add first argument. (back_threader::debug_counter): New. (back_threader::maybe_register_path): Call debug_counter. --- gcc/dbgcnt.def | 4 ++ gcc/passes.def | 10 ++--- gcc/tree-ssa-threadbackward.c | 71 ++++++++++++++++++++++++++++++++--- 3 files changed, 74 insertions(+), 11 deletions(-) diff --git a/gcc/dbgcnt.def b/gcc/dbgcnt.def index c2bcc4eef5e..3a85665a1d7 100644 --- a/gcc/dbgcnt.def +++ b/gcc/dbgcnt.def @@ -144,6 +144,10 @@ echo ubound: $ub Please keep the list sorted in alphabetic order. */ DEBUG_COUNTER (asan_use_after_scope) DEBUG_COUNTER (auto_inc_dec) +DEBUG_COUNTER (back_thread1) +DEBUG_COUNTER (back_thread2) +DEBUG_COUNTER (back_threadfull1) +DEBUG_COUNTER (back_threadfull2) DEBUG_COUNTER (ccp) DEBUG_COUNTER (cfg_cleanup) DEBUG_COUNTER (cprop) diff --git a/gcc/passes.def b/gcc/passes.def index 29921f80ed9..0f541454e7f 100644 --- a/gcc/passes.def +++ b/gcc/passes.def @@ -81,7 +81,7 @@ along with GCC; see the file COPYING3. If not see /* After CCP we rewrite no longer addressed locals into SSA form if possible. */ NEXT_PASS (pass_forwprop); - NEXT_PASS (pass_early_thread_jumps); + NEXT_PASS (pass_early_thread_jumps, /*first=*/true); NEXT_PASS (pass_sra_early); /* pass_build_ealias is a dummy pass that ensures that we execute TODO_rebuild_alias at this point. */ @@ -210,7 +210,7 @@ along with GCC; see the file COPYING3. If not see NEXT_PASS (pass_return_slot); NEXT_PASS (pass_fre, true /* may_iterate */); NEXT_PASS (pass_merge_phi); - NEXT_PASS (pass_thread_jumps_full); + NEXT_PASS (pass_thread_jumps_full, /*first=*/true); NEXT_PASS (pass_vrp, true /* warn_array_bounds_p */); NEXT_PASS (pass_dse); NEXT_PASS (pass_dce); @@ -233,7 +233,7 @@ along with GCC; see the file COPYING3. If not see propagations have already run, but before some more dead code is removed, and this place fits nicely. Remember this when trying to move or duplicate pass_dominator somewhere earlier. */ - NEXT_PASS (pass_thread_jumps); + NEXT_PASS (pass_thread_jumps, /*first=*/true); NEXT_PASS (pass_dominator, true /* may_peel_loop_headers_p */); /* Threading can leave many const/copy propagations in the IL. Clean them up. Failure to do so well can lead to false @@ -332,10 +332,10 @@ along with GCC; see the file COPYING3. If not see NEXT_PASS (pass_fre, false /* may_iterate */); /* After late FRE we rewrite no longer addressed locals into SSA form if possible. */ - NEXT_PASS (pass_thread_jumps); + NEXT_PASS (pass_thread_jumps, /*first=*/false); NEXT_PASS (pass_dominator, false /* may_peel_loop_headers_p */); NEXT_PASS (pass_strlen); - NEXT_PASS (pass_thread_jumps_full); + NEXT_PASS (pass_thread_jumps_full, /*first=*/false); NEXT_PASS (pass_vrp, false /* warn_array_bounds_p */); /* Run CCP to compute alignment and nonzero bits. */ NEXT_PASS (pass_ccp, true /* nonzero_p */); diff --git a/gcc/tree-ssa-threadbackward.c b/gcc/tree-ssa-threadbackward.c index c66e74d159a..8e4a59744c5 100644 --- a/gcc/tree-ssa-threadbackward.c +++ b/gcc/tree-ssa-threadbackward.c @@ -44,6 +44,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-cfgcleanup.h" #include "tree-pretty-print.h" #include "cfghooks.h" +#include "dbgcnt.h" // Path registry for the backwards threader. After all paths have been // registered with register_path(), thread_through_all_blocks() is called @@ -80,12 +81,13 @@ private: class back_threader { public: - back_threader (function *fun, unsigned flags); + back_threader (function *fun, unsigned flags, bool first); ~back_threader (); unsigned thread_blocks (); private: void maybe_thread_block (basic_block bb); void find_paths (basic_block bb, tree name); + bool debug_counter (); edge maybe_register_path (); bool find_paths_to_names (basic_block bb, bitmap imports); bool resolve_def (tree name, bitmap interesting, vec &worklist); @@ -120,14 +122,19 @@ private: // VARYING. Setting to true is more precise but slower. function *m_fun; unsigned m_flags; + // Set to TRUE for the first of each thread[12] pass or the first of + // each threadfull[12] pass. This is used to differentiate between + // the different threading passes so we can set up debug counters. + bool m_first; }; // Used to differentiate unreachable edges, so we may stop the search // in a the given direction. const edge back_threader::UNREACHABLE_EDGE = (edge) -1; -back_threader::back_threader (function *fun, unsigned flags) - : m_profit (flags & BT_SPEED) +back_threader::back_threader (function *fun, unsigned flags, bool first) + : m_profit (flags & BT_SPEED), + m_first (first) { if (flags & BT_SPEED) loop_optimizer_init (LOOPS_HAVE_PREHEADERS | LOOPS_HAVE_SIMPLE_LATCHES); @@ -149,6 +156,37 @@ back_threader::~back_threader () loop_optimizer_finalize (); } +// A wrapper for the various debug counters for the threading passes. +// Returns TRUE if it's OK to register the current threading +// candidate. + +bool +back_threader::debug_counter () +{ + // We don't have any counters for the ethread pass as that + // one is usually harmless ;-). + if ((m_flags & BT_SPEED) == 0) + return true; + + if (m_flags & BT_RESOLVE) + { + if (m_first && !dbg_cnt (back_threadfull1)) + return false; + + if (!m_first && !dbg_cnt (back_threadfull2)) + return false; + } + else + { + if (m_first && !dbg_cnt (back_thread1)) + return false; + + if (!m_first && !dbg_cnt (back_thread2)) + return false; + } + return true; +} + // Register the current path for jump threading if it's profitable to // do so. // @@ -172,6 +210,9 @@ back_threader::maybe_register_path () if (profitable) { + if (!debug_counter ()) + return NULL; + m_registry.register_path (m_path, taken_edge); if (irreducible) @@ -974,15 +1015,21 @@ public: { return new pass_early_thread_jumps (m_ctxt); } + void set_pass_param (unsigned int, bool param) override + { + m_first = param; + } bool gate (function *) override { return flag_thread_jumps; } unsigned int execute (function *fun) override { - back_threader threader (fun, BT_NONE); + back_threader threader (fun, BT_NONE, m_first); return threader.thread_blocks (); } +private: + bool m_first; }; // Jump threading pass without resolving of unknown SSAs. @@ -996,15 +1043,21 @@ public: { return new pass_thread_jumps (m_ctxt); } + void set_pass_param (unsigned int, bool param) override + { + m_first = param; + } bool gate (function *) override { return flag_thread_jumps && flag_expensive_optimizations; } unsigned int execute (function *fun) override { - back_threader threader (fun, BT_SPEED); + back_threader threader (fun, BT_SPEED, m_first); return threader.thread_blocks (); } +private: + bool m_first; }; // Jump threading pass that fully resolves unknown SSAs. @@ -1018,15 +1071,21 @@ public: { return new pass_thread_jumps_full (m_ctxt); } + void set_pass_param (unsigned int, bool param) override + { + m_first = param; + } bool gate (function *) override { return flag_thread_jumps && flag_expensive_optimizations; } unsigned int execute (function *fun) override { - back_threader threader (fun, BT_SPEED | BT_RESOLVE); + back_threader threader (fun, BT_SPEED | BT_RESOLVE, m_first); return threader.thread_blocks (); } +private: + bool m_first; }; } // namespace {