From patchwork Mon Sep 25 20:22:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Makarov X-Patchwork-Id: 144559 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1462240vqu; Mon, 25 Sep 2023 13:23:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH+U+PINed8PkL8GnSaW5G2K21pLXncVQR+FpkJeB1KONtCTMbk0AayugeDBqUsVijQWpab X-Received: by 2002:a05:6402:198:b0:51e:5251:8f45 with SMTP id r24-20020a056402019800b0051e52518f45mr6719226edv.4.1695673406424; Mon, 25 Sep 2023 13:23:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695673406; cv=none; d=google.com; s=arc-20160816; b=nlF2YXUg5dy4NVb6hmcIQBpISqtzyF0fTnSczYuzCyHapsBvQdVIto+Mx+nOV3QLuV bU0Y3YfHuXx2UtWJV2rnquCnawW7h2ax/C73QGfusiMachFhpT3wSHmpOUekSnwek2+w P+JCHLZWy7nr7hrMvWthAm+Ypxj7y8OdCULIElPJEoVi91fngjD7XdR7TEvf4FLZIa1X HK07pKMlb7tL/RlTn/Qze1dEQx30b/DrUz7C/oeKkpMnHKUmYE4vSEtVo/yPo0rsbSSc /wYC02aYTSx2opJMHDPdbuFNWltqRXfO95xaaMO8l5ZVKMHf8YnOX/VNO23TkKmQkp2C 3d1A== ARC-Message-Signature: i=1; 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 :dmarc-filter:delivered-to; bh=68HBF8rfA/gzYv5tpqQga/894f/82GVITZNwK+RdALg=; fh=XNn3asQvIblazGK92GBt13dVv+YmGV3pBS0JC29ZQco=; b=HChcKj2FDIjsFuNQ2FVgZyHbbfXntoTAPYv9NSZ7MAsWcQ/XiFjWnQI5cPkpaESWb/ Z0UIYQ+IAn9DqP/n/TWNFzJNgqCoua9bSMo6aYFsmCovDoQkf3nwUin963ok75dzoUgr VRR0dEvQhD0MVNSSNkG23Ha+290vQNvjNot0uKk2A+6dqKQsxmhdqPcwHrULX44MhMRh FeS7LbhbihZjx+WUbrnlhtOKYMAjbLJIUEfzu4PXqswEJaB0NWWHw3YbQaAGWLy/keS9 UtgljVciOEIrxZe38qZ1RHV5Fm5+VhSDgZcw6gmxpsyxxik1B6E+Pc2/EcgWjEYiHuUK xHgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EndQ7oR3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id n22-20020aa7db56000000b005330b2d190csi9280355edt.224.2023.09.25.13.23.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 13:23:26 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EndQ7oR3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 CEC8F3856973 for ; Mon, 25 Sep 2023 20:23:18 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id 450BF3858D3C for ; Mon, 25 Sep 2023 20:22:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 450BF3858D3C 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=1695673371; 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=68HBF8rfA/gzYv5tpqQga/894f/82GVITZNwK+RdALg=; b=EndQ7oR3SP+JjECSMza8unOTCFBrFKUx85lTHABY7pxQeVtMp0Q4RJifr7wtW71SCC0aW1 N0X+z5jWq/Yhn6fn9Y1i26TUDiUbwBbH8LUWSwFOGoW6/iU4jEC3NKDFJ3hzF/6lUA2AiY dj474RAiK9c0DZXfkzr7AblV0GvfrSU= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-691-SdFoDOa5PLaEhyS3boRU3g-1; Mon, 25 Sep 2023 16:22:50 -0400 X-MC-Unique: SdFoDOa5PLaEhyS3boRU3g-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-65af1fad7f1so93911196d6.2 for ; Mon, 25 Sep 2023 13:22:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695673369; x=1696278169; 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=hUGRGxrVIAoBWcOvvQVrQzvCMoth6dvBwOVZPJuCoZs=; b=X/28ZTBOY1JpJzRe32GwH1Q1VSAM9fcJoNrajsYwkFmkCsfTlQsW7BOeVFKnTtJJ59 GGeMQ5SESLyK5Hn1z7pBxRmjlC4O3GWMJf/ze/8NMJSnqXX7mbpw162Efjabie/ukFJj z/oO34xnuPXPOCyXwuK68XgOmgBCCro7aSCIJ4RX5epoHJ04RdhFEEdJ+eWnKHpgCHIV YPepJuEWF6NU1C/31/G7+/aWb60CNTO5DLw6w543Z+2G89c1o7+3M4FnTIQURixN/Rhy zKRE+ZMmq051wxEKZpug7DJkcXmsIt67hutvcMqrCHWtTNgkx1YxS4C7f0xtoqjVPhWI JZig== X-Gm-Message-State: AOJu0Ywd6vcP7K8GCN20TpayvkQKdJSH35zBLCWlu+9MTOpSu+OS/ZOs OEZJZvse4ZBv1La32gqDku/6nHAT2x3Ku7z8fBsn6v8jVq5+qM9ygZZqulJ4/as+D8mFXjfq8yx IjAMWY2mw22/4A9MC7nWxQV4vkHnSa5KEn5pR1xaJqP+YRj66aTE0lAmf5q5/exUBb4HdsGd1/y jFKA== X-Received: by 2002:ad4:4d54:0:b0:655:71df:4c7d with SMTP id m20-20020ad44d54000000b0065571df4c7dmr7347210qvm.56.1695673369375; Mon, 25 Sep 2023 13:22:49 -0700 (PDT) X-Received: by 2002:ad4:4d54:0:b0:655:71df:4c7d with SMTP id m20-20020ad44d54000000b0065571df4c7dmr7347195qvm.56.1695673368915; Mon, 25 Sep 2023 13:22:48 -0700 (PDT) Received: from [192.168.1.88] (23-233-12-249.cpe.pppoe.ca. [23.233.12.249]) by smtp.gmail.com with ESMTPSA id q7-20020a0cf5c7000000b00656506a1881sm4444262qvm.74.2023.09.25.13.22.47 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 Sep 2023 13:22:48 -0700 (PDT) Message-ID: <1b7a2897-2aa4-b1ed-0c42-afdef403ff06@redhat.com> Date: Mon, 25 Sep 2023 16:22:47 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 To: "gcc-patches@gcc.gnu.org" From: Vladimir Makarov Subject: [pushed] [PR111497][LRA]: Copy substituted equivalence X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.1 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_H4, RCVD_IN_MSPIKE_WL, 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 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: 1778042437638030454 X-GMAIL-MSGID: 1778042437638030454 The following patch solves https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111497 The patch was successfully tested and bootstrapped on x86-64 and aarch64. commit 3c23defed384cf17518ad6c817d94463a445d21b Author: Vladimir N. Makarov Date: Mon Sep 25 16:19:50 2023 -0400 [PR111497][LRA]: Copy substituted equivalence When we substitute the equivalence and it becomes shared, we can fail to correctly update reg info used by LRA. This can result in wrong code generation, e.g. because of incorrect live analysis. It can also result in compiler crash as the pseudo survives RA. This is what exactly happened for the PR. This patch solves this problem by unsharing substituted equivalences. gcc/ChangeLog: PR middle-end/111497 * lra-constraints.cc (lra_constraints): Copy substituted equivalence. * lra.cc (lra): Change comment for calling unshare_all_rtl_again. gcc/testsuite/ChangeLog: PR middle-end/111497 * g++.target/i386/pr111497.C: new test. diff --git a/gcc/lra-constraints.cc b/gcc/lra-constraints.cc index 3aaa4906999..76a1393ab23 100644 --- a/gcc/lra-constraints.cc +++ b/gcc/lra-constraints.cc @@ -5424,6 +5424,11 @@ lra_constraints (bool first_p) loc_equivalence_callback, curr_insn); if (old != *curr_id->operand_loc[0]) { + /* If we substitute pseudo by shared equivalence, we can fail + to update LRA reg info and this can result in many + unexpected consequences. So keep rtl unshared: */ + *curr_id->operand_loc[0] + = copy_rtx (*curr_id->operand_loc[0]); lra_update_insn_regno_info (curr_insn); changed_p = true; } diff --git a/gcc/lra.cc b/gcc/lra.cc index 563aff10b96..361f84fdacb 100644 --- a/gcc/lra.cc +++ b/gcc/lra.cc @@ -2579,9 +2579,8 @@ lra (FILE *f) if (inserted_p) commit_edge_insertions (); - /* Replacing pseudos with their memory equivalents might have - created shared rtx. Subsequent passes would get confused - by this, so unshare everything here. */ + /* Subsequent passes expect that rtl is unshared, so unshare everything + here. */ unshare_all_rtl_again (get_insns ()); if (flag_checking) diff --git a/gcc/testsuite/g++.target/i386/pr111497.C b/gcc/testsuite/g++.target/i386/pr111497.C new file mode 100644 index 00000000000..a645bb95907 --- /dev/null +++ b/gcc/testsuite/g++.target/i386/pr111497.C @@ -0,0 +1,22 @@ +// { dg-do compile { target ia32 } } +// { dg-options "-march=i686 -mtune=generic -fPIC -O2 -g" } + +class A; +struct B { const char *b1; int b2; }; +struct C : B { C (const char *x, int y) { b1 = x; b2 = y; } }; +struct D : C { D (B x) : C (x.b1, x.b2) {} }; +struct E { E (A *); }; +struct F : E { D f1, f2, f3, f4, f5, f6; F (A *, const B &, const B &, const B &); }; +struct G : F { G (A *, const B &, const B &, const B &); }; +struct H { int h; }; +struct I { H i; }; +struct J { I *j; }; +struct A : J {}; +inline F::F (A *x, const B &y, const B &z, const B &w) + : E(x), f1(y), f2(z), f3(w), f4(y), f5(z), f6(w) {} +G::G (A *x, const B &y, const B &z, const B &w) : F(x, y, z, w) +{ + H *h = &x->j->i; + if (h) + h->h++; +}