* [PATCH] Avoid creating (const (reg ...)) [PR108603]
@ 2023-03-02 10:21 Richard Sandiford
2023-03-02 10:26 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Richard Sandiford @ 2023-03-02 10:21 UTC (permalink / raw)
To: gcc-patches
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.
Tested on aarch64-linux-gnu & x86_64-linux-gnu. OK to install?
Richard
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.
---
gcc/explow.cc | 11 ++++++++---
gcc/testsuite/gcc.target/aarch64/sve/pr108603.c | 8 ++++++++
2 files changed, 16 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/pr108603.c
diff --git a/gcc/explow.cc b/gcc/explow.cc
index 83439b32abe..32e9498ee07 100644
--- a/gcc/explow.cc
+++ b/gcc/explow.cc
@@ -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
index 00000000000..a2aea9f0b12
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sve/pr108603.c
@@ -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];
+}
--
2.25.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Avoid creating (const (reg ...)) [PR108603]
2023-03-02 10:21 [PATCH] Avoid creating (const (reg ...)) [PR108603] Richard Sandiford
@ 2023-03-02 10:26 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-03-02 10:26 UTC (permalink / raw)
To: Richard Sandiford, gcc-patches
On Thu, Mar 2, 2023 at 11:21 AM Richard Sandiford via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> 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.
>
> Tested on aarch64-linux-gnu & x86_64-linux-gnu. OK to install?
OK.
Thanks,
Richard.
> Richard
>
>
> 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.
> ---
> gcc/explow.cc | 11 ++++++++---
> gcc/testsuite/gcc.target/aarch64/sve/pr108603.c | 8 ++++++++
> 2 files changed, 16 insertions(+), 3 deletions(-)
> create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/pr108603.c
>
> diff --git a/gcc/explow.cc b/gcc/explow.cc
> index 83439b32abe..32e9498ee07 100644
> --- a/gcc/explow.cc
> +++ b/gcc/explow.cc
> @@ -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
> index 00000000000..a2aea9f0b12
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/aarch64/sve/pr108603.c
> @@ -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];
> +}
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-03-02 10:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-02 10:21 [PATCH] Avoid creating (const (reg ...)) [PR108603] Richard Sandiford
2023-03-02 10:26 ` Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).