<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/153598>153598</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[RISCV] Verifier failure in the RISCVMoveMerger pass
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
svs-quic
</td>
</tr>
</table>
<pre>
https://godbolt.org/z/jEeEcsMMe
When we run the `RISCVMoveMerger` pass on the following MIR with `-mattr=+zcmp` we run into verifier issues on using an undefined register:
```
---
name: mov-merge
tracksRegLiveness: true
body: |
bb.0.entry:
liveins: $x8, $x9
$x12 = ADDI $x0, -3
SW renamable $x9, $x2, 56
$x10 = ADDI killed renamable $x9, 0
SW renamable $x8, $x2, 60
$x11 = ADDI killed renamable $x8, 0
PseudoRET
...
```
The error is:
```
*** Bad machine code: Using an undefined physical register ***
- function: mov-merge
- basic block: %bb.0 entry (0x2b403d40)
- instruction: SW renamable $x8, $x2, 60
- operand 0: renamable $x8
LLVM ERROR: Found 1 machine code errors.
```
It looks like we always insert the merged move after the first MV instruction thereby missing cases where the source register in the second MV is killed in between.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMVNGO4jgQ_Brz0krkODGEhzxkh0EaadCd2L3ZZyfpEC-OzdkOLPv1J5vMDDu7pzsUCYd0Vbqr6BLOyYNGrAj_RPhmISY_GFu5s0v-nmS7aEx3rQbvT47kNWFbwrYH0zVG-dTYA2HbH4Rtvz3iY-t2OyS0JrT-OqCGC4KdNPgBgSzp_unzw8vOnHGH9oCWLCmchHNgbhW9UcpcpD7A7mkPF-mHAEpG4b0l-YawTz_a8RRQM63U3sAZrewlWpDOTRjJJhdIhIZJd9hLjR1YPEjn0Yb-Y3tkSeeL1kmSEFprMSLJaxjNORlDg4TW3or26PZ4eJZn1OjC_ODtFJ4FUcLt_YesHgitAZompSlqb6-3F4KSZ5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