Skip to content

Commit c40877d

Browse files
mshockwavetopperc
andauthored
[RISCV] Attach an implicit source operand on vector copies (#126155)
Somtimes when we're breaking up a large vector copy into several smaller ones, not every single smaller source registers are initialized at the time when the original COPY happens, and the verifier will not be pleased when seeing the smaller copies reading from an undef register. This patch is a workaround for the said issue by attaching an implicit read of the source operand on the newly generated copies. This is tested by llvm/test/CodeGen/RISCV/rvv/vector-interleave.ll which would have crashed the compiler without this fix when LLVM_EXPENSIVE_CHECK is enabled. Original context: #124825 (comment) --------- Co-authored-by: Craig Topper <[email protected]>
1 parent 4aa71f0 commit c40877d

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,11 @@ void RISCVInstrInfo::copyPhysRegVector(
437437
MIB.addReg(RISCV::VL, RegState::Implicit);
438438
MIB.addReg(RISCV::VTYPE, RegState::Implicit);
439439
}
440+
// Add an implicit read of the original source to silence the verifier
441+
// in the cases where some of the smaller VRs we're copying from might be
442+
// undef, caused by the fact that the original, larger source VR might not
443+
// be fully initialized at the time this COPY happens.
444+
MIB.addReg(SrcReg, RegState::Implicit);
440445

441446
// If we are copying reversely, we should decrease the encoding.
442447
SrcEncoding += (ReversedCopy ? -NumCopied : NumCopied);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
2+
# RUN: llc -mtriple=riscv64 -mattr=+v -run-pass=postrapseudos %s -o - | FileCheck %s
3+
4+
---
5+
name: copy
6+
isSSA: false
7+
noVRegs: true
8+
liveins:
9+
- { reg: '$v0', virtual-reg: '' }
10+
body: |
11+
bb.0:
12+
liveins: $v0
13+
14+
; CHECK-LABEL: name: copy
15+
; CHECK: liveins: $v0
16+
; CHECK-NEXT: {{ $}}
17+
; CHECK-NEXT: $v20m2 = VMV2R_V $v14m2, implicit $vtype, implicit $v14_v15_v16_v17_v18
18+
; CHECK-NEXT: $v22m2 = VMV2R_V $v16m2, implicit $vtype, implicit $v14_v15_v16_v17_v18
19+
; CHECK-NEXT: $v24 = VMV1R_V $v18, implicit $vtype, implicit $v14_v15_v16_v17_v18, implicit $vtype
20+
; CHECK-NEXT: PseudoRET implicit $v0
21+
renamable $v20_v21_v22_v23_v24 = COPY renamable $v14_v15_v16_v17_v18, implicit $vtype
22+
PseudoRET implicit $v0
23+
24+
...

0 commit comments

Comments
 (0)