From patchwork Thu May 12 01:48:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 53830 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 31B2D3857372 for ; Thu, 12 May 2022 01:50:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 31B2D3857372 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652320220; bh=gL+IT4hlEoR+uiyvjmN19QPe3mcPBkLWbxXLYRq8qjg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=DLVRbYPuy8b3w9XMl+6qD7aGCAzR5FpLEdBqqoamcoP2dHeWB5Z+7kxIhkdwPoeol NZ1sjNQSvk+q3bSauXD+LMqF3/07EM4aelZV0rhnqjASAA2Qb05HNEomxMrtxKX+R4 8IHvwHXP4fmaa/3zsPASIQYsHvduV7BZgiQ+ou7s= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTPS id CB8F33856257 for ; Thu, 12 May 2022 01:48:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CB8F33856257 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 97E33116A06; Wed, 11 May 2022 21:48:58 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id nLtQxtmpH+j8; Wed, 11 May 2022 21:48:58 -0400 (EDT) Received: from free.home (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPS id 5FF32116809; Wed, 11 May 2022 21:48:58 -0400 (EDT) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 24C1mol9106077 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 May 2022 22:48:50 -0300 To: gcc-patches@gcc.gnu.org Subject: [PATCH] [PR105455] predict: Check for no REG_BR_PROB in uninitialized case Organization: Free thinker, does not speak for AdaCore Date: Wed, 11 May 2022 22:48:50 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: Alexandre Oliva via Gcc-patches From: Alexandre Oliva Reply-To: Alexandre Oliva Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" There is an assumption in force_edge_cold that, if any edge out of the same src block has uninitialized probability, then a conditional branch out of src won't have REG_BR_PROB set. This assumption is supposed to hold, but buggy gimple passes may turn unconditional edges into conditional ones, adding edges with uninitialized probability out of blocks that retain originally unconditional edges with precise always probability. Expand may then copy the formerly-unconditional edge's probability to REG_BR_PROB, and if that edge ends up forced cold, the probability in the edge will be modified without adjusting the note, and rtl_verify_edges complains about that. This patch adds checking that REG_BR_PROB is absent to the path taken by force_cold_edge for uninitialized probabilities, so that the problem is caught earlier and fixed sooner. I'm not sure it buys us much, but... Regstrapped on x86_64-linux-gnu. Ok to install? for gcc/ChangeLog * predict.cc (force_edge_cold): Check for no REG_BR_PROB in the uninitialized probability case. --- gcc/predict.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/gcc/predict.cc b/gcc/predict.cc index 5734e4c851630..48ac81624ec4a 100644 --- a/gcc/predict.cc +++ b/gcc/predict.cc @@ -4378,7 +4378,19 @@ force_edge_cold (edge e, bool impossible) /* If we are not guessing profiles but have some other edges out, just assume the control flow goes elsewhere. */ if (uninitialized_exit) - e->probability = goal; + { + e->probability = goal; +#if CHECKING_P + /* We don't expect to have a REG_BR_PROB note to adjust when + there were edges with uninitialized probabilities. This + would be a symptom of creating edges, before expand, without + assigning probabilities, while other edges have them. */ + if (current_ir_type () != IR_GIMPLE + && e->src != ENTRY_BLOCK_PTR_FOR_FN (cfun)) + gcc_checking_assert (!find_reg_note (BB_END (e->src), + REG_BR_PROB, NULL_RTX)); +#endif + } /* If there are other edges out of e->src, redistribute probabilitity there. */ else if (prob_sum > profile_probability::never ())