aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir N. Makarov <vmakarov@redhat.com>2023-09-25 16:19:50 -0400
committerRichard Biener <rguenther@suse.de>2024-06-12 13:39:20 +0200
commit959cef942508b818c7dcb8df0f3c7bf4968d406a (patch)
tree4afa2e7abf5f1dffe62011edc8d6718e11721781
parent844ff32c04a4e36bf69f3878634d9f50aec3a332 (diff)
downloadgcc-959cef942508b818c7dcb8df0f3c7bf4968d406a.zip
gcc-959cef942508b818c7dcb8df0f3c7bf4968d406a.tar.gz
gcc-959cef942508b818c7dcb8df0f3c7bf4968d406a.tar.bz2
[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. (cherry picked from commit 3c23defed384cf17518ad6c817d94463a445d21b)
-rw-r--r--gcc/lra-constraints.cc5
-rw-r--r--gcc/lra.cc5
-rw-r--r--gcc/testsuite/g++.target/i386/pr111497.C22
3 files changed, 29 insertions, 3 deletions
diff --git a/gcc/lra-constraints.cc b/gcc/lra-constraints.cc
index d92ab76..04b0b6f 100644
--- a/gcc/lra-constraints.cc
+++ b/gcc/lra-constraints.cc
@@ -5139,6 +5139,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 1444cb7..5e29d32 100644
--- a/gcc/lra.cc
+++ b/gcc/lra.cc
@@ -2535,9 +2535,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 0000000..a645bb9
--- /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++;
+}