Skip to content

Commit f7ea8d4

Browse files
committed
Use std::optional in DenseMap, remove TII check given everything in demandedVL must be a candidate
1 parent 376fe4d commit f7ea8d4

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ namespace {
3333
class RISCVVLOptimizer : public MachineFunctionPass {
3434
const MachineRegisterInfo *MRI;
3535
const MachineDominatorTree *MDT;
36-
const TargetInstrInfo *TII;
3736

3837
public:
3938
static char ID;
@@ -60,7 +59,7 @@ class RISCVVLOptimizer : public MachineFunctionPass {
6059

6160
/// For a given instruction, records what elements of it are demanded by
6261
/// downstream users.
63-
DenseMap<const MachineInstr *, MachineOperand> DemandedVLs;
62+
DenseMap<const MachineInstr *, std::optional<MachineOperand>> DemandedVLs;
6463
};
6564

6665
} // end anonymous namespace
@@ -1209,15 +1208,10 @@ RISCVVLOptimizer::getMinimumVLForUser(MachineOperand &UserOp) {
12091208

12101209
// If we know the demanded VL of UserMI, then we can reduce the VL it
12111210
// requires.
1212-
if (DemandedVLs.contains(&UserMI)) {
1213-
// We can only shrink the VL used if the elementwise result doesn't depend
1214-
// on VL (i.e. not vredsum/viota etc.)
1215-
if (!RISCVII::elementsDependOnVL(
1216-
TII->get(RISCV::getRVVMCOpcode(UserMI.getOpcode())).TSFlags)) {
1217-
const MachineOperand &DemandedVL = DemandedVLs.at(&UserMI);
1218-
if (RISCV::isVLKnownLE(DemandedVL, VLOp))
1219-
return DemandedVL;
1220-
}
1211+
if (auto DemandedVL = DemandedVLs[&UserMI]) {
1212+
assert(isCandidate(UserMI));
1213+
if (RISCV::isVLKnownLE(*DemandedVL, VLOp))
1214+
return DemandedVL;
12211215
}
12221216

12231217
return VLOp;
@@ -1348,8 +1342,6 @@ bool RISCVVLOptimizer::runOnMachineFunction(MachineFunction &MF) {
13481342
if (!ST.hasVInstructions())
13491343
return false;
13501344

1351-
TII = ST.getInstrInfo();
1352-
13531345
// For each instruction that defines a vector, compute what VL its
13541346
// downstream users demand.
13551347
for (MachineBasicBlock *MBB : post_order(&MF)) {

0 commit comments

Comments
 (0)