From patchwork Wed Nov 22 14:06:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Makarov X-Patchwork-Id: 168386 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp1346461vqb; Wed, 22 Nov 2023 06:06:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IF8amWQzXT6Brbxh6Q3f6zlVjI0mlWIJU+fmfoey6zZQ9n3LNQ8QABWjN9SezvMxEZ8N4HV X-Received: by 2002:a0c:f40b:0:b0:679:d238:8ca6 with SMTP id h11-20020a0cf40b000000b00679d2388ca6mr2070717qvl.65.1700662002089; Wed, 22 Nov 2023 06:06:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700662002; cv=pass; d=google.com; s=arc-20160816; b=n92WoqlQd8oGgto1QAIzA3dgq1PYVTMfwypoKlYGZdz/VyIPSmsxta4cdgv9/bSFPh stJwnjNSWcGT2M/ArkslbFsLaYP88dcJV2cJZcm1Pl5La3r8EBF5m6YhJjBU0Ol+ozUP KnVDnZldZf7Q3BYi3joE95Z/3l6JPo5d0YJ68K1llc3EBnNYB2d0hoU7jzHROy7HFP/C BOzYHCwjtc4w2nXeqfglCp4GEpvdrNr2EzKFC8lxdEGyqp0YccIhdjYOX/AsgHEouaGl RkGCo2NJi1c/3V/ne2+r8Qk6jiheDQQeN2hN+IwUpgRFI+LZ1EfotpYVC5l3OfOav/14 PQIw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-language:subject:from :to:user-agent:mime-version:date:message-id:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=br3/o5QnAWADMfR7hLpFoLX/Su+pA9iAUBH3EasyPIM=; fh=XNn3asQvIblazGK92GBt13dVv+YmGV3pBS0JC29ZQco=; b=AbKtJA+tnNMwDOQR4jna52Q70MBV67kpCG+zcplRhtLLRpym8jwoQQZu/KQne1FhYs /1Yqthnws8md8yr4az4VsGP9PdmLupWs12mgXwGGC0nlBXuNPjlUi6lKIkzbIITwbai6 kLoP612YNjvPnq2UeiBeleJP8T5SLpArajsx1hh5ruSlxwrXsY+ydRwOtXMYkB0tH4kU bsscfPI6DlctIOEleGA/BkqgXfTT1bJu72QVgl271CTrvSqQJZ37Cr0O2xzvxWO0zllb MrJPdC2qkLRMP5wpFIH6h5g2hB2i6/ZaJAnd/+1y4RZTeXsRWVYNfPAObf19vVky4Q7N 4Wcg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bmclMVkx; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id s13-20020a05620a254d00b007741ee6ce02si12265560qko.104.2023.11.22.06.06.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 06:06:42 -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=@redhat.com header.s=mimecast20190719 header.b=bmclMVkx; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 55C5E38582A4 for ; Wed, 22 Nov 2023 14:06:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id B9D573858434 for ; Wed, 22 Nov 2023 14:06:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B9D573858434 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B9D573858434 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700661977; cv=none; b=rNHbjkJV9SC0oAhL2M9Ka5/IzhCJJUDYGhjQOe3Bdx/Xb5mbrnB1IxidVZ8q2Tt6r9IQ4Ofsa2dmefk04Lttx/8YqtwT+46qtn9DYJP9mQOJOUNl5ZKXpn1aV15Ax9AgVy5TH4KB//2Z4spXP4Blik2EDjHb9V2NKGScbVLvWyw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700661977; c=relaxed/simple; bh=br3/o5QnAWADMfR7hLpFoLX/Su+pA9iAUBH3EasyPIM=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=i+8GN2bKTYVzKuXNjWslIKiaZ2fGDkA+XNZOHNPoPRqFsl/YOnod8Iv/Bk1WWClD7cw6vepTAnp8axppsHQqYZQmFOI3B/7t6jzLIPty+Y0fqyEgxR5teWaaPbaJnKBUb12OinQ5KiB5XHa5OgPg+jrgWjPDyCcmjTrCY0T+3zw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700661975; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=br3/o5QnAWADMfR7hLpFoLX/Su+pA9iAUBH3EasyPIM=; b=bmclMVkxr7obrZrKN0ZaREPw7CdDxGo70atddlV9uD6Ox/UUhzHvNErqSPmdRV1TLDItqX wgxLmYWgJjhmgUDfflBh81ys0wLzTYVxttDN0cAjNjvHhlwI7o7XlspedlMNA3El6w1n3a kYUDhpJ6kTCwtkV8j18ExpWG8ZJlynE= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-588-8xggdjjfOeSco0PyqhtooA-1; Wed, 22 Nov 2023 09:06:13 -0500 X-MC-Unique: 8xggdjjfOeSco0PyqhtooA-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-679e650f9f0so28213756d6.3 for ; Wed, 22 Nov 2023 06:06:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700661972; x=1701266772; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=x6tIzU56FZfhI/LhD02YUibgRjLPQChQ7b2FVkRhaFk=; b=XlA4Uul5L5wFwL7upSbfauh4oKq5wYb2edWt1ZdEnooFYlFEX2StP61UApgr2eLQgR kfWEQSQpk2DaQtBclly7xNe7t+achkCgyu9Zvn8ZXoDpWQh7gaqQoyG+ZE6GoVS6HnfV QTTWAzFqK809dShYcEfT9o9fS1JEhicSqsohnMDEY0wesf2YUbcpNwBw9TFy15gXgksn EiWvWH0Jo+WrPT1FFJLn0AObL17lgKYd3urkeyO2dB1gpfPwGLuSNnJuH6sBifGPhm+Q wK+k8M+OkKLLeXPhI8GUmEDU7DINH13GREQXFKCzw55G/IabKFqW21RAdiHpEEbNlWog yolw== X-Gm-Message-State: AOJu0YyNvUHPu4WVa9CIuesaYESrSXMWL7oZcOVAQyp3y1KRD0jH1aqp lbBC6lp1aMVUb8VNi+ksgeYAe+5+yS24KehIGxiF4pov45TwjWvESF4vcL3KiZjd0+MOKRpaPLv Sws5hLp4ZiFqF5BstOFjy7jNBGSX8SzZOs2SRVEjsdQs/r+GB48qjHaGULXHb3VSwwWJfcKSguY 33dw== X-Received: by 2002:a05:6214:c8d:b0:675:b8ec:d6b4 with SMTP id r13-20020a0562140c8d00b00675b8ecd6b4mr2653047qvr.46.1700661972198; Wed, 22 Nov 2023 06:06:12 -0800 (PST) X-Received: by 2002:a05:6214:c8d:b0:675:b8ec:d6b4 with SMTP id r13-20020a0562140c8d00b00675b8ecd6b4mr2653011qvr.46.1700661971811; Wed, 22 Nov 2023 06:06:11 -0800 (PST) Received: from [192.168.1.88] (23-233-12-249.cpe.pppoe.ca. [23.233.12.249]) by smtp.gmail.com with ESMTPSA id r12-20020a05621410cc00b0066d132b1c8bsm4859971qvs.102.2023.11.22.06.06.11 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Nov 2023 06:06:11 -0800 (PST) Message-ID: <7d9aad3c-2ac8-21f5-4ee1-49d6042bdb07@redhat.com> Date: Wed, 22 Nov 2023 09:06:10 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 To: "gcc-patches@gcc.gnu.org" From: Vladimir Makarov Subject: [pushed] [PR112610] [IRA]: Fix using undefined dump file in IRA code during insn scheduling X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783273359407349012 X-GMAIL-MSGID: 1783273359407349012 The following patch fixes https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112610 The patch was successfully tested and bootstrapped on x86-64. commit 95f61de95bbcc2e4fb7020e27698140abea23788 Author: Vladimir N. Makarov Date: Wed Nov 22 09:01:02 2023 -0500 [IRA]: Fix using undefined dump file in IRA code during insn scheduling Part of IRA code is used for register pressure sensitive insn scheduling and live range shrinkage. Numerous changes of IRA resulted in that this IRA code uses dump file passed by the scheduler and internal ira dump file (in called functions) which can be undefined or freed by the scheduler during compiling previous functions. The patch fixes this problem. To reproduce the error valgrind should be used and GCC should be compiled with valgrind annotations. Therefor the patch does not contain the test case. gcc/ChangeLog: PR rtl-optimization/112610 * ira-costs.cc: (find_costs_and_classes): Remove arg. Use ira_dump_file for printing. (print_allocno_costs, print_pseudo_costs): Ditto. (ira_costs): Adjust call of find_costs_and_classes. (ira_set_pseudo_classes): Set up and restore ira_dump_file. diff --git a/gcc/ira-costs.cc b/gcc/ira-costs.cc index e0528e76a64..c3efd295e54 100644 --- a/gcc/ira-costs.cc +++ b/gcc/ira-costs.cc @@ -1662,16 +1662,16 @@ scan_one_insn (rtx_insn *insn) -/* Print allocnos costs to file F. */ +/* Print allocnos costs to the dump file. */ static void -print_allocno_costs (FILE *f) +print_allocno_costs (void) { int k; ira_allocno_t a; ira_allocno_iterator ai; ira_assert (allocno_p); - fprintf (f, "\n"); + fprintf (ira_dump_file, "\n"); FOR_EACH_ALLOCNO (a, ai) { int i, rclass; @@ -1681,32 +1681,34 @@ print_allocno_costs (FILE *f) enum reg_class *cost_classes = cost_classes_ptr->classes; i = ALLOCNO_NUM (a); - fprintf (f, " a%d(r%d,", i, regno); + fprintf (ira_dump_file, " a%d(r%d,", i, regno); if ((bb = ALLOCNO_LOOP_TREE_NODE (a)->bb) != NULL) - fprintf (f, "b%d", bb->index); + fprintf (ira_dump_file, "b%d", bb->index); else - fprintf (f, "l%d", ALLOCNO_LOOP_TREE_NODE (a)->loop_num); - fprintf (f, ") costs:"); + fprintf (ira_dump_file, "l%d", ALLOCNO_LOOP_TREE_NODE (a)->loop_num); + fprintf (ira_dump_file, ") costs:"); for (k = 0; k < cost_classes_ptr->num; k++) { rclass = cost_classes[k]; - fprintf (f, " %s:%d", reg_class_names[rclass], + fprintf (ira_dump_file, " %s:%d", reg_class_names[rclass], COSTS (costs, i)->cost[k]); if (flag_ira_region == IRA_REGION_ALL || flag_ira_region == IRA_REGION_MIXED) - fprintf (f, ",%d", COSTS (total_allocno_costs, i)->cost[k]); + fprintf (ira_dump_file, ",%d", + COSTS (total_allocno_costs, i)->cost[k]); } - fprintf (f, " MEM:%i", COSTS (costs, i)->mem_cost); + fprintf (ira_dump_file, " MEM:%i", COSTS (costs, i)->mem_cost); if (flag_ira_region == IRA_REGION_ALL || flag_ira_region == IRA_REGION_MIXED) - fprintf (f, ",%d", COSTS (total_allocno_costs, i)->mem_cost); - fprintf (f, "\n"); + fprintf (ira_dump_file, ",%d", + COSTS (total_allocno_costs, i)->mem_cost); + fprintf (ira_dump_file, "\n"); } } -/* Print pseudo costs to file F. */ +/* Print pseudo costs to the dump file. */ static void -print_pseudo_costs (FILE *f) +print_pseudo_costs (void) { int regno, k; int rclass; @@ -1714,21 +1716,21 @@ print_pseudo_costs (FILE *f) enum reg_class *cost_classes; ira_assert (! allocno_p); - fprintf (f, "\n"); + fprintf (ira_dump_file, "\n"); for (regno = max_reg_num () - 1; regno >= FIRST_PSEUDO_REGISTER; regno--) { if (REG_N_REFS (regno) <= 0) continue; cost_classes_ptr = regno_cost_classes[regno]; cost_classes = cost_classes_ptr->classes; - fprintf (f, " r%d costs:", regno); + fprintf (ira_dump_file, " r%d costs:", regno); for (k = 0; k < cost_classes_ptr->num; k++) { rclass = cost_classes[k]; - fprintf (f, " %s:%d", reg_class_names[rclass], + fprintf (ira_dump_file, " %s:%d", reg_class_names[rclass], COSTS (costs, regno)->cost[k]); } - fprintf (f, " MEM:%i\n", COSTS (costs, regno)->mem_cost); + fprintf (ira_dump_file, " MEM:%i\n", COSTS (costs, regno)->mem_cost); } } @@ -1939,7 +1941,7 @@ calculate_equiv_gains (void) and their best costs. Set up preferred, alternative and allocno classes for pseudos. */ static void -find_costs_and_classes (FILE *dump_file) +find_costs_and_classes (void) { int i, k, start, max_cost_classes_num; int pass; @@ -1991,8 +1993,8 @@ find_costs_and_classes (FILE *dump_file) classes to guide the selection. */ for (pass = start; pass <= flag_expensive_optimizations; pass++) { - if ((!allocno_p || internal_flag_ira_verbose > 0) && dump_file) - fprintf (dump_file, + if ((!allocno_p || internal_flag_ira_verbose > 0) && ira_dump_file) + fprintf (ira_dump_file, "\nPass %i for finding pseudo/allocno costs\n\n", pass); if (pass != start) @@ -2244,8 +2246,8 @@ find_costs_and_classes (FILE *dump_file) alt_class = NO_REGS; setup_reg_classes (i, best, alt_class, regno_aclass[i]); if ((!allocno_p || internal_flag_ira_verbose > 2) - && dump_file != NULL) - fprintf (dump_file, + && ira_dump_file != NULL) + fprintf (ira_dump_file, " r%d: preferred %s, alternative %s, allocno %s\n", i, reg_class_names[best], reg_class_names[alt_class], reg_class_names[regno_aclass[i]]); @@ -2295,16 +2297,16 @@ find_costs_and_classes (FILE *dump_file) } ALLOCNO_CLASS_COST (a) = allocno_cost; } - if (internal_flag_ira_verbose > 2 && dump_file != NULL + if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL && (pass == 0 || pref[a_num] != best)) { - fprintf (dump_file, " a%d (r%d,", a_num, i); + fprintf (ira_dump_file, " a%d (r%d,", a_num, i); if ((bb = ALLOCNO_LOOP_TREE_NODE (a)->bb) != NULL) - fprintf (dump_file, "b%d", bb->index); + fprintf (ira_dump_file, "b%d", bb->index); else - fprintf (dump_file, "l%d", + fprintf (ira_dump_file, "l%d", ALLOCNO_LOOP_TREE_NODE (a)->loop_num); - fprintf (dump_file, ") best %s, allocno %s\n", + fprintf (ira_dump_file, ") best %s, allocno %s\n", reg_class_names[best], reg_class_names[aclass]); } @@ -2329,13 +2331,13 @@ find_costs_and_classes (FILE *dump_file) } } - if (internal_flag_ira_verbose > 4 && dump_file) + if (internal_flag_ira_verbose > 4 && ira_dump_file) { if (allocno_p) - print_allocno_costs (dump_file); + print_allocno_costs (); else - print_pseudo_costs (dump_file); - fprintf (dump_file,"\n"); + print_pseudo_costs (); + fprintf (ira_dump_file,"\n"); } } ira_free (regno_best_class); @@ -2594,7 +2596,7 @@ ira_costs (void) /* Process equivs in reload to update costs through hook ira_adjust_equiv_reg_cost. */ calculate_elim_costs_all_insns (); - find_costs_and_classes (ira_dump_file); + find_costs_and_classes (); setup_allocno_class_and_costs (); finish_regno_cost_classes (); finish_costs (); @@ -2606,17 +2608,20 @@ ira_costs (void) void ira_set_pseudo_classes (bool define_pseudo_classes, FILE *dump_file) { + FILE *saved_file = ira_dump_file; allocno_p = false; internal_flag_ira_verbose = flag_ira_verbose; + ira_dump_file = dump_file; cost_elements_num = max_reg_num (); init_costs (); initiate_regno_cost_classes (); - find_costs_and_classes (dump_file); + find_costs_and_classes (); finish_regno_cost_classes (); if (define_pseudo_classes) pseudo_classes_defined_p = true; finish_costs (); + ira_dump_file = saved_file; }