public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-2559] AArch64: use stable sorting in generating ldp/stp
@ 2021-07-28 9:51 Bin Cheng
0 siblings, 0 replies; only message in thread
From: Bin Cheng @ 2021-07-28 9:51 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:b662250c1f5e0e453f1fd6022cc47e517f70fa8e
commit r12-2559-gb662250c1f5e0e453f1fd6022cc47e517f70fa8e
Author: Bin Cheng <bin.cheng@linux.alibaba.com>
Date: Wed Jul 28 17:50:59 2021 +0800
AArch64: use stable sorting in generating ldp/stp
In some corner cases, we have code as below:
[base + 0x310] = A
[base + 0x320] = B
[base + 0x330] = C
[base + 0x320] = D
unstable sorting could result in wrong value in offset 0x320. The
patch fixes it by using gcc_stablesort.
2021-07-28 Bin Cheng <bin.cheng@linux.alibaba.com>
* config/aarch64/aarch64.c (aarch64_gen_adjusted_ldpstp): use
gcc_stablesort.
Diff:
---
gcc/config/aarch64/aarch64.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 3bdf19d71b5..e2114605901 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -24441,8 +24441,16 @@ aarch64_gen_adjusted_ldpstp (rtx *operands, bool load,
for (int i = 0; i < 8; i ++)
temp_operands[i] = operands[i];
- /* Sort the operands. */
- qsort (temp_operands, 4, 2 * sizeof (rtx *), aarch64_ldrstr_offset_compare);
+ /* Sort the operands. Note for cases as below:
+ [base + 0x310] = A
+ [base + 0x320] = B
+ [base + 0x330] = C
+ [base + 0x320] = D
+ We need stable sorting otherwise wrong data may be store to offset 0x320.
+ Also note the dead store in above case should be optimized away, but no
+ guarantees here. */
+ gcc_stablesort(temp_operands, 4, 2 * sizeof (rtx *),
+ aarch64_ldrstr_offset_compare);
/* Copy the memory operands so that if we have to bail for some
reason the original addresses are unchanged. */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-07-28 9:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-28 9:51 [gcc r12-2559] AArch64: use stable sorting in generating ldp/stp Bin Cheng
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).