From patchwork Fri Apr 15 07:48:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Trofimovich X-Patchwork-Id: 1617682 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=FkxfvKkQ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KfpQR1HXXz9sG0 for ; Fri, 15 Apr 2022 17:50:05 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CD503385B219 for ; Fri, 15 Apr 2022 07:50:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CD503385B219 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1650009002; bh=8cbF7FcNuqFVGRLLEC/y3fn0q42dbPNa2VVveYTYYeA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=FkxfvKkQj9qhoxY0N50uJq6rGVh1+HnCwXHGzWY7XiKa4MMkwoonMB2BowNDXdyVv Y9n4Qy+x+l0WVuFo4R4nB9n1InewBRqZh6jVQevuI74MkCGOmYq8VMC7pJGf6sGuRC Q6xMY5+Q0ANtd+nyybFmf4GEKri8wB58+IlVqaqw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id 71857385843E for ; Fri, 15 Apr 2022 07:49:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 71857385843E Received: by mail-wm1-x32b.google.com with SMTP id n40-20020a05600c3ba800b0038ff1939b16so3400138wms.2 for ; Fri, 15 Apr 2022 00:49:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8cbF7FcNuqFVGRLLEC/y3fn0q42dbPNa2VVveYTYYeA=; b=WGbS8Fz/RPTvaq0vDVGkPQdY10Oh/pKWn+L8nIumNBrcwohrqGMh/FuNItwHgeFRBs VYAHi9hO1+X2YhhefAwiJhCHtOvx5Adf+xW8L3Zo0I7YXf2N7iYqCn/XzOvfG7OF2UrC h1WVnq0aAFtC6/PjPqaOdgl97zB+9Z7hfPR+Rb9iB0f3yTlLs9/BND6HIsJQvLMA6gtX t9QsjHsWQ2W2hbky4Q7dkbscE/Rl6MkIbApl8dAn1nWq6PPRXuWG2qY8Rx0IkvBe/tYd ywjREwtoMY9csfX3VfvDQTI4N0/CrXrOqdIgD9q5iuLxENPiI4AN75JEWAMAl6yFOYTj vcJA== X-Gm-Message-State: AOAM533ghyaDA4In/92FEwxR+kWXO2cuCqBdxNCLh36CMllDT1wH2pmp R19gVdlzcqUcqKQ7eQ2854Q= X-Google-Smtp-Source: ABdhPJx16EKzBe/qX42j18u3koZdTzssPy6dSJXwwDTx4GVuVfUbG7iz0HOvNymetuQ/EVR1f/yfhw== X-Received: by 2002:a1c:7408:0:b0:38e:b7af:c503 with SMTP id p8-20020a1c7408000000b0038eb7afc503mr2195859wmc.58.1650008960167; Fri, 15 Apr 2022 00:49:20 -0700 (PDT) Received: from nz.home (host81-147-8-147.range81-147.btcentralplus.com. [81.147.8.147]) by smtp.gmail.com with ESMTPSA id a11-20020a056000188b00b00204109f7826sm4047648wri.28.2022.04.15.00.49.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 00:49:19 -0700 (PDT) Received: by nz.home (Postfix, from userid 1000) id C804D2D05EAE4; Fri, 15 Apr 2022 08:49:18 +0100 (BST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] gcov-profile: Allow negavive counts of indirect calls [PR105282] Date: Fri, 15 Apr 2022 08:48:55 +0100 Message-Id: <20220415074855.1031369-1-slyich@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, WEIRD_PORT 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: Sergei Trofimovich via Gcc-patches From: Sergei Trofimovich Reply-To: Sergei Trofimovich Cc: Jan Hubicka , Sergei Trofimovich , Nathan Sidwell Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" From: Sergei Trofimovich TOPN metrics are histograms that contain overall count and per-bucket count. Overall count can be nevative when two profiles merge and some of per-bucket metrics are dropped. Noticed as an ICE on python PGO build where gcc crashes as: during IPA pass: modref a.c:36:1: ICE: in stream_out_histogram_value, at value-prof.cc:340 36 | } | ^ stream_out_histogram_value(output_block*, histogram_value_t*) gcc/value-prof.cc:340 gcc/ChangeLog: PR gcov-profile/105282 * value-prof.cc (stream_out_histogram_value): Allow negavive counts on HIST_TYPE_INDIR_CALL. --- gcc/value-prof.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gcc/value-prof.cc b/gcc/value-prof.cc index 9785c7a03ea..4927d119aa0 100644 --- a/gcc/value-prof.cc +++ b/gcc/value-prof.cc @@ -319,40 +319,44 @@ stream_out_histogram_value (struct output_block *ob, histogram_value hist) streamer_write_bitpack (&bp); switch (hist->type) { case HIST_TYPE_INTERVAL: streamer_write_hwi (ob, hist->hdata.intvl.int_start); streamer_write_uhwi (ob, hist->hdata.intvl.steps); break; default: break; } for (i = 0; i < hist->n_counters; i++) { /* When user uses an unsigned type with a big value, constant converted to gcov_type (a signed type) can be negative. */ gcov_type value = hist->hvalue.counters[i]; if (hist->type == HIST_TYPE_TOPN_VALUES || hist->type == HIST_TYPE_IOR) /* Note that the IOR counter tracks pointer values and these can have sign bit set. */ ; + else if (hist->type == HIST_TYPE_INDIR_CALL && i == 0) + /* 'all' counter overflow is stored as a negative value. Individual + counters and values are expected to be non-negative. */ + ; else gcc_assert (value >= 0); streamer_write_gcov_count (ob, value); } if (hist->hvalue.next) stream_out_histogram_value (ob, hist->hvalue.next); } /* Dump information about HIST to DUMP_FILE. */ void stream_in_histogram_value (class lto_input_block *ib, gimple *stmt) { enum hist_type type; unsigned int ncounters = 0; struct bitpack_d bp; unsigned int i; histogram_value new_val; bool next;