From patchwork Mon Aug 14 15:59:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1821052 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=XC8oui8U; dkim-atps=neutral Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RPfHj52VFz1yfP for ; Tue, 15 Aug 2023 02:00:17 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D752E3858409 for ; Mon, 14 Aug 2023 16:00:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D752E3858409 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692028814; bh=qXbZcCFO3iiw+xOU956d8bRXHMC/kmMLHi3jmWreGHA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=XC8oui8UwyrC5a9TMpdBYZpEPcm/2nPWq+WndEgPk2nCgtSetzzZZTQVa+bGA4RwG 7EvfDZ8OzJ4ZCdk7uWy3BBw9NuxH/Q+96KgVrWw4BNxvQLz5+zk6N77oLt6hhv1GuH aD8wn72ktllSFSo7QZ6Eq1NRhXxj4uzpQkJw0Atg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id E83493858C20 for ; Mon, 14 Aug 2023 15:59:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E83493858C20 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 5AD0D281300; Mon, 14 Aug 2023 17:59:53 +0200 (CEST) Date: Mon, 14 Aug 2023 17:59:53 +0200 To: gcc-patches@gcc.gnu.org Subject: Avoid division by zero in fold_loop_internal_call Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, JMQ_SPF_NEUTRAL, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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: Jan Hubicka via Gcc-patches From: Jan Hubicka Reply-To: Jan Hubicka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, My patch to fix profile after folding internal call is missing check for the case profile was already zero before if-conversion. Bootstrapped/regtested x86_64-linux, comitted. gcc/ChangeLog: PR gcov-profile/110988 * tree-cfg.cc (fold_loop_internal_call): Avoid division by zero. diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc index ab1f8067c54..105f4b1c953 100644 --- a/gcc/tree-cfg.cc +++ b/gcc/tree-cfg.cc @@ -7734,11 +7734,14 @@ fold_loop_internal_call (gimple *g, tree value) test. This should not happen as the guarded code should start with pre-header. */ gcc_assert (single_pred_edge (taken_edge->dest)); - taken_edge->dest->count - = taken_edge->dest->count.apply_scale (new_count, - old_count); - scale_strictly_dominated_blocks (taken_edge->dest, - new_count, old_count); + if (old_count.nonzero_p ()) + { + taken_edge->dest->count + = taken_edge->dest->count.apply_scale (new_count, + old_count); + scale_strictly_dominated_blocks (taken_edge->dest, + new_count, old_count); + } } } }