rtl-ssa: Fix -fcompare-debug failure [PR100303]
authorRichard Sandiford <richard.sandiford@arm.com>
Thu, 29 Apr 2021 16:24:57 +0000 (17:24 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Thu, 29 Apr 2021 16:24:57 +0000 (17:24 +0100)
commitc97351c0cf4872cc0e99e73ed17fb16659fd38b3
tree452b0e0a1354649f1b17d57fe9cc830cd4a47f57
parent449d7b40f6f6be8d7f9aa7232c73b0371f0963bf
rtl-ssa: Fix -fcompare-debug failure [PR100303]

This patch fixes an oversight in the handling of debug instructions
in rtl-ssa.  At the moment (and whether this is a good idea or not
remains to be seen), we maintain a linear RPO sequence of definitions
and non-debug uses.  If a register is defined more than once, we use
a degenerate phi to reestablish a previous definition where necessary.

However, debug instructions shouldn't of course affect codegen,
so we can't create a new definition just for them.  In those situations
we instead hang the debug use off the real definition (meaning that
debug uses do not follow a linear order wrt definitions).  Again,
it remains to be seen whether that's a good idea.

The problem in the PR was that we weren't taking this into account
when increasing (or potentially increasing) the live range of an
existing definition.  We'd create the phi even if it would only
be used by debug instructions.

The patch goes for the simple but inelegant approach of passing
a bool to say whether the use is a debug use or not.  I imagine
this area will need some tweaking based on experience in future.

gcc/
PR rtl-optimization/100303
* rtl-ssa/accesses.cc (function_info::make_use_available): Take a
boolean that indicates whether the use will only be used in
debug instructions.  Treat it in the same way that existing
cross-EBB debug references would be handled if so.
(function_info::make_uses_available): Likewise.
* rtl-ssa/functions.h (function_info::make_uses_available): Update
prototype accordingly.
(function_info::make_uses_available): Likewise.
* fwprop.c (try_fwprop_subst): Update call accordingly.
gcc/fwprop.c
gcc/rtl-ssa/accesses.cc
gcc/rtl-ssa/functions.h
gcc/testsuite/g++.dg/torture/pr100303.C [new file with mode: 0644]