From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 16B2E3858C3A for ; Mon, 7 Nov 2022 20:52:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 16B2E3858C3A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667854358; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ysCsZ8BitKWrFMkY/KGx2+I1VhuMS/yGXwGQ+8Nhpj0=; b=Ch+vESHWjDsVmEBzJZFiXNx6fcPj/E5b+cfKXyU8RYjF5xOQnJCYjMKAVVEGW18tDVG6O2 X7BhecWucLPC87nbG8A7TzGWa06p4YMpqUuBknMHM1Ii3JpZTY6PfOy8f0yqDuCF2svgOB 3SFYxjzihP05KnIyHGxBR145TuJPyuI= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-189-80giUIAaM0ugxpZH9ZTCFA-1; Mon, 07 Nov 2022 15:52:37 -0500 X-MC-Unique: 80giUIAaM0ugxpZH9ZTCFA-1 Received: by mail-qv1-f69.google.com with SMTP id g1-20020ad45101000000b004bb5eb9913fso8378060qvp.16 for ; Mon, 07 Nov 2022 12:52:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ysCsZ8BitKWrFMkY/KGx2+I1VhuMS/yGXwGQ+8Nhpj0=; b=1UNqajnGVZVmaivoqdOYHiBTCQ12YVmxsAv/sj8tR3RHdfIYypq7x9T3LAs+FYqO30 F7mEtEcCbWv2EZRbxl8EXbi146vPHK/U5Dt0ESmEAQuolmpl49GfajHYgVsR3eIyV9nY hPeb1TivCqrkazyD7q97rX6lnUfoI//3dETYeXpp0VnFEeMn+UmgOW4MM4qaOV9+9akM HFj+hqP59x3HsW7ZhkEG1g55j7O+fru3xxJnVfjBeRCgyIGbvjJqLRF3nLKeZQo01doq 4o4IDCbEh7ZHTBN35C0kzzbvBGENKZucejknH0TTP+Crge7oIZrq0retGxelKJFpTGzT iJxA== X-Gm-Message-State: ACrzQf3ttlbHdrLi00G/EtpHB8hEdTNA2P0XW2it3j5TEr47xH0rQvJT 7VSaN5u03zgBjnZojx7jAaKZloSXNxnkJQqH33B7AIUVozDfGOwXiX7RM31miKNUivm4qX053Vt gPttujSjw/USSz6oMZQ== X-Received: by 2002:a05:6214:1d06:b0:4b9:1938:b6ca with SMTP id e6-20020a0562141d0600b004b91938b6camr46507676qvd.114.1667854356669; Mon, 07 Nov 2022 12:52:36 -0800 (PST) X-Google-Smtp-Source: AMsMyM6BLkk1nZXDp2A7ApBbLAuFh7BtkVa2I+nm7NqzyYNQZKEGA2f3EG4ZToXYqb/O4SFz2V/okQ== X-Received: by 2002:a05:6214:1d06:b0:4b9:1938:b6ca with SMTP id e6-20020a0562141d0600b004b91938b6camr46507650qvd.114.1667854356381; Mon, 07 Nov 2022 12:52:36 -0800 (PST) Received: from [192.168.1.113] (23-233-12-120.cpe.pppoe.ca. [23.233.12.120]) by smtp.gmail.com with ESMTPSA id ay14-20020a05620a178e00b006bb366779a4sm7698959qkb.6.2022.11.07.12.52.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 07 Nov 2022 12:52:36 -0800 (PST) Message-ID: Date: Mon, 7 Nov 2022 15:52:35 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [RFA] gcc: fix PR rtl-optimization/107482 To: Max Filippov , gcc-patches@gcc.gnu.org References: <20221107094645.3718427-1-jcmvbkbc@gmail.com> From: Vladimir Makarov In-Reply-To: <20221107094645.3718427-1-jcmvbkbc@gmail.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00,BODY_8BITS,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_NUMSUBJECT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 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;