[PR103149] detach values through mem only if general regs won't do
authorAlexandre Oliva <oliva@adacore.com>
Sat, 4 Dec 2021 03:17:18 +0000 (00:17 -0300)
committerAlexandre Oliva <oliva@gnu.org>
Wed, 8 Dec 2021 01:14:02 +0000 (22:14 -0300)
commit0485ce9128f272fe7ccb48672f69d7be6bb26a9c
treed93e13b124e2130e2a4fd57cd3582b3cd37e0a5d
parent1f6b0003b6601656bef4869d9c724e2a263cb64c
[PR103149] detach values through mem only if general regs won't do

When hardening compares or conditional branches, we perform redundant
tests, and to prevent them from being optimized out, we use asm
statements that preserve a value used in a compare, but in a way that
the compiler can no longer assume it's the same value, so it can't
optimize the redundant test away.

We used to use +g, but that requires general regs or mem.  You might
think that, if a reg constraint can't be satisfied, the register
allocator will fall back to memory, but that's not so: we decide on
matching MEMs very early on, by using the same addressable operand on
both input and output, and only if the constraint does not allow
registers.  If it does, we use gimple registers and then pseudos as
inputs and outputs, and then inputs can be substituted by equivalent
expressions, and then, if no register contraint fits (e.g. because
that mode won't fit in general regs, or won't fit in regs at all), the
register allocator will give up before even trying to allocate some
temporary memory to unify input and output.

This patch arranges for us to create and use the temporary stack slot
if we can tell the mode requires memory, or won't otherwise fit in
general regs, and thus to use +m for that asm.

for  gcc/ChangeLog

PR middle-end/103149
* gimple-harden-conditionals.cc (detach_value): Use memory if
general regs won't do.

for  gcc/testsuite/ChangeLog

PR middle-end/103149
* gcc.target/aarch64/pr103149.c: New.
gcc/gimple-harden-conditionals.cc
gcc/testsuite/gcc.target/aarch64/pr103149.c [new file with mode: 0644]