[CodeGen] Incorrect implicit-def placement when lowering multi-instruction COPY
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
When lowering a `COPY` with an `implict-def` to multiple instructions, transferImplicitOperands (llvm/lib/CodeGen/TargetInstrInfo.cpp) places all implicit operands on the last generated instruction. If the `implicit-def` defines a super-register of the copy destination, a following backward liveness scan will remove all previous sub-register defs of the replacement instructions.
The following examples shows the issue:
```
# RUN: llc -mtriple=aarch64 -run-pass=postrapseudos %s -o - | FileCheck %s
---
name: test
tracksRegLiveness: true
body: |
bb.0:
liveins: $q4_q5, $q6_q7, $x0
$q0_q1 = COPY $q4_q5, implicit-def $q0_q1_q2_q3
$q2_q3 = COPY $q6_q7
ST4Fourv4s $q0_q1_q2_q3, $x0
RET_ReallyLR
...
```
Outputs
```
$q0 = ORRv16i8 $q4, $q4 <-- will be removed by dead-mi-elimination
$q1 = ORRv16i8 $q5, $q5, implicit-def $q0_q1_q2_q3
$q2 = ORRv16i8 $q6, $q6
$q3 = ORRv16i8 $q7, $q7
ST4Fourv4s $q0_q1_q2_q3, $x0
```
This can be fixed by placing `implicit-def` of super-registers at the first replacement instruction.
A proposal fix is in [#194892](https://github.com/llvm/llvm-project/pull/194892)
Contributor guide
Assessment
This issue has not been assessed yet.