Message ID | 20221107094645.3718427-1-jcmvbkbc@gmail.com |
---|---|
State | Accepted |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1947451wru; Mon, 7 Nov 2022 01:48:03 -0800 (PST) X-Google-Smtp-Source: AMsMyM5ZKSlLxhzhUURcFfDhDgWi5WCocBOt/EzWw8jXV69U66ESGk0ogF5rQWJuHrDYNXpGyOEV X-Received: by 2002:a17:907:2719:b0:782:b261:e9eb with SMTP id w25-20020a170907271900b00782b261e9ebmr48340854ejk.104.1667814483286; Mon, 07 Nov 2022 01:48:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667814483; cv=none; d=google.com; s=arc-20160816; b=fAOTbO7/UJj7NNObBxntNNrODmWn6O3EQZi33P/ZFiRTypkmOgf592/em8AKVM3rcf Y5+HUTRFqf78wRj9jjinEo8Hjl4MsGmjDKW677qhNHa9XL6Ye1QLsWZwK3imgNLAmY1P AsOy3VaQM2L61n0KymZiht8F7GGWcY5OAOYfp7jjok9yOyq0yBP788rmVvNiTvUA5wgg kowv5kEMInjHUiUDXJQKbmst+sMpdUcJHdL+rQafQfD05/Bt2Q685/8Jj8tz2zDUz50m BQWSVVHq1sHy7asy/R0ONYkcsg8TBKymhuXd5bqkcToCedQJ45ECcF2563QBG+X2pMFA v6Mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=eEIiejLsqq3bJR5RSe8+h2yQSAOKDl/Z358TQwsj+CY=; b=fIIv2Xso8WGvO3IqmsVcLEMavxURwVF8DNzObUvyuPHEI1xvDdZ3ti5PVdR9ItAKg6 kVBXAixOr9dZCP+72MGytq+16EanJlOjeylVBfpop+PqSpIwVIceK846RL6BMNldpL5Z XsqtZSgKtakarRNuAEZ4uiyba9+0wtAeZ8kRXAMwVR+9BuXXjkkOUEp9EIQWPj14QJim hQbcJbSOPP64GG/KFYbpmijsY1UWkD70xBKeFZIRBrkvog3T5eYRPjiNVM1thSSyaTix raCX7b3+FOL2EVRolWRniie1D1KL0Mk1qgMh5rsNfdiTFvE0p+Ktyl83ILlDar8KYPuM oD9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=GJaGqa9T; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id y18-20020aa7ce92000000b0045cad599362si8175486edv.530.2022.11.07.01.48.03 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 01:48:03 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=GJaGqa9T; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4DD153858C2C for <ouuuleilei@gmail.com>; Mon, 7 Nov 2022 09:48:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4DD153858C2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667814482; bh=eEIiejLsqq3bJR5RSe8+h2yQSAOKDl/Z358TQwsj+CY=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=GJaGqa9TqF3FggF9IbWc+PVFlTqXDcP2wc9jrvgjXB+fgoTz3cLuh/ze9l3z+NLcM 6NoPi46+UTG9LqmcjLLLbPRaWLBTDFOrR9FUaxsx4ifBDEzcmFJ+I87wWxBTKm79iw 8qMlQ4WI0bwJ09dkDJXzhP4X3nehBiIl6kOrBS8c= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id 352963858C1F for <gcc-patches@gcc.gnu.org>; Mon, 7 Nov 2022 09:47:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 352963858C1F Received: by mail-pl1-x630.google.com with SMTP id g24so10580535plq.3 for <gcc-patches@gcc.gnu.org>; Mon, 07 Nov 2022 01:47:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=eEIiejLsqq3bJR5RSe8+h2yQSAOKDl/Z358TQwsj+CY=; b=D5McIZaCqhBoRC3i2xLe9kl14F/zGJOVBoqdYIgugwvIeFObn9ckF1zw3ZGq3yxZZU Qc0e4Fy2w6e4RURDMl16bRhTy8I/3NQ6HgI0z3Mxm0bJERIaVec6GtD+KeDelVUrukEu LLcPb6rbXBKJZyhr2WAnMGr22v7gHJGGxJWxckXyBpVSy5J0h5cT3rdJxT4aRg3Q9Bst 7HVHsjkbWmix6CbI3adHOw5QeFRK826vpVUfbkBXcfZz0WcCddUzvEnLi1n6I8OqUJkm 5TfyOkJEKPZmYr3HKJoPiOhklc9ZXs4hsIRDoyi6+pMeoa6PTWORAxC+QRYpq/roEiYN UQiQ== X-Gm-Message-State: ACrzQf0qbYYUoE46/Wfyd+Z8rm8tSrkOpacrNIVgfsrYD1WDLRekV/nK lHbnPBS39byhuM/n/NzeQXitbct7Yto= X-Received: by 2002:a17:902:ceca:b0:187:12cc:d6a1 with SMTP id d10-20020a170902ceca00b0018712ccd6a1mr44982224plg.162.1667814433824; Mon, 07 Nov 2022 01:47:13 -0800 (PST) Received: from octofox.hsd1.ca.comcast.net ([2601:641:401:1d20:f042:87a2:c6b:9a6f]) by smtp.gmail.com with ESMTPSA id e4-20020a170902784400b001871acf245csm4557575pln.37.2022.11.07.01.47.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 01:47:12 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: Vladimir Makarov <vmakarov@redhat.com>, Max Filippov <jcmvbkbc@gmail.com> Subject: [RFA] gcc: fix PR rtl-optimization/107482 Date: Mon, 7 Nov 2022 01:46:45 -0800 Message-Id: <20221107094645.3718427-1-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, FROM_LOCAL_NOVOWEL, GIT_PATCH_0, HK_RANDOM_ENVFROM, HK_RANDOM_FROM, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Max Filippov via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Max Filippov <jcmvbkbc@gmail.com> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748830239438417604?= X-GMAIL-MSGID: =?utf-8?q?1748830239438417604?= |
Series |
[RFA] gcc: fix PR rtl-optimization/107482
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | success | Github commit url |
Commit Message
Max Filippov
Nov. 7, 2022, 9:46 a.m. UTC
gcc/ * ira-color.cc (update_costs_from_allocno): Check that allocno is in the consideration_allocno_bitmap before dereferencing ALLOCNO_COLOR_DATA (allocno). --- This fixes the invalid memory access, but I'm not sure if that's sufficient and there's no remaining higher level logical issue. Regtested for target=xtensa-linux-uclibc, no new regressions. gcc/ira-color.cc | 2 ++ 1 file changed, 2 insertions(+)
Comments
On 2022-11-07 04:46, Max Filippov wrote: > gcc/ > * ira-color.cc (update_costs_from_allocno): Check that allocno > is in the consideration_allocno_bitmap before dereferencing > ALLOCNO_COLOR_DATA (allocno). > --- > This fixes the invalid memory access, but I'm not sure if that's > sufficient and there's no remaining higher level logical issue. Thank you for reporting and working on this issue. I believe your approach is sufficient. Although the patch could be improved by three ways: The simplest one is to move consideration allocno check out of loop by using the following patch diff --git a/gcc/ira-color.cc b/gcc/ira-color.cc index 4a1a325e8e3..a8e52b6b265 100644 --- a/gcc/ira-color.cc +++ b/gcc/ira-color.cc @@ -1413,7 +1413,9 @@ update_costs_from_allocno (ira_allocno_t allocno, int hard_regno, ira_copy_t cp, next_cp; rclass = REGNO_REG_CLASS (hard_regno); - do + if (!bitmap_bit_p (consideration_allocno_bitmap, ALLOCNO_NUM (allocno))) + return; + do { mode = ALLOCNO_MODE (allocno); ira_init_register_move_cost_if_necessary (mode); or by even better patch: diff --git a/gcc/ira-color.cc b/gcc/ira-color.cc index 4a1a325e8e3..ffe73b61c45 100644 --- a/gcc/ira-color.cc +++ b/gcc/ira-color.cc @@ -2209,8 +2209,8 @@ assign_hard_reg (ira_allocno_t a, bool retry_p) restore_costs_from_copies (a); ALLOCNO_HARD_REGNO (a) = best_hard_regno; ALLOCNO_ASSIGNED_P (a) = true; - if (best_hard_regno >= 0) - update_costs_from_copies (a, true, ! retry_p); + if (best_hard_regno >= 0 && !retry_p) + update_costs_from_copies (a, true, true); ira_assert (ALLOCNO_CLASS (a) == aclass); /* We don't need updated costs anymore. */ ira_free_allocno_updated_costs (a); Probably the best way would be to allocate and set up data for new allocnos of pseudos created on the borders of the allocation regions. But it is too complicated and I am not sure it will give some visible performance improvement. So I'd prefer the second patch with change in assign_hard_reg. Please, check that my proposed patch works and commit it in the case of success. Thank you. > Regtested for target=xtensa-linux-uclibc, no new regressions. > > gcc/ira-color.cc | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/gcc/ira-color.cc b/gcc/ira-color.cc > index 4a1a325e8e31..4527eab39bb7 100644 > --- a/gcc/ira-color.cc > +++ b/gcc/ira-color.cc > @@ -1434,6 +1434,8 @@ update_costs_from_allocno (ira_allocno_t allocno, int hard_regno, > > if (another_allocno == from > || (ALLOCNO_COLOR_DATA (another_allocno) != NULL > + && bitmap_bit_p (consideration_allocno_bitmap, > + ALLOCNO_NUM (allocno)) > && (ALLOCNO_COLOR_DATA (allocno)->first_thread_allocno > != ALLOCNO_COLOR_DATA (another_allocno)->first_thread_allocno))) > continue;
On Mon, Nov 7, 2022 at 12:52 PM Vladimir Makarov <vmakarov@redhat.com> wrote: > even better patch: > > diff --git a/gcc/ira-color.cc b/gcc/ira-color.cc > index 4a1a325e8e3..ffe73b61c45 100644 > --- a/gcc/ira-color.cc > +++ b/gcc/ira-color.cc > @@ -2209,8 +2209,8 @@ assign_hard_reg (ira_allocno_t a, bool retry_p) > restore_costs_from_copies (a); > ALLOCNO_HARD_REGNO (a) = best_hard_regno; > ALLOCNO_ASSIGNED_P (a) = true; > - if (best_hard_regno >= 0) > - update_costs_from_copies (a, true, ! retry_p); > + if (best_hard_regno >= 0 && !retry_p) > + update_costs_from_copies (a, true, true); > ira_assert (ALLOCNO_CLASS (a) == aclass); > /* We don't need updated costs anymore. */ > ira_free_allocno_updated_costs (a); > ... > Please, check that my proposed patch works and commit it in the case of > success. Thank you for taking a look and suggesting a better fix. I've tested your version for target=xtensa-linux-uclibc, it fixes the issue without new regressions. I've committed the fix to the master branch and will backport it to gcc-10, -11 and -12 in a few days.
diff --git a/gcc/ira-color.cc b/gcc/ira-color.cc index 4a1a325e8e31..4527eab39bb7 100644 --- a/gcc/ira-color.cc +++ b/gcc/ira-color.cc @@ -1434,6 +1434,8 @@ update_costs_from_allocno (ira_allocno_t allocno, int hard_regno, if (another_allocno == from || (ALLOCNO_COLOR_DATA (another_allocno) != NULL + && bitmap_bit_p (consideration_allocno_bitmap, + ALLOCNO_NUM (allocno)) && (ALLOCNO_COLOR_DATA (allocno)->first_thread_allocno != ALLOCNO_COLOR_DATA (another_allocno)->first_thread_allocno))) continue;