From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 7C5303858D28 for ; Mon, 7 Aug 2023 13:18:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7C5303858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id AAB7A1FDBE; Mon, 7 Aug 2023 13:18:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1691414336; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=cQnTYDlXFS+m6h4YiSYEpG1tN/uI7/Hkl+RVTbODioc=; b=oMEKYRp2L/dirlvxd6GpHxwkOa6JzWTQdiUT0dwjLA2EVDGIqbY4qdXfSQbEylTil53IZi YOxGANOoOAjRTjBN/c+gDwq/f2Bu6tUi35/Mtdqs+NdNFXcARV+oKoKh/39op9ZEwDmjob Z9wQWBKwI7iNLimyCmKAM4EaND1wI7E= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1691414336; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=cQnTYDlXFS+m6h4YiSYEpG1tN/uI7/Hkl+RVTbODioc=; b=gHE9nWf7VRn53V4GzIHRKkpE75KqLP0ja5sWZAZeqNwIYBmanG8jHeOMW6xor7nngKmxcV +4KVa9HnNRddBiAA== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 9D4DD2C145; Mon, 7 Aug 2023 13:18:56 +0000 (UTC) Date: Mon, 7 Aug 2023 13:18:56 +0000 (UTC) From: Richard Biener To: Jeff Law cc: gcc-patches@gcc.gnu.org, vmakarov@redhat.com Subject: Re: [PATCH] rtl-optimization/110587 - speedup find_hard_regno_for_1 In-Reply-To: Message-ID: References: <44c7f5b9-f3d9-4d7a-7090-d483e002ff21@gmail.com> User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_NUMSUBJECT,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 List-Id: On Wed, 2 Aug 2023, Richard Biener wrote: > On Mon, 31 Jul 2023, Jeff Law wrote: > > > > > > > On 7/31/23 04:54, Richard Biener via Gcc-patches wrote: > > > On Tue, 25 Jul 2023, Richard Biener wrote: > > > > > >> The following applies a micro-optimization to find_hard_regno_for_1, > > >> re-ordering the check so we can easily jump-thread by using an else. > > >> This reduces the time spent in this function by 15% for the testcase > > >> in the PR. > > >> > > >> Bootstrap & regtest running on x86_64-unknown-linux-gnu, OK if that > > >> passes? > > > > > > Ping. > > > > > >> Thanks, > > >> Richard. > > >> > > >> PR rtl-optimization/110587 > > >> * lra-assigns.cc (find_hard_regno_for_1): Re-order checks. > > >> --- > > >> gcc/lra-assigns.cc | 9 +++++---- > > >> 1 file changed, 5 insertions(+), 4 deletions(-) > > >> > > >> diff --git a/gcc/lra-assigns.cc b/gcc/lra-assigns.cc > > >> index b8582dcafff..d2ebcfd5056 100644 > > >> --- a/gcc/lra-assigns.cc > > >> +++ b/gcc/lra-assigns.cc > > >> @@ -522,14 +522,15 @@ find_hard_regno_for_1 (int regno, int *cost, int > > >> @@ try_only_hard_regno, > > >> r2 != NULL; > > >> r2 = r2->start_next) > > >> { > > >> - if (r2->regno >= lra_constraint_new_regno_start > > >> + if (live_pseudos_reg_renumber[r2->regno] < 0 > > >> + && r2->regno >= lra_constraint_new_regno_start > > >> && lra_reg_info[r2->regno].preferred_hard_regno1 >= 0 > > >> - && live_pseudos_reg_renumber[r2->regno] < 0 > > >> && rclass_intersect_p[regno_allocno_class_array[r2->regno]]) > > >> sparseset_set_bit (conflict_reload_and_inheritance_pseudos, > > >> r2->regno); > > >> - if (live_pseudos_reg_renumber[r2->regno] >= 0 > > >> - && rclass_intersect_p[regno_allocno_class_array[r2->regno]]) > > >> + else if (live_pseudos_reg_renumber[r2->regno] >= 0 > > >> + && rclass_intersect_p > > >> + [regno_allocno_class_array[r2->regno]]) > > >> sparseset_set_bit (live_range_hard_reg_pseudos, r2->regno); > > My biggest concern here would be r2->regno < 0 in the new code which could > > cause an OOB array reference in the first condition of the test. > > > > Isn't that the point if the original ordering? Test that r2->regno is > > reasonable before using it as an array index? > > Note the original code is > > if (r2->regno >= lra_constraint_new_regno_start > ... > if (live_pseudos_reg_renumber[r2->regno] >= 0 > ... > > so we are going to access live_pseudos_reg_renumber[r2->regno] > independent on the r2->regno >= lra_constraint_new_regno_start check, > so I don't think that's the point of the original ordering. Note > I preserved the ordering with respect to other array accesses, > the speedup seen is because we now have the > > > if (live_pseudos_reg_renumber[r2->regno] < 0 > ... > else if (live_pseudos_reg_renumber[r2->regno] >= 0 > ... > > structure directly exposed which helps the compiler. > > I think the check on r2->regno is to decide whether to alter > conflict_reload_and_inheritance_pseudos or > live_range_hard_reg_pseudos (so it's also somewhat natural to check > that first). So - OK? Thanks, Richard.