[PATCH] PR rtl-optimization/101885: Prevent combine from clobbering flags
authorRoger Sayle <roger@nextmovesoftware.com>
Fri, 4 Feb 2022 09:32:21 +0000 (09:32 +0000)
committerRoger Sayle <roger@nextmovesoftware.com>
Fri, 4 Feb 2022 09:38:02 +0000 (09:38 +0000)
commit49365d511ac9b64009b1de11ef8a941f59407f67
treeab69188cdad2d034a6286a862c2008164087936e
parent5b6370295d1efaa563f6d8c45f1fb779c3db452e
[PATCH] PR rtl-optimization/101885: Prevent combine from clobbering flags

This patch addresses PR rtl-optimization/101885 which is a P2 wrong code
regression.  In combine, if the resulting fused instruction is a parallel
of two sets which fails to be recognized by the backend, combine tries to
emit these as two sequential set instructions (known as split_i2i3).
As each set is recognized the backend may add any necessary "clobbers".
The code currently checks that any clobbers added to the first "set"
don't interfere with the second set, but doesn't currently handle the
case that clobbers added to the second set may interfere/kill the
destination of the first set (which must be live at this point).
The solution is to cut'n'paste the "clobber" logic from just a few
lines earlier, suitably adjusted for the second instruction.

One minor nit that may confuse a reviewer is that at this point in
the code we've lost track of which set was first and which was second
(combine chooses dynamically, and the recog processes that adds the
clobbers may have obfuscated the original SET_DEST) so the actual test
below is to confirm that any newly added clobbers (on the second set
instruction) don't overlap either set0's or set1's destination.

2022-02-04  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
PR rtl-optimization/101885
* combine.cc (try_combine): When splitting a parallel into two
sequential sets, check not only that the first doesn't clobber
the second but also that the second doesn't clobber the first.

gcc/testsuite/ChangeLog
PR rtl-optimization/101885
* gcc.dg/pr101885.c: New test case.
gcc/combine.cc
gcc/testsuite/gcc.dg/pr101885.c [new file with mode: 0644]