Skip to content

Commit bcca57b

Browse files
authored
[RISCV] Simplify mask operand check in VLOptimizer. NFC (#150373)
We don't need to lookup the reg class because the MCInstDesc already gives us this information. With that we can remove some helper methods, and tighten the assert in isCandidate because all pseudos at this stage should be defining virtual registers.
1 parent 9df8bc9 commit bcca57b

File tree

2 files changed

+12
-28
lines changed

2 files changed

+12
-28
lines changed

llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,6 @@ FunctionPass *llvm::createRISCVVLOptimizerPass() {
114114
return new RISCVVLOptimizer();
115115
}
116116

117-
/// Return true if R is a physical or virtual vector register, false otherwise.
118-
static bool isVectorRegClass(Register R, const MachineRegisterInfo *MRI) {
119-
if (R.isPhysical())
120-
return RISCV::VRRegClass.contains(R);
121-
const TargetRegisterClass *RC = MRI->getRegClass(R);
122-
return RISCVRI::isVRegClass(RC->TSFlags);
123-
}
124-
125117
LLVM_ATTRIBUTE_UNUSED
126118
static raw_ostream &operator<<(raw_ostream &OS, const OperandInfo &OI) {
127119
OI.print(OS);
@@ -183,37 +175,28 @@ static unsigned getIntegerExtensionOperandEEW(unsigned Factor,
183175
return Log2EEW;
184176
}
185177

186-
/// Check whether MO is a mask operand of MI.
187-
static bool isMaskOperand(const MachineInstr &MI, const MachineOperand &MO,
188-
const MachineRegisterInfo *MRI) {
189-
190-
if (!MO.isReg() || !isVectorRegClass(MO.getReg(), MRI))
191-
return false;
192-
193-
const MCInstrDesc &Desc = MI.getDesc();
194-
return Desc.operands()[MO.getOperandNo()].RegClass == RISCV::VMV0RegClassID;
195-
}
196-
197178
static std::optional<unsigned>
198179
getOperandLog2EEW(const MachineOperand &MO, const MachineRegisterInfo *MRI) {
199180
const MachineInstr &MI = *MO.getParent();
181+
const MCInstrDesc &Desc = MI.getDesc();
200182
const RISCVVPseudosTable::PseudoInfo *RVV =
201183
RISCVVPseudosTable::getPseudoInfo(MI.getOpcode());
202184
assert(RVV && "Could not find MI in PseudoTable");
203185

204186
// MI has a SEW associated with it. The RVV specification defines
205187
// the EEW of each operand and definition in relation to MI.SEW.
206-
unsigned MILog2SEW =
207-
MI.getOperand(RISCVII::getSEWOpNum(MI.getDesc())).getImm();
188+
unsigned MILog2SEW = MI.getOperand(RISCVII::getSEWOpNum(Desc)).getImm();
208189

209-
const bool HasPassthru = RISCVII::isFirstDefTiedToFirstUse(MI.getDesc());
210-
const bool IsTied = RISCVII::isTiedPseudo(MI.getDesc().TSFlags);
190+
const bool HasPassthru = RISCVII::isFirstDefTiedToFirstUse(Desc);
191+
const bool IsTied = RISCVII::isTiedPseudo(Desc.TSFlags);
211192

212193
bool IsMODef = MO.getOperandNo() == 0 ||
213194
(HasPassthru && MO.getOperandNo() == MI.getNumExplicitDefs());
214195

215196
// All mask operands have EEW=1
216-
if (isMaskOperand(MI, MO, MRI))
197+
const MCOperandInfo &Info = Desc.operands()[MO.getOperandNo()];
198+
if (Info.OperandType == MCOI::OPERAND_REGISTER &&
199+
Info.RegClass == RISCV::VMV0RegClassID)
217200
return 0;
218201

219202
// switch against BaseInstr to reduce number of cases that need to be
@@ -1296,8 +1279,8 @@ bool RISCVVLOptimizer::isCandidate(const MachineInstr &MI) const {
12961279
TII->get(RISCV::getRVVMCOpcode(MI.getOpcode())).TSFlags) &&
12971280
"Instruction shouldn't be supported if elements depend on VL");
12981281

1299-
assert(MI.getOperand(0).isReg() &&
1300-
isVectorRegClass(MI.getOperand(0).getReg(), MRI) &&
1282+
assert(RISCVRI::isVRegClass(
1283+
MRI->getRegClass(MI.getOperand(0).getReg())->TSFlags) &&
13011284
"All supported instructions produce a vector register result");
13021285

13031286
LLVM_DEBUG(dbgs() << "Found a candidate for VL reduction: " << MI << "\n");

llvm/test/CodeGen/RISCV/rvv/vxrm.mir

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ body: |
1313
; MIR-NEXT: {{ $}}
1414
; MIR-NEXT: WriteVXRMImm 0, implicit-def $vxrm
1515
; MIR-NEXT: dead $x0 = PseudoVSETVLI killed renamable $x10, 197 /* e8, mf8, ta, ma */, implicit-def $vl, implicit-def $vtype
16-
; MIR-NEXT: renamable $v8 = PseudoVAADD_VV_MF8 undef $v8, killed renamable $v8, killed renamable $v9, 0, $noreg, 3 /* e8 */, 0 /* tu, mu */, implicit $vxrm, implicit $vl, implicit $vtype
16+
; MIR-NEXT: renamable $v8 = PseudoVAADD_VV_MF8 undef renamable $v8, killed renamable $v8, killed renamable $v9, 0, $noreg, 3 /* e8 */, 0 /* tu, mu */, implicit $vxrm, implicit $vl, implicit $vtype
1717
; MIR-NEXT: PseudoRET implicit $v8
1818
; ASM-LABEL: verify_vxrm:
1919
; ASM: # %bb.0:
@@ -24,6 +24,7 @@ body: |
2424
%0:vr = COPY $v8
2525
%1:vr = COPY $v9
2626
%2:gprnox0 = COPY $x10
27-
renamable $v8 = PseudoVAADD_VV_MF8 undef $noreg, %0, %1, 0, %2, 3 /* e8 */, 0
27+
%3:vr = PseudoVAADD_VV_MF8 undef $noreg, %0, %1, 0, %2, 3 /* e8 */, 0
28+
$v8 = COPY %3
2829
PseudoRET implicit $v8
2930
...

0 commit comments

Comments
 (0)