aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2024-11-28 11:45:00 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2024-11-28 11:45:00 +0100
commit654afa46c90f7552af52fed30bc1a3fa21163f40 (patch)
tree2ffb5f19e3cb3b24cd5b2dbdd2874cf0f51c4dcc /gcc
parent37c98fdeac7ae2f9649d49e0cfa2631c84a329da (diff)
downloadgcc-654afa46c90f7552af52fed30bc1a3fa21163f40.zip
gcc-654afa46c90f7552af52fed30bc1a3fa21163f40.tar.gz
gcc-654afa46c90f7552af52fed30bc1a3fa21163f40.tar.bz2
rs6000: Add PowerPC inline asm redzone clobber support
The following patch on top of the https://gcc.gnu.org/pipermail/gcc-patches/2024-November/667949.html patch adds rs6000 part of the support (the only other target I'm aware of which clearly has red zone as well). 2024-11-28 Jakub Jelinek <jakub@redhat.com> * config/rs6000/rs6000.h (struct machine_function): Add asm_redzone_clobber_seen member. * config/rs6000/rs6000-logue.cc (rs6000_stack_info): Force info->push_p if cfun->machine->asm_redzone_clobber_seen. * config/rs6000/rs6000.cc (TARGET_REDZONE_CLOBBER): Redefine. (rs6000_redzone_clobber): New function. * gcc.target/powerpc/asm-redzone-1.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/config/rs6000/rs6000-logue.cc2
-rw-r--r--gcc/config/rs6000/rs6000.cc21
-rw-r--r--gcc/config/rs6000/rs6000.h1
-rw-r--r--gcc/testsuite/gcc.target/powerpc/asm-redzone-1.c71
4 files changed, 94 insertions, 1 deletions
diff --git a/gcc/config/rs6000/rs6000-logue.cc b/gcc/config/rs6000/rs6000-logue.cc
index c87058b..2efb8b1 100644
--- a/gcc/config/rs6000/rs6000-logue.cc
+++ b/gcc/config/rs6000/rs6000-logue.cc
@@ -918,7 +918,7 @@ rs6000_stack_info (void)
else if (DEFAULT_ABI == ABI_V4)
info->push_p = non_fixed_size != 0;
- else if (frame_pointer_needed)
+ else if (frame_pointer_needed || cfun->machine->asm_redzone_clobber_seen)
info->push_p = 1;
else
diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 3c25315..02a2f11 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -1751,6 +1751,9 @@ static const scoped_attribute_specs *const rs6000_attribute_table[] =
#undef TARGET_CAN_CHANGE_MODE_CLASS
#define TARGET_CAN_CHANGE_MODE_CLASS rs6000_can_change_mode_class
+#undef TARGET_REDZONE_CLOBBER
+#define TARGET_REDZONE_CLOBBER rs6000_redzone_clobber
+
#undef TARGET_CONSTANT_ALIGNMENT
#define TARGET_CONSTANT_ALIGNMENT rs6000_constant_alignment
@@ -13725,6 +13728,24 @@ rs6000_can_change_mode_class (machine_mode from,
return true;
}
+/* Implement TARGET_REDZONE_CLOBBER. */
+
+static rtx
+rs6000_redzone_clobber ()
+{
+ cfun->machine->asm_redzone_clobber_seen = true;
+ if (DEFAULT_ABI != ABI_V4)
+ {
+ int red_zone_size = TARGET_32BIT ? 220 : 288;
+ rtx base = plus_constant (Pmode, stack_pointer_rtx,
+ GEN_INT (-red_zone_size));
+ rtx mem = gen_rtx_MEM (BLKmode, base);
+ set_mem_size (mem, red_zone_size);
+ return mem;
+ }
+ return NULL_RTX;
+}
+
/* Debug version of rs6000_can_change_mode_class. */
static bool
rs6000_debug_can_change_mode_class (machine_mode from,
diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
index e0c41e1..926b6b2 100644
--- a/gcc/config/rs6000/rs6000.h
+++ b/gcc/config/rs6000/rs6000.h
@@ -2421,6 +2421,7 @@ typedef struct GTY(()) machine_function
global entry. It helps to control the patchable area before and after
local entry. */
bool global_entry_emitted;
+ bool asm_redzone_clobber_seen;
} machine_function;
#endif
diff --git a/gcc/testsuite/gcc.target/powerpc/asm-redzone-1.c b/gcc/testsuite/gcc.target/powerpc/asm-redzone-1.c
new file mode 100644
index 0000000..87b9180
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/asm-redzone-1.c
@@ -0,0 +1,71 @@
+/* { dg-do run { target lp64 } } */
+/* { dg-options "-O2" } */
+
+__attribute__((noipa)) int
+foo (void)
+{
+ int a = 1;
+ int b = 2;
+ int c = 3;
+ int d = 4;
+ int e = 5;
+ int f = 6;
+ int g = 7;
+ int h = 8;
+ int i = 9;
+ int j = 10;
+ int k = 11;
+ int l = 12;
+ int m = 13;
+ int n = 14;
+ int o = 15;
+ int p = 16;
+ int q = 17;
+ int r = 18;
+ int s = 19;
+ int t = 20;
+ int u = 21;
+ int v = 22;
+ int w = 23;
+ int x = 24;
+ int y = 25;
+ int z = 26;
+ asm volatile ("" : "+g" (a), "+g" (b), "+g" (c), "+g" (d), "+g" (e));
+ asm volatile ("" : "+g" (f), "+g" (g), "+g" (h), "+g" (i), "+g" (j));
+ asm volatile ("" : "+g" (k), "+g" (l), "+g" (m), "+g" (n), "+g" (o));
+ asm volatile ("" : "+g" (k), "+g" (l), "+g" (m), "+g" (n), "+g" (o));
+ asm volatile ("" : "+g" (p), "+g" (q), "+g" (s), "+g" (t), "+g" (u));
+ asm volatile ("" : "+g" (v), "+g" (w), "+g" (y), "+g" (z));
+#ifdef __PPC64__
+ asm volatile ("std 1,-8(1); std 1,-16(1); std 1,-24(1); std 1,-32(1)"
+ : : : "18", "19", "20", "redzone");
+#elif defined(_AIX)
+ asm volatile ("stw 1,-4(1); stw 1,-8(1); stw 1,-12(1); stw 1,-16(1)"
+ : : : "18", "19", "20", "redzone");
+#endif
+ asm volatile ("" : "+g" (a), "+g" (b), "+g" (c), "+g" (d), "+g" (e));
+ asm volatile ("" : "+g" (f), "+g" (g), "+g" (h), "+g" (i), "+g" (j));
+ asm volatile ("" : "+g" (k), "+g" (l), "+g" (m), "+g" (n), "+g" (o));
+ asm volatile ("" : "+g" (p), "+g" (q), "+g" (s), "+g" (t), "+g" (u));
+ asm volatile ("" : "+g" (v), "+g" (w), "+g" (y), "+g" (z));
+ return a + b + c + d + e + f + g + h + i + j + k + l + m + n;
+}
+
+__attribute__((noipa)) void
+bar (char *p, long *q)
+{
+ (void) p;
+ *q = 42;
+}
+
+int
+main ()
+{
+ volatile int x = 256;
+ long y;
+ bar (__builtin_alloca (x), &y);
+ if (foo () != 105)
+ __builtin_abort ();
+ if (y != 42)
+ __builtin_abort ();
+}