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: 1839371 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EndQ7oR3; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RvZ7c6S6Gz1yp0 for ; Tue, 26 Sep 2023 06:23:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8EABA3856969 for ; Mon, 25 Sep 2023 20:23:04 +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-Google-Smtp-Source: AGHT+IH9v2MU/FQqI6R3i+Ms8n9+q29P0m2RCMUlgSOmDpVFhKUF5+Pm28QneGxxFyCPgsBcQZq0ng== 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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++; +}