From e6c7a3a54ffaf0001017f619faf2fa260fb517b4 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Thu, 16 Jun 2022 14:45:44 -0700 Subject: [PATCH] [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 --- llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp | 9 ++++++++- llvm/test/CodeGen/RISCV/rvv/implicit-def-copy.ll | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 llvm/test/CodeGen/RISCV/rvv/implicit-def-copy.ll diff --git a/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp b/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp index 1f42566..3d3b504 100644 --- a/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp @@ -317,8 +317,15 @@ InstrEmitter::AddRegisterOperand(MachineInstrBuilder &MIB, OpRC = TII->getRegClass(*II, IIOpNum, TRI, *MF); if (OpRC) { + unsigned MinNumRegs = MinRCSize; + // Don't apply any RC size limit for IMPLICIT_DEF. Each use has a unique + // virtual register. + if (Op.isMachineOpcode() && + Op.getMachineOpcode() == TargetOpcode::IMPLICIT_DEF) + MinNumRegs = 0; + const TargetRegisterClass *ConstrainedRC - = MRI->constrainRegClass(VReg, OpRC, MinRCSize); + = MRI->constrainRegClass(VReg, OpRC, MinNumRegs); if (!ConstrainedRC) { OpRC = TRI->getAllocatableClass(OpRC); assert(OpRC && "Constraints cannot be fulfilled for allocation"); diff --git a/llvm/test/CodeGen/RISCV/rvv/implicit-def-copy.ll b/llvm/test/CodeGen/RISCV/rvv/implicit-def-copy.ll new file mode 100644 index 0000000..2aa0127 --- /dev/null +++ b/llvm/test/CodeGen/RISCV/rvv/implicit-def-copy.ll @@ -0,0 +1,23 @@ +; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py +; RUN: llc < %s -mtriple=riscv64 -mattr=+v -stop-after=finalize-isel | FileCheck %s + +; Make sure we don't create a COPY instruction for IMPLICIT_DEF. + +define @vpload_nxv8i64(* %ptr, %m, i32 zeroext %evl) #1 { + ; CHECK-LABEL: name: vpload_nxv8i64 + ; CHECK: bb.0 (%ir-block.0): + ; CHECK-NEXT: liveins: $x10, $v0, $x11 + ; CHECK-NEXT: {{ $}} + ; CHECK-NEXT: [[COPY:%[0-9]+]]:gprnox0 = COPY $x11 + ; CHECK-NEXT: [[COPY1:%[0-9]+]]:vr = COPY $v0 + ; CHECK-NEXT: [[COPY2:%[0-9]+]]:gpr = COPY $x10 + ; CHECK-NEXT: $v0 = COPY [[COPY1]] + ; CHECK-NEXT: [[DEF:%[0-9]+]]:vrm8nov0 = IMPLICIT_DEF + ; 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) + ; CHECK-NEXT: $v8m8 = COPY [[PseudoVLE64_V_M8_MASK]] + ; CHECK-NEXT: PseudoRET implicit $v8m8 + %load = call @llvm.vp.load.nxv8i64.p0nxv8i64(* %ptr, %m, i32 %evl) + ret %load +} + +declare @llvm.vp.load.nxv8i64.p0nxv8i64(*, , i32) -- 2.7.4