Skip to content

Commit 61e681c

Browse files
fixup! respond to review
1 parent 8d50a38 commit 61e681c

File tree

1 file changed

+18
-29
lines changed

1 file changed

+18
-29
lines changed

llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ class RISCVVLOptimizer : public MachineFunctionPass {
5050
StringRef getPassName() const override { return PASS_NAME; }
5151

5252
private:
53-
std::optional<const MachineOperand> getVLForUser(MachineOperand &UserOp);
53+
std::optional<MachineOperand> getVLForUser(MachineOperand &UserOp);
5454
/// Returns the largest common VL MachineOperand that may be used to optimize
5555
/// MI. Returns std::nullopt if it failed to find a suitable VL.
56-
std::optional<const MachineOperand> checkUsers(MachineInstr &MI);
56+
std::optional<MachineOperand> checkUsers(MachineInstr &MI);
5757
bool tryReduceVL(MachineInstr &MI);
5858
bool isCandidate(const MachineInstr &MI) const;
5959
};
@@ -1055,7 +1055,7 @@ bool RISCVVLOptimizer::isCandidate(const MachineInstr &MI) const {
10551055
return true;
10561056
}
10571057

1058-
std::optional<const MachineOperand>
1058+
std::optional<MachineOperand>
10591059
RISCVVLOptimizer::getVLForUser(MachineOperand &UserOp) {
10601060
const MachineInstr &UserMI = *UserOp.getParent();
10611061
const MCInstrDesc &Desc = UserMI.getDesc();
@@ -1102,51 +1102,43 @@ RISCVVLOptimizer::getVLForUser(MachineOperand &UserOp) {
11021102
return VLOp;
11031103
}
11041104

1105-
std::optional<const MachineOperand>
1106-
RISCVVLOptimizer::checkUsers(MachineInstr &MI) {
1105+
std::optional<MachineOperand> RISCVVLOptimizer::checkUsers(MachineInstr &MI) {
11071106
// FIXME: Avoid visiting each user for each time we visit something on the
11081107
// worklist, combined with an extra visit from the outer loop. Restructure
11091108
// along lines of an instcombine style worklist which integrates the outer
11101109
// pass.
1111-
bool CanReduceVL = true;
1112-
std::optional<const MachineOperand> CommonVL;
1110+
std::optional<MachineOperand> CommonVL;
11131111
for (auto &UserOp : MRI->use_operands(MI.getOperand(0).getReg())) {
11141112
const MachineInstr &UserMI = *UserOp.getParent();
11151113
LLVM_DEBUG(dbgs() << " Checking user: " << UserMI << "\n");
11161114
if (mayReadPastVL(UserMI)) {
11171115
LLVM_DEBUG(dbgs() << " Abort because used by unsafe instruction\n");
1118-
CanReduceVL = false;
1119-
break;
1116+
return std::nullopt;
11201117
}
11211118

11221119
// Tied operands might pass through.
11231120
if (UserOp.isTied()) {
11241121
LLVM_DEBUG(dbgs() << " Abort because user used as tied operand\n");
1125-
CanReduceVL = false;
1126-
break;
1122+
return std::nullopt;
11271123
}
11281124

11291125
auto VLOp = getVLForUser(UserOp);
1130-
if (!VLOp) {
1131-
CanReduceVL = false;
1132-
break;
1133-
}
1126+
if (!VLOp)
1127+
return std::nullopt;
11341128

11351129
// Use the largest VL among all the users. If we cannot determine this
11361130
// statically, then we cannot optimize the VL.
11371131
if (!CommonVL || RISCV::isVLKnownLE(*CommonVL, *VLOp)) {
1138-
CommonVL.emplace(*VLOp);
1132+
CommonVL = *VLOp;
11391133
LLVM_DEBUG(dbgs() << " User VL is: " << VLOp << "\n");
11401134
} else if (!RISCV::isVLKnownLE(*VLOp, *CommonVL)) {
11411135
LLVM_DEBUG(dbgs() << " Abort because cannot determine a common VL\n");
1142-
CanReduceVL = false;
1143-
break;
1136+
return std::nullopt;
11441137
}
11451138

11461139
if (!RISCVII::hasSEWOp(UserMI.getDesc().TSFlags)) {
11471140
LLVM_DEBUG(dbgs() << " Abort due to lack of SEW operand\n");
1148-
CanReduceVL = false;
1149-
break;
1141+
return std::nullopt;
11501142
}
11511143

11521144
OperandInfo ConsumerInfo = getOperandInfo(UserOp, MRI);
@@ -1155,29 +1147,26 @@ RISCVVLOptimizer::checkUsers(MachineInstr &MI) {
11551147
LLVM_DEBUG(dbgs() << " Abort due to unknown operand information.\n");
11561148
LLVM_DEBUG(dbgs() << " ConsumerInfo is: " << ConsumerInfo << "\n");
11571149
LLVM_DEBUG(dbgs() << " ProducerInfo is: " << ProducerInfo << "\n");
1158-
CanReduceVL = false;
1159-
break;
1150+
return std::nullopt;
11601151
}
11611152

11621153
// If the operand is used as a scalar operand, then the EEW must be
11631154
// compatible. Otherwise, the EMUL *and* EEW must be compatible.
1164-
if ((isVectorOpUsedAsScalarOp(UserOp) &&
1155+
bool IsVectorOpUsedAsScalarOp = isVectorOpUsedAsScalarOp(UserOp);
1156+
if ((IsVectorOpUsedAsScalarOp &&
11651157
!OperandInfo::EEWAreEqual(ConsumerInfo, ProducerInfo)) ||
1166-
(!isVectorOpUsedAsScalarOp(UserOp) &&
1158+
(!IsVectorOpUsedAsScalarOp &&
11671159
!OperandInfo::EMULAndEEWAreEqual(ConsumerInfo, ProducerInfo))) {
11681160
LLVM_DEBUG(
11691161
dbgs()
11701162
<< " Abort due to incompatible information for EMUL or EEW.\n");
11711163
LLVM_DEBUG(dbgs() << " ConsumerInfo is: " << ConsumerInfo << "\n");
11721164
LLVM_DEBUG(dbgs() << " ProducerInfo is: " << ProducerInfo << "\n");
1173-
CanReduceVL = false;
1174-
break;
1165+
return std::nullopt;
11751166
}
11761167
}
11771168

1178-
return CanReduceVL && CommonVL
1179-
? std::make_optional<const MachineOperand>(*CommonVL)
1180-
: std::nullopt;
1169+
return CommonVL;
11811170
}
11821171

11831172
bool RISCVVLOptimizer::tryReduceVL(MachineInstr &OrigMI) {

0 commit comments

Comments
 (0)