Skip to content

Commit e6c7a3a

Browse files
committed
[SelectionDAG] Don't apply MinRCSize constraint in InstrEmitter::AddRegisterOperand for IMPLICIT_DEF sources.
MinRCSize is 4 and prevents constrainRegClass from changing the register class if the new class has size less than 4. IMPLICIT_DEF gets a unique vreg for each use and will be removed by the ProcessImplicitDef pass before register allocation. I don't think there is any reason to prevent constraining the virtual register to whatever register class the use needs. The attached test case was previously creating a copy of IMPLICIT_DEF because vrm8nov0 has 3 registers in it. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D128005
1 parent 011e060 commit e6c7a3a

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,15 @@ InstrEmitter::AddRegisterOperand(MachineInstrBuilder &MIB,
317317
OpRC = TII->getRegClass(*II, IIOpNum, TRI, *MF);
318318

319319
if (OpRC) {
320+
unsigned MinNumRegs = MinRCSize;
321+
// Don't apply any RC size limit for IMPLICIT_DEF. Each use has a unique
322+
// virtual register.
323+
if (Op.isMachineOpcode() &&
324+
Op.getMachineOpcode() == TargetOpcode::IMPLICIT_DEF)
325+
MinNumRegs = 0;
326+
320327
const TargetRegisterClass *ConstrainedRC
321-
= MRI->constrainRegClass(VReg, OpRC, MinRCSize);
328+
= MRI->constrainRegClass(VReg, OpRC, MinNumRegs);
322329
if (!ConstrainedRC) {
323330
OpRC = TRI->getAllocatableClass(OpRC);
324331
assert(OpRC && "Constraints cannot be fulfilled for allocation");
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
; RUN: llc < %s -mtriple=riscv64 -mattr=+v -stop-after=finalize-isel | FileCheck %s
3+
4+
; Make sure we don't create a COPY instruction for IMPLICIT_DEF.
5+
6+
define <vscale x 8 x i64> @vpload_nxv8i64(<vscale x 8 x i64>* %ptr, <vscale x 8 x i1> %m, i32 zeroext %evl) #1 {
7+
; CHECK-LABEL: name: vpload_nxv8i64
8+
; CHECK: bb.0 (%ir-block.0):
9+
; CHECK-NEXT: liveins: $x10, $v0, $x11
10+
; CHECK-NEXT: {{ $}}
11+
; CHECK-NEXT: [[COPY:%[0-9]+]]:gprnox0 = COPY $x11
12+
; CHECK-NEXT: [[COPY1:%[0-9]+]]:vr = COPY $v0
13+
; CHECK-NEXT: [[COPY2:%[0-9]+]]:gpr = COPY $x10
14+
; CHECK-NEXT: $v0 = COPY [[COPY1]]
15+
; CHECK-NEXT: [[DEF:%[0-9]+]]:vrm8nov0 = IMPLICIT_DEF
16+
; CHECK-NEXT: [[PseudoVLE64_V_M8_MASK:%[0-9]+]]:vrm8nov0 = PseudoVLE64_V_M8_MASK [[DEF]], [[COPY2]], $v0, [[COPY]], 6 /* e64 */, 1 :: (load unknown-size from %ir.ptr, align 64)
17+
; CHECK-NEXT: $v8m8 = COPY [[PseudoVLE64_V_M8_MASK]]
18+
; CHECK-NEXT: PseudoRET implicit $v8m8
19+
%load = call <vscale x 8 x i64> @llvm.vp.load.nxv8i64.p0nxv8i64(<vscale x 8 x i64>* %ptr, <vscale x 8 x i1> %m, i32 %evl)
20+
ret <vscale x 8 x i64> %load
21+
}
22+
23+
declare <vscale x 8 x i64> @llvm.vp.load.nxv8i64.p0nxv8i64(<vscale x 8 x i64>*, <vscale x 8 x i1>, i32)

0 commit comments

Comments
 (0)