]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Avoid creating (const (reg ...)) [PR108603]
authorRichard Sandiford <richard.sandiford@arm.com>
Mon, 3 Apr 2023 08:57:07 +0000 (09:57 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Mon, 3 Apr 2023 08:57:07 +0000 (09:57 +0100)
convert_memory_address_addr_space_1 has two modes: one in which it
tries to create a self-contained RTL expression (which might fail)
and one in which it can emit new instructions where necessary.

When handling a CONST, the function recurses into the CONST's
operand and then constifies the result.  But that's only valid if
the result is still a self-contained expression.  If new instructions
have been emitted, the expression will refer to the (non-constant)
results of those instructions.

In the PR, this caused us to emit a nonsensical (const (reg ...))
REG_EQUAL note.

gcc/
PR tree-optimization/108603
* explow.cc (convert_memory_address_addr_space_1): Only wrap
the result of a recursive call in a CONST if no instructions
were emitted.

gcc/testsuite/
PR tree-optimization/108603
* gcc.target/aarch64/sve/pr108603.c: New test.

(cherry picked from commit b09dc74801cf4e19bdf5fcd18a5cd53fc9e9ca9a)

gcc/explow.cc
gcc/testsuite/gcc.target/aarch64/sve/pr108603.c [new file with mode: 0644]

index ddb4d6ae3600542f8d2bb5617cdd3933a9fae6c0..d8aa75ee9baffa75519424a745e8b928645f1d07 100644 (file)
@@ -349,9 +349,14 @@ convert_memory_address_addr_space_1 (scalar_int_mode to_mode ATTRIBUTE_UNUSED,
       return temp;
 
     case CONST:
-      temp = convert_memory_address_addr_space_1 (to_mode, XEXP (x, 0), as,
-                                                 true, no_emit);
-      return temp ? gen_rtx_CONST (to_mode, temp) : temp;
+      {
+       auto *last = no_emit ? nullptr : get_last_insn ();
+       temp = convert_memory_address_addr_space_1 (to_mode, XEXP (x, 0), as,
+                                                   true, no_emit);
+       if (temp && (no_emit || last == get_last_insn ()))
+         return gen_rtx_CONST (to_mode, temp);
+       return temp;
+      }
 
     case PLUS:
     case MULT:
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pr108603.c b/gcc/testsuite/gcc.target/aarch64/sve/pr108603.c
new file mode 100644 (file)
index 0000000..a2aea9f
--- /dev/null
@@ -0,0 +1,8 @@
+/* { dg-options "-O2 -mabi=ilp32 -fdata-sections" } */
+
+int a[128];
+long long *p;
+void f() {
+  for (long i = 0; i < sizeof(long); i++)
+    p[i] = a[i];
+}