https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62151
bin.cheng <amker.cheng at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |amker.cheng at gmail dot com,
| |law at redhat dot com
--- Comment #12 from bin.cheng <amker.cheng at gmail dot com> ---
Seems there are two problems in distribute_notes when handling REG_DEAD note.
Quote from source code:
if (from_insn
&& CALL_P (from_insn)
&& find_reg_fusage (from_insn, USE, XEXP (note, 0)))
place = from_insn;
else if (reg_referenced_p (XEXP (note, 0), PATTERN (i3)))
place = i3;
else if (i2 != 0 && next_nonnote_nondebug_insn (i2) == i3
&& reg_referenced_p (XEXP (note, 0), PATTERN (i2)))
place = i2;
else if ((rtx_equal_p (XEXP (note, 0), elim_i2)
&& !(i2mod
&& reg_overlap_mentioned_p (XEXP (note, 0),
i2mod_old_rhs)))
|| rtx_equal_p (XEXP (note, 0), elim_i1)
|| rtx_equal_p (XEXP (note, 0), elim_i0))
break;
tem_insn = i3;
Issue 1, Checks against elim_i0/elim_i1/elim_i2 and their values are not
correct for some cases. In this case as below
i0: r0 <- i0src
i1: r1 <- i1src (using r0)
REG_DEAD (r0)
i2: r0 <- i2src (using r1)
i3: r3 <- i3src (using r0)
ix: other use of r0
In try_combine, elim_i0/elim_i1/elim_i2 are set to 0/r1/0 correspondingly.
When calling distribute_notes for reg_notes in i1, the check "rtx_equal_p (XEXP
(note, 0), elim_i0)" evaluates to FALSE. As a result, GCC falls through to
below code which is to handle another note distribution case. This is why I
thought the logic doesn't make any sense at the first glance.
So If variables elim_i0/elim_i1/elim_i2 are set to correct values,
distribution_notes acts as expected by discarding the REG_DEAD note.
The point is, when we distributing REG_DEAD note in i1, elim_i0 should be set
to i1dest (r0 in the example), which means r0 is eliminated as far as i1 is
handled, no matter if it is re-set by i2 or not.
Another issue is about tem_insn, I think in any cases, we should start
searching reference/def of the noted register from "from_insn" (if it exist).
Think about below case:
ix: rA <- xxx
i0: r0 <- const_0
i1: r1 <- rA & r0
REG_DEAD (rA)
i2: r0 <- i2src (using r1)
iy: rA <- yyy
i3: r3 <- i3src (using r0)
Starting from i3, we will delete insn iy, but what should be deleted actually
is insn ix!