loop-invariant: Fix -fcompare-debug failure [PR103837]
authorJakub Jelinek <jakub@redhat.com>
Tue, 28 Dec 2021 16:40:17 +0000 (17:40 +0100)
committerJakub Jelinek <jakub@redhat.com>
Tue, 28 Dec 2021 16:40:17 +0000 (17:40 +0100)
commit3c5fd3616f73fbcd241cc3a5e09275c2b0c49bd4
tree866d5f0b3c7bae8a20a130111b7a98673e4be884
parent78ee8381bf0ebd09a92936bdb9e1b5c9fc85ad88
loop-invariant: Fix -fcompare-debug failure [PR103837]

In the following testcase we have a -fcompare-debug failure, because
can_move_invariant_reg doesn't ignore DEBUG_INSNs in its decisions.
In the testcase we have due to uninitialized variable:
  loop_header
    debug_insn using pseudo84
    pseudo84 = invariant
    insn using pseudo84
  end loop
and with -g decide not to move the pseudo84 = invariant before the
loop header; in this case not resetting the debug insns might be fine.
But, we could have also:
  pseudo84 = whatever
  loop_header
    debug_insn using pseudo84
    pseudo84 = invariant
    insn using pseudo84
  end loop
and in that case not resetting the debug insns would result in wrong-debug.
And, we don't really have generally a good substitution on what pseudo84
contains, it could inherit various values from different paths.
So, the following patch ignores DEBUG_INSNs in the decisions, and if there
are any that previously prevented the optimization, resets them before
return true.

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

PR rtl-optimization/103837
* loop-invariant.c (can_move_invariant_reg): Ignore DEBUG_INSNs in
the decisions whether to return false or continue and right before
returning true reset those debug insns that previously caused
returning false.

* gcc.dg/pr103837.c: New test.
gcc/loop-invariant.c
gcc/testsuite/gcc.dg/pr103837.c [new file with mode: 0644]