From patchwork Tue Feb 11 14:54:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans-Peter Nilsson X-Patchwork-Id: 1236314 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-519341-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=axis.com 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=jMvIgBA3; 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 48H5Qw6dKvz9sP7 for ; Wed, 12 Feb 2020 01:54:46 +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 :message-id:from:to:cc:subject:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=mEc59LjoynKmQaIS +mGP/msr8nJmxMBAyGkjGPCb40KvW9PFyPl5W/Sp5dtz66sgcJiPSHfleKQg9ox8 0xh+IUQv0i20q4hA/G+hoc5eYNZyZgyE9/2McLoAjaaQ4Ult0Uh21S2lsFwt2UC4 W+/rpfxieNyasD8VB/UmWlFtve4= 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 :message-id:from:to:cc:subject:mime-version:content-type :content-transfer-encoding; s=default; bh=1uScIyYr2HTPPp+jRHmGKH bLBts=; b=jMvIgBA37D4AT73oQE75psuKj6gL5VhiwrhXaxfAEBOYoiUGYRbCAE g5bR4ITYRfMUfhs7SdnphM+7Ws85gsDcrRzjLGAH9Lj17Cs79fcvt0IcgkEPcduG tX3022jCdMXf5xU0LDu+5HCLqN3UhgfbL0Q2ks1fwRwAgoUH6we6U= Received: (qmail 105829 invoked by alias); 11 Feb 2020 14:54:37 -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 105812 invoked by uid 89); 11 Feb 2020 14:54:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: smtp2.axis.com Received: from smtp2.axis.com (HELO smtp2.axis.com) (195.60.68.18) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Feb 2020 14:54:33 +0000 IronPort-SDR: VNcB+h1cIWM5mCgoEYmCjrF2swbWlJqYkF9kf2swrQZ8X6yOb0TY3nyCZy63ujDy+OcOHJfOQ0 N3pExXJXK12sz8kMUNT8j5jp9P4ITJx3QIizO/Sq8YPqUajO/puyKz2T7QviS6O/nvU+ygumIz 515Fdt3oUrBJ4QGqFkdy00GmTrfxeEYaZEGYS0bou6d5NoISpiyUp4egRuTyVW4e6OlrhFQg/M cQCXAP7hoBfzj7ow3cJH4KOmPOXlD2KgNnHQm0ozhW1TjoNtYUYoaseiowWDqNPwIYimRUaiMf vfA= Date: Tue, 11 Feb 2020 15:54:29 +0100 Message-ID: <202002111454.01BEsT98003726@ignucius.se.axis.com> From: Hans-Peter Nilsson To: CC: Subject: [PATCH] regalloc/debug: fix buggy print_hard_reg_set MIME-Version: 1.0 X-IsSubscribed: yes I was using ira-conflicts.c:print_hard_reg_set with a local patch to gdbinit.in in a debug-session, and noticed the erroneous output. I see there's an almost identical function in ira-color.c and on top of that, there's another function by the same name and with similar semantics in sel-sched-dump.c, but the last one doesn't try to print ranges. I'm guessing the dump functions have been used with targets that have "impossible" registers at FIRST_PSEUDO_REGISTER - 1. CRIS happens to have the condition-code register at FIRST_PSEUDO_REGISTER - 1; not allocatable but appears a lot in (clobbered) register sets after decc0ration. Before, for a target with FIRST_PSEUDO_REGISTER 20, you'd get "19-18" for (1<<19). For (1<<18)|(1<<19), you'd get "18". The diff is unfortunately hairy, but I hope you agree the code is a bit clearer. I'm deliberately not consolidating the dump functions as IMHO that's too much a matter of taste. * ira-conflicts.c (print_hard_reg_set): Correct output for sets including FIRST_PSEUDO_REGISTER - 1. * ira-color.c (print_hard_reg_set): Ditto. Ok to commit? --- gcc/ira-color.c | 22 ++++++++++++---------- gcc/ira-conflicts.c | 22 ++++++++++++---------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/gcc/ira-color.c b/gcc/ira-color.c index 4a726dc7c..0d88c1efe 100644 --- a/gcc/ira-color.c +++ b/gcc/ira-color.c @@ -478,24 +478,26 @@ first_common_ancestor_node (allocno_hard_regs_node_t first, static void print_hard_reg_set (FILE *f, HARD_REG_SET set, bool new_line_p) { - int i, start; + int i, start, end; - for (start = -1, i = 0; i < FIRST_PSEUDO_REGISTER; i++) + for (start = end = -1, i = 0; i < FIRST_PSEUDO_REGISTER; i++) { - if (TEST_HARD_REG_BIT (set, i)) + bool reg_included = TEST_HARD_REG_BIT (set, i); + + if (reg_included) { - if (i == 0 || ! TEST_HARD_REG_BIT (set, i - 1)) + if (start == -1) start = i; + end = i; } - if (start >= 0 - && (i == FIRST_PSEUDO_REGISTER - 1 || ! TEST_HARD_REG_BIT (set, i))) + if (start >= 0 && (!reg_included || i == FIRST_PSEUDO_REGISTER - 1)) { - if (start == i - 1) + if (start == end) fprintf (f, " %d", start); - else if (start == i - 2) - fprintf (f, " %d %d", start, start + 1); + else if (start == end + 1) + fprintf (f, " %d %d", start, end); else - fprintf (f, " %d-%d", start, i - 1); + fprintf (f, " %d-%d", start, end); start = -1; } } diff --git a/gcc/ira-conflicts.c b/gcc/ira-conflicts.c index 11d3a86dc..0220e725e 100644 --- a/gcc/ira-conflicts.c +++ b/gcc/ira-conflicts.c @@ -611,25 +611,27 @@ build_conflicts (void) static void print_hard_reg_set (FILE *file, const char *title, HARD_REG_SET set) { - int i, start; + int i, start, end; fputs (title, file); - for (start = -1, i = 0; i < FIRST_PSEUDO_REGISTER; i++) + for (start = end = -1, i = 0; i < FIRST_PSEUDO_REGISTER; i++) { - if (TEST_HARD_REG_BIT (set, i)) + bool reg_included = TEST_HARD_REG_BIT (set, i); + + if (reg_included) { - if (i == 0 || ! TEST_HARD_REG_BIT (set, i - 1)) + if (start == -1) start = i; + end = i; } - if (start >= 0 - && (i == FIRST_PSEUDO_REGISTER - 1 || ! TEST_HARD_REG_BIT (set, i))) + if (start >= 0 && (!reg_included || i == FIRST_PSEUDO_REGISTER - 1)) { - if (start == i - 1) + if (start == end) fprintf (file, " %d", start); - else if (start == i - 2) - fprintf (file, " %d %d", start, start + 1); + else if (start == end + 1) + fprintf (file, " %d %d", start, end); else - fprintf (file, " %d-%d", start, i - 1); + fprintf (file, " %d-%d", start, end); start = -1; } }