Skip to content

Commit b832c49

Browse files
authored
[RISCV] Fix VLOptimizer assert, relax ElementsDependOn on viota/vms{b,i,o}f.m (#149698)
The previous assert wasn't passing the TSFlags but the opcode, so wasn't working. Fixing it reveals that it was actually triggering, because we're too strict with viota and vmsxf.m We already reduce the VL on these instructions because the result in each element doesn't depend on VL. However, it does change if masked, so account for that.
1 parent aa7ada1 commit b832c49

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

llvm/lib/Target/RISCV/RISCVInstrFormats.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ class EltDeps<bit vl, bit mask> {
174174

175175
def EltDepsNone : EltDeps<vl=0, mask=0>;
176176
def EltDepsVL : EltDeps<vl=1, mask=0>;
177+
def EltDepsMask : EltDeps<vl=0, mask=1>;
177178
def EltDepsVLMask : EltDeps<vl=1, mask=1>;
178179

179180
class EEW <bits<2> val> {

llvm/lib/Target/RISCV/RISCVInstrInfoV.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ def VFIRST_M : RVInstV<0b010000, 0b10001, OPMVV, (outs GPR:$vd),
16421642

16431643
def : MnemonicAlias<"vpopc.m", "vcpop.m">;
16441644

1645-
let Constraints = "@earlyclobber $vd", RVVConstraint = Iota, ElementsDependOn = EltDepsVLMask in {
1645+
let Constraints = "@earlyclobber $vd", RVVConstraint = Iota, ElementsDependOn = EltDepsMask in {
16461646

16471647
let DestEEW = EEW1 in {
16481648
// vmsbf.m set-before-first mask bit
@@ -1655,7 +1655,7 @@ defm VMSOF_M : VMSFS_MV_V<"vmsof.m", 0b010100, 0b00010>;
16551655
// Vector Iota Instruction
16561656
defm VIOTA_M : VIOTA_MV_V<"viota.m", 0b010100, 0b10000>;
16571657

1658-
} // Constraints = "@earlyclobber $vd", RVVConstraint = Iota, ElementsDependOn = EltDepsVLMask
1658+
} // Constraints = "@earlyclobber $vd", RVVConstraint = Iota, ElementsDependOn = EltDepsMask
16591659

16601660
// Vector Element Index Instruction
16611661
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {

llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp

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

3738
public:
3839
static char ID;
@@ -1291,7 +1292,8 @@ bool RISCVVLOptimizer::isCandidate(const MachineInstr &MI) const {
12911292
return false;
12921293
}
12931294

1294-
assert(!RISCVII::elementsDependOnVL(RISCV::getRVVMCOpcode(MI.getOpcode())) &&
1295+
assert(!RISCVII::elementsDependOnVL(
1296+
TII->get(RISCV::getRVVMCOpcode(MI.getOpcode())).TSFlags) &&
12951297
"Instruction shouldn't be supported if elements depend on VL");
12961298

12971299
assert(MI.getOperand(0).isReg() &&
@@ -1495,6 +1497,8 @@ bool RISCVVLOptimizer::runOnMachineFunction(MachineFunction &MF) {
14951497
if (!ST.hasVInstructions())
14961498
return false;
14971499

1500+
TII = ST.getInstrInfo();
1501+
14981502
// For each instruction that defines a vector, compute what VL its
14991503
// downstream users demand.
15001504
for (MachineBasicBlock *MBB : post_order(&MF)) {

0 commit comments

Comments
 (0)