aarch64: Fix missed shrink-wrapping opportunity
authorRichard Sandiford <richard.sandiford@arm.com>
Thu, 28 May 2020 12:18:13 +0000 (13:18 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Thu, 28 May 2020 12:18:13 +0000 (13:18 +0100)
commit59a3d73d50a1fd3c392e421ba4c07966ce045043
tree4651c89bd2c06f3018992a76e0746efdefcab44c
parent1ccbfffb0fb614f09cf2b7b70f152d6e489cfd17
aarch64: Fix missed shrink-wrapping opportunity

wb_candidate1 and wb_candidate2 exist for two overlapping cases:
when we use an STR or STP with writeback to allocate the frame,
and when we set up a frame chain record (either using writeback
allocation or not).

However, aarch64_layout_frame was leaving these fields with
legitimate register numbers even if we decided to do neither
of those things.  This prevented those registers from being
shrink-wrapped, even though we were otherwise treating them
as normal saves and restores.

The case this patch handles isn't the common case, so it might
not be worth going out of our way to optimise it.  But I think
the patch actually makes the output of aarch64_layout_frame more
consistent.

2020-05-28  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
* config/aarch64/aarch64.h (aarch64_frame): Add a comment above
wb_candidate1 and wb_candidate2.
* config/aarch64/aarch64.c (aarch64_layout_frame): Invalidate
wb_candidate1 and wb_candidate2 if we decided not to use them.

gcc/testsuite/
* gcc.target/aarch64/shrink_wrap_1.c: New test.
gcc/config/aarch64/aarch64.c
gcc/config/aarch64/aarch64.h
gcc/testsuite/gcc.target/aarch64/shrink_wrap_1.c [new file with mode: 0644]