]> gcc.gnu.org Git - gcc.git/commit
optabs: Don't reuse target for multi-word expansions if it overlaps operand(s) [PR97073]
authorJakub Jelinek <jakub@redhat.com>
Sun, 27 Sep 2020 21:18:26 +0000 (23:18 +0200)
committerJakub Jelinek <jakub@redhat.com>
Mon, 28 Sep 2020 09:13:55 +0000 (11:13 +0200)
commite5438c920c4d6ffad6eb85640698f4ff0307c0d7
tree7e5272757f8f064f072c6ad9371daf2409395180
parent890e17485cc3b293afee0d2a0042f59e31530fd3
optabs: Don't reuse target for multi-word expansions if it overlaps operand(s) [PR97073]

The following testcase is miscompiled on i686-linux, because
we try to expand a double-word bitwise logic operation with op0
being a (mem:DI u) and target (mem:DI u+4), i.e. partial overlap, and
thus end up with:
movl 4(%esp), %eax
andl u, %eax
movl %eax, u+4
! movl u+4, %eax optimized out
andl 8(%esp), %eax
movl %eax, u+8
rather than with the desired:
movl 4(%esp), %edx
movl 8(%esp), %eax
andl u, %edx
andl u+4, %eax
movl %eax, u+8
movl %edx, u+4
because the store of the first word to target overwrites the second word of
the operand.
expand_binop for this (and several similar places) already check for target
== op0 or target == op1, this patch just adds reg_overlap_mentioned_p calls
next to it.
Pedantically, at least for some of these it might be sufficient to force
a different target if there is overlap but target is not rtx_equal_p to
the operand (e.g. in this bitwise logical case, but e.g. not in the shift
cases where there is reordering), though that would go against the
preexisting target == op? checks and the rationale that REG_EQUAL notes in
that case isn't correct.

2020-09-27  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/97073
* optabs.c (expand_binop, expand_absneg_bit, expand_unop,
expand_copysign_bit): Check reg_overlap_mentioned_p between target
and operand(s) and if it returns true, force a pseudo as target.

* gcc.c-torture/execute/pr97073.c: New test.

(cherry picked from commit a4b31d5807f2bc67c8999b3d53369cf2a5c6e1ec)
gcc/optabs.c
gcc/testsuite/gcc.c-torture/execute/pr97073.c [new file with mode: 0644]
This page took 0.064192 seconds and 6 git commands to generate.