<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/107702>107702</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
MachineCopyPropagation remove copy instruction due to no live-out succ, but the def is indeed used.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zzk0
</td>
</tr>
</table>
<pre>
Suppose we have the following scenario:
```
Before MachineCopyPropagation Pass:
bb.1: (no successors)
B = COPY C
early-clobber A = OP B (B is a sub-register of A, and B is not renamable.)
After MachineCopyPropagation Pass:
bb.1: (no successors)
early-clobber A = OP B (B is a sub-register of A, and B is not renamable.)
```
Is this reasonable?
The following might be somewhat difficult to understand. If you feel confused, please let me know. According to the code, we encounter the following situation:
1. `B = COPY C` is added to MaybeDeadCopies.
2. The def register in the instruction `early-clobber A = OP B` is checked, and Tracker.clobberRegister is called to remove A's RegUnit (including B) from the CopyTracker map.
3. When reading the operand `early-clobber A = OP B`, ReadRegister is called for B. However, at this point, B has already been removed from the CopyTracker, so the copy instruction `B = COPY C` is not removed from MaybeDeadCopies.
As a result, B = COPY C is mistakenly deleted when there are no successors.
Any suggestions would be appreciated.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VF-P4jYQ_zTmZUQUHNjAQx6AFeo9nG61varqo2NPEhfHjjw2KPfpK4fc7sHd9qmVkFESz8zvz8wIIt1axIptDmzzvBAxdM5X376d80Xt1Fj9HofBEcIVoRMXhNAhNM4Yd9W2BZJohdeOFXuWP7P8-_mUz7_p8YCN8wifhey0xaMbxhfvBtGKoJ2FF0H0EF_X2YoVe2B8ax1QlBKJnCfGd7cLAAAHYMUzHL-8_AXH97covBmX0ri6Rg_76c6Xl3SZbw-gCQRQrJceW00BPbgG9owfQVgF03frAni0ohe1weyt4u3cNynmvyTyv-G9t-B2fiIInSbwKMjZFMCK051xP5xf75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