From e17114487df7f90d8e015efad697a3cc93845b90 Mon Sep 17 00:00:00 2001 From: Wilco Dijkstra Date: Wed, 26 Jul 2017 10:49:17 +0000 Subject: [PATCH] Fix PR46932: Block auto increment on frame pointer Block auto increment on frame pointer references. This is never beneficial since the SFP expands into SP+C or FP+C during register allocation. The generated code for the testcase is now as expected: str x30, [sp, -32]! strb w0, [sp, 31] add x0, sp, 31 bl foo3 ldr x30, [sp], 32 ret gcc/ PR middle-end/46932 * auto-inc-dec.c (parse_add_or_inc): Block autoinc on sfp. gcc/testsuite/ PR middle-end/46932 * gcc.dg/pr46932.c: New testcase. From-SVN: r250564 --- gcc/ChangeLog | 5 +++++ gcc/auto-inc-dec.c | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr46932.c | 13 +++++++++++++ 4 files changed, 29 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr46932.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2adda50f195..9bd8736ad58 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2017-07-26 Wilco Dijkstra + + PR middle-end/46932 + * auto-inc-dec.c (parse_add_or_inc): Block autoinc on sfp. + 2017-07-26 Martin Liska PR sanitize/81186 diff --git a/gcc/auto-inc-dec.c b/gcc/auto-inc-dec.c index 91fa5cf0bbe..db1bd5bba2c 100644 --- a/gcc/auto-inc-dec.c +++ b/gcc/auto-inc-dec.c @@ -769,6 +769,12 @@ parse_add_or_inc (rtx_insn *insn, bool before_mem) inc_insn.pat = pat; inc_insn.reg_res = SET_DEST (pat); inc_insn.reg0 = XEXP (SET_SRC (pat), 0); + + /* Block any auto increment of the frame pointer since it expands into + an addition and cannot be removed by copy propagation. */ + if (inc_insn.reg0 == frame_pointer_rtx) + return false; + if (rtx_equal_p (inc_insn.reg_res, inc_insn.reg0)) inc_insn.form = before_mem ? FORM_PRE_INC : FORM_POST_INC; else diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0794a290aab..e7991a67d63 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-07-26 Wilco Dijkstra + + PR middle-end/46932 + * gcc.dg/pr46932.c: New testcase. + 2017-07-26 Martin Liska PR sanitize/81186 diff --git a/gcc/testsuite/gcc.dg/pr46932.c b/gcc/testsuite/gcc.dg/pr46932.c new file mode 100644 index 00000000000..b96febcc095 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr46932.c @@ -0,0 +1,13 @@ +/* { dg-options "-O2 -fdump-rtl-auto_inc_dec" } */ + +/* Check that accesses based on the frame pointer do not + use auto increment. */ + +extern void foo(char*); +void t01(char t) +{ + char c = t; + foo(&c); +} + +/* { dg-final { scan-rtl-dump-not "success" "auto_inc_dec" } } */ -- 2.30.2