PR target/106122: Don't update %esp via the stack with -Oz on x86.
authorRoger Sayle <roger@nextmovesoftware.com>
Sun, 3 Jul 2022 13:01:17 +0000 (14:01 +0100)
committerRoger Sayle <roger@nextmovesoftware.com>
Sun, 3 Jul 2022 13:01:17 +0000 (14:01 +0100)
commit55899e33de74082521708a58fdc79510e0c5efad
tree016e63655b7dc61143c9d908c274b4c5bf9a1449
parenta60152e87cc0900ed01854cdda8c2be6aab34af2
PR target/106122: Don't update %esp via the stack with -Oz on x86.

When optimizing for size with -Oz, setting a register can be minimized by
pushing an immediate value to the stack and popping it to the destination.
Alas the one general register that shouldn't be updated via the stack is
the stack pointer itself, where "pop %esp" can't be represented in GCC's
RTL ("use of a register mentioned in pre_inc, pre_dec, post_inc or
post_dec is not permitted within the same instruction").  This patch
fixes PR target/106122 by explicitly checking for SP_REG in the
problematic peephole2.

2022-07-O3  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
PR target/106122
* config/i386/i386.md (peephole2): Avoid generating pop %esp
when optimizing for size.

gcc/testsuite/ChangeLog
PR target/106122
* gcc.target/i386/pr106122.c: New test case.
gcc/config/i386/i386.md
gcc/testsuite/gcc.target/i386/pr106122.c [new file with mode: 0644]