Skip to content

Commit 0c854d4

Browse files
committed
Use getMinimalPhysRegClass and check TSFlags to check if it's a whole vector copy
1 parent 0debf87 commit 0c854d4

File tree

2 files changed

+11
-23
lines changed

2 files changed

+11
-23
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "RISCV.h"
2828
#include "RISCVSubtarget.h"
2929
#include "llvm/ADT/Statistic.h"
30+
#include "llvm/Analysis/ValueTracking.h"
3031
#include "llvm/CodeGen/LiveDebugVariables.h"
3132
#include "llvm/CodeGen/LiveIntervals.h"
3233
#include "llvm/CodeGen/LiveStacks.h"
@@ -196,24 +197,11 @@ static bool hasUndefinedPassthru(const MachineInstr &MI) {
196197
}
197198

198199
/// Return true if \p MI is a copy that will be lowered to one or more vmvNr.vs.
199-
static bool isVecCopy(const MachineInstr &MI) {
200-
static const TargetRegisterClass *RVVRegClasses[] = {
201-
&RISCV::VRRegClass, &RISCV::VRM2RegClass, &RISCV::VRM4RegClass,
202-
&RISCV::VRM8RegClass, &RISCV::VRN2M1RegClass, &RISCV::VRN2M2RegClass,
203-
&RISCV::VRN2M4RegClass, &RISCV::VRN3M1RegClass, &RISCV::VRN3M2RegClass,
204-
&RISCV::VRN4M1RegClass, &RISCV::VRN4M2RegClass, &RISCV::VRN5M1RegClass,
205-
&RISCV::VRN6M1RegClass, &RISCV::VRN7M1RegClass, &RISCV::VRN8M1RegClass};
206-
if (!MI.isCopy())
207-
return false;
208-
209-
Register DstReg = MI.getOperand(0).getReg();
210-
Register SrcReg = MI.getOperand(1).getReg();
211-
for (const auto &RegClass : RVVRegClasses) {
212-
if (RegClass->contains(DstReg, SrcReg)) {
213-
return true;
214-
}
215-
}
216-
return false;
200+
static bool isVectorCopy(const TargetRegisterInfo *TRI,
201+
const MachineInstr &MI) {
202+
return MI.isCopy() && MI.getOperand(0).getReg().isPhysical() &&
203+
RISCVRegisterInfo::isRVVRegClass(
204+
TRI->getMinimalPhysRegClass(MI.getOperand(0).getReg()));
217205
}
218206

219207
/// Which subfields of VL or VTYPE have values we need to preserve?
@@ -537,7 +525,7 @@ DemandedFields getDemanded(const MachineInstr &MI, const RISCVSubtarget *ST) {
537525
// However it does need valid SEW, i.e. vill must be cleared. The entry to a
538526
// function, calls and inline assembly may all set it, so make sure we clear
539527
// it for whole register copies.
540-
if (isVecCopy(MI))
528+
if (isVectorCopy(ST->getRegisterInfo(), MI))
541529
Res.VILL = true;
542530

543531
return Res;
@@ -1245,7 +1233,7 @@ static VSETVLIInfo adjustIncoming(VSETVLIInfo PrevInfo, VSETVLIInfo NewInfo,
12451233
// legal for MI, but may not be the state requested by MI.
12461234
void RISCVInsertVSETVLI::transferBefore(VSETVLIInfo &Info,
12471235
const MachineInstr &MI) const {
1248-
if (isVecCopy(MI) &&
1236+
if (isVectorCopy(ST->getRegisterInfo(), MI) &&
12491237
(Info.isUnknown() || !Info.isValid() || Info.hasSEWLMULRatioOnly())) {
12501238
// Use an arbitrary but valid AVL and VTYPE so vill will be cleared. It may
12511239
// be coalesced into another vsetvli since we won't demand any fields.
@@ -1345,7 +1333,7 @@ bool RISCVInsertVSETVLI::computeVLVTYPEChanges(const MachineBasicBlock &MBB,
13451333
transferBefore(Info, MI);
13461334

13471335
if (isVectorConfigInstr(MI) || RISCVII::hasSEWOp(MI.getDesc().TSFlags) ||
1348-
isVecCopy(MI))
1336+
isVectorCopy(ST->getRegisterInfo(), MI))
13491337
HadVectorOp = true;
13501338

13511339
transferAfter(Info, MI);
@@ -1475,7 +1463,7 @@ void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock &MBB) {
14751463
PrefixTransparent = false;
14761464
}
14771465

1478-
if (isVecCopy(MI) &&
1466+
if (isVectorCopy(ST->getRegisterInfo(), MI) &&
14791467
!PrevInfo.isCompatible(DemandedFields::all(), CurInfo, LIS)) {
14801468
insertVSETVLI(MBB, MI, MI.getDebugLoc(), CurInfo, PrevInfo);
14811469
PrefixTransparent = false;

llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,8 +835,8 @@ body: |
835835
; CHECK-NEXT: PseudoBR %bb.3
836836
; CHECK-NEXT: {{ $}}
837837
; CHECK-NEXT: bb.3:
838+
; CHECK-NEXT: dead [[PseudoVSETVLIX0_1:%[0-9]+]]:gpr = PseudoVSETVLIX0 $x0, 197 /* e8, mf8, ta, ma */, implicit-def $vl, implicit-def $vtype
838839
; CHECK-NEXT: $v0 = COPY %mask
839-
; CHECK-NEXT: dead $x0 = PseudoVSETVLIX0 killed $x0, 197 /* e8, mf8, ta, ma */, implicit-def $vl, implicit-def $vtype, implicit $vl
840840
; CHECK-NEXT: PseudoVSOXEI64_V_M1_MF8_MASK [[COPY]], %b, %idxs, $v0, -1, 3 /* e8 */, implicit $vl, implicit $vtype
841841
; CHECK-NEXT: PseudoRET
842842
bb.0:

0 commit comments

Comments
 (0)