@@ -1366,29 +1366,31 @@ static bool isVectorOpUsedAsScalarOp(MachineOperand &MO) {
1366
1366
}
1367
1367
}
1368
1368
1369
- static bool safeToPropgateVL (const MachineInstr &MI) {
1369
+ // / Return true if MI may read elements past VL.
1370
+ static bool mayReadPastVL (const MachineInstr &MI) {
1370
1371
const RISCVVPseudosTable::PseudoInfo *RVV =
1371
1372
RISCVVPseudosTable::getPseudoInfo (MI.getOpcode ());
1372
1373
if (!RVV)
1373
- return false ;
1374
+ return true ;
1374
1375
1375
1376
switch (RVV->BaseInstr ) {
1376
- // vslidedown instructions may use the higher part of the input operand beyond
1377
- // the VL .
1377
+ // vslidedown instructions may read elements past VL. They are handled
1378
+ // according to current tail policy .
1378
1379
case RISCV::VSLIDEDOWN_VI:
1379
1380
case RISCV::VSLIDEDOWN_VX:
1380
1381
case RISCV::VSLIDE1DOWN_VX:
1381
1382
case RISCV::VFSLIDE1DOWN_VF:
1382
1383
1383
- // vrgather instructions may index beyond the VL.
1384
+ // vrgather instructions may read the source vector at any index < VLMAX,
1385
+ // regardless of VL.
1384
1386
case RISCV::VRGATHER_VI:
1385
1387
case RISCV::VRGATHER_VV:
1386
1388
case RISCV::VRGATHER_VX:
1387
1389
case RISCV::VRGATHEREI16_VV:
1388
- return false ;
1390
+ return true ;
1389
1391
1390
1392
default :
1391
- return true ;
1393
+ return false ;
1392
1394
}
1393
1395
}
1394
1396
@@ -1443,6 +1445,7 @@ bool RISCVVLOptimizer::tryReduceVL(MachineInstr &OrigMI) {
1443
1445
while (!Worklist.empty ()) {
1444
1446
MachineInstr &MI = *Worklist.pop_back_val ();
1445
1447
LLVM_DEBUG (dbgs () << " Try reduce VL for " << MI << " \n " );
1448
+
1446
1449
std::optional<Register> CommonVL;
1447
1450
bool CanReduceVL = true ;
1448
1451
for (auto &UserOp : MRI->use_operands (MI.getOperand (0 ).getReg ())) {
@@ -1461,7 +1464,7 @@ bool RISCVVLOptimizer::tryReduceVL(MachineInstr &OrigMI) {
1461
1464
continue ;
1462
1465
}
1463
1466
1464
- if (! safeToPropgateVL (UserMI)) {
1467
+ if (mayReadPastVL (UserMI)) {
1465
1468
LLVM_DEBUG (dbgs () << " Abort due to used by unsafe instruction\n " );
1466
1469
CanReduceVL = false ;
1467
1470
break ;
0 commit comments