]> git.ipfire.org Git - thirdparty/gcc.git/commit
shrink-wrapping: Fix up prologue block discovery [PR103860]
authorJakub Jelinek <jakub@redhat.com>
Thu, 30 Dec 2021 13:23:18 +0000 (14:23 +0100)
committerJakub Jelinek <jakub@redhat.com>
Wed, 11 May 2022 05:58:35 +0000 (07:58 +0200)
commit5d96fb401e1c03b6b6a6ec2c5276dfdc479bb3e4
treed6c912c978cd70dbc17a6b26fbfb25222aec1081
parentd7dbfed37a3622f72a6c2607343fa62ed579fb40
shrink-wrapping: Fix up prologue block discovery [PR103860]

The following testcase is miscompiled, because a prologue which
contains subq $8, %rsp instruction is emitted at the start of
a basic block which contains conditional jump that depends on
flags register set in an earlier basic block, the prologue instruction
then clobbers those flags.
Normally this case is checked by can_get_prologue predicate, but this
is done only at the start of the loop.  If we update pro later in the
loop (because some bb shouldn't be duplicated) and then don't push
anything further into vec and the vec is already empty (this can happen
when the new pro is already in bb_with bitmask and either has no successors
(that is the case in the testcase where that bb ends with a trap) or
all the successors are already in bb_with, then the loop doesn't iterate
further and can_get_prologue will not be checked.

The following simple patch makes sure we call can_get_prologue even after
the last former iteration when vec is already empty and only break from
the loop afterwards (and only if the updating of pro done because of
!can_get_prologue didn't push anything into vec again).

2021-12-30  Jakub Jelinek  <jakub@redhat.com>

PR rtl-optimization/103860
* shrink-wrap.c (try_shrink_wrapping): Make sure can_get_prologue is
called on pro even if nothing further is pushed into vec.

* gcc.dg/pr103860.c: New test.

(cherry picked from commit 1820137ba624d7eb2004a10f9632498b6bc1696a)
gcc/shrink-wrap.c
gcc/testsuite/gcc.dg/pr103860.c [new file with mode: 0644]