From patchwork Tue Jan 28 20:40:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1230649 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-518444-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ucw.cz Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=qAa7p88Z; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 486dm60q6wz9sNT for ; Wed, 29 Jan 2020 07:40:19 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=d6rXeugpjkhHpFS+tB/P42/fOz8R9/Lb3Fd559Nev35ioA0kmdXVp zJGdrConZocH7KJNCrGL1Sk3dQg2chgE0DDB4yFU4NQcYiM+QJtY4ichy9NjORB5 TZHwMhvxcp6JawKaPUFuOSoAyYGEf0sORUNzlqTxututEoySLYvCno= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=DTt0h1WcJ2/VfXBMXN6G1oBT7YM=; b=qAa7p88Z71SsIArZgvs0 HA2Gwhr1ocqP0nJ6DC9IIYjnHt9sgYwzrVFoh1YwBcdQK5frRXY0GarKBKKcU+VX JTWHXecyNhkh0cXiaN49Dug77KT6nStWvLFZbShi4Xhc0Vlv0Ts1ml19BFwmFkxv bzzIDshD8HD524gKiZWqb/Q= Received: (qmail 28286 invoked by alias); 28 Jan 2020 20:40:13 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 26971 invoked by uid 89); 28 Jan 2020 20:40:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: nikam.ms.mff.cuni.cz Received: from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 28 Jan 2020 20:40:11 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id F1F872804B4; Tue, 28 Jan 2020 21:40:08 +0100 (CET) Date: Tue, 28 Jan 2020 21:40:08 +0100 From: Jan Hubicka To: gcc-patches@gcc.gnu.org, mliska@suse.cz Subject: Verify sanity of indirect call/topn profiles Message-ID: <20200128204008.GF55295@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Hi, I will try to reming this next stage1 since it is not regression fix. I found it useful to have bit of sanity checking of the topn profiles to work out the bugs in merging and updating that was there. Honza gcc/ChangeLog: 2020-01-28 Jan Hubicka * profile.c (compute_value_histograms): Verify profile sanity. diff --git a/gcc/profile.c b/gcc/profile.c index cd754c4c66a..782534e5ab4 100644 --- a/gcc/profile.c +++ b/gcc/profile.c @@ -856,10 +856,10 @@ compute_value_histograms (histogram_values values, unsigned cfg_checksum, gimple_add_histogram_value (cfun, stmt, hist); hist->hvalue.counters = XNEWVEC (gcov_type, hist->n_counters); for (j = 0; j < hist->n_counters; j++) - if (aact_count) - hist->hvalue.counters[j] = aact_count[j]; - else - hist->hvalue.counters[j] = 0; + if (aact_count) + hist->hvalue.counters[j] = aact_count[j]; + else + hist->hvalue.counters[j] = 0; if (hist->type == HIST_TYPE_TOPN_VALUES || hist->type == HIST_TYPE_INDIR_CALL) @@ -871,6 +871,26 @@ compute_value_histograms (histogram_values values, unsigned cfg_checksum, = RDIV (hist->hvalue.counters[2 * i + 2], GCOV_TOPN_VALUES); sort_hist_values (hist); + + /* Check profile sanity. */ + if (hist->hvalue.counters[2] != -1) + for (int i = 0; i < GCOV_TOPN_VALUES - 1 && ok; i++) + for (int j = i + 1; j < GCOV_TOPN_VALUES && ok; j++) + if ((hist->hvalue.counters[i * 2 + 1] + == hist->hvalue.counters[j * 2 + 1] + && hist->hvalue.counters[i * 2 + 2] + && hist->hvalue.counters[j * 2 + 2]) + || hist->hvalue.counters[i * 2 + 2] < 0) + { + if (hist->type == HIST_TYPE_TOPN_VALUES) + error_at (gimple_location (stmt), + "corrupted profile info:" + " invalid topn profile histogram"); + else + error_at (gimple_location (stmt), + "corrupted profile info:" + " indirect call profile histogram"); + } } /* Time profiler counter is not related to any statement,