aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Schwinge <tschwinge@baylibre.com>2024-04-10 10:45:56 +0200
committerThomas Schwinge <tschwinge@baylibre.com>2024-04-10 10:45:56 +0200
commitd2bcecd7fd914adf55daac7d36745b03b3279c49 (patch)
tree8e6e5ae86e8fa52e5e730dd9787d7018e9858d84
parentca224bde2989de54fc33fae46df560b7f5af835e (diff)
parentdb4e496aadf1d7ab1c5af24410394d1551ddd3f0 (diff)
downloadgcc-d2bcecd7fd914adf55daac7d36745b03b3279c49.zip
gcc-d2bcecd7fd914adf55daac7d36745b03b3279c49.tar.gz
gcc-d2bcecd7fd914adf55daac7d36745b03b3279c49.tar.bz2
Merge commit 'a5258f3a11ab577835ef5e93be5cb65ec9e44132^' into HEAD
-rw-r--r--gcc/config/aarch64/aarch64.cc11
-rw-r--r--gcc/testsuite/gcc.target/aarch64/pr112573.c15
2 files changed, 26 insertions, 0 deletions
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 7d1f8c6..e6bd3fd 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -12617,6 +12617,17 @@ aarch64_legitimize_address (rtx x, rtx /* orig_x */, machine_mode mode)
not to split a CONST for some forms of address expression, otherwise
it will generate sub-optimal code. */
+ /* First split X + CONST (base, offset) into (base + X) + offset. */
+ if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST)
+ {
+ poly_int64 offset;
+ rtx base = strip_offset (XEXP (x, 1), &offset);
+
+ base = expand_binop (Pmode, add_optab, base, XEXP (x, 0),
+ NULL_RTX, true, OPTAB_DIRECT);
+ x = plus_constant (Pmode, base, offset);
+ }
+
if (GET_CODE (x) == PLUS && CONST_INT_P (XEXP (x, 1)))
{
rtx base = XEXP (x, 0);
diff --git a/gcc/testsuite/gcc.target/aarch64/pr112573.c b/gcc/testsuite/gcc.target/aarch64/pr112573.c
new file mode 100644
index 0000000..be04c0c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/pr112573.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-section-anchors" } */
+
+char a[100];
+
+void f1 (int x, int y)
+{
+ *((a + y) + 3) = x;
+ *((a + y) + 2) = x;
+ *((a + y) + 1) = x;
+ *((a + y) + 0) = x;
+}
+
+/* { dg-final { scan-assembler-times "strb" 4 } } */
+/* { dg-final { scan-assembler-times "adrp" 1 } } */