@@ -1464,20 +1464,6 @@ static void doUnion(DemandedFields &A, DemandedFields B) {
14641464 A.MaskPolicy |= B.MaskPolicy ;
14651465}
14661466
1467- static bool isNonZeroAVL (const MachineOperand &MO,
1468- const MachineRegisterInfo &MRI) {
1469- if (MO.isReg ()) {
1470- if (MO.getReg () == RISCV::X0)
1471- return true ;
1472- if (MachineInstr *MI = MRI.getVRegDef (MO.getReg ());
1473- MI && isNonZeroLoadImmediate (*MI))
1474- return true ;
1475- return false ;
1476- }
1477- assert (MO.isImm ());
1478- return 0 != MO.getImm ();
1479- }
1480-
14811467// Return true if we can mutate PrevMI to match MI without changing any the
14821468// fields which would be observed.
14831469static bool canMutatePriorConfig (const MachineInstr &PrevMI,
@@ -1491,21 +1477,26 @@ static bool canMutatePriorConfig(const MachineInstr &PrevMI,
14911477 if (Used.VLAny )
14921478 return false ;
14931479
1494- // We don't bother to handle the equally zero case here as it's largely
1495- // uninteresting.
14961480 if (Used.VLZeroness ) {
14971481 if (isVLPreservingConfig (PrevMI))
14981482 return false ;
1499- if (!isNonZeroAVL (MI. getOperand ( 1 ), MRI) ||
1500- ! isNonZeroAVL (PrevMI. getOperand ( 1 ), MRI))
1483+ if (!getInfoForVSETVLI (PrevMI). hasEquallyZeroAVL ( getInfoForVSETVLI (MI),
1484+ MRI))
15011485 return false ;
15021486 }
15031487
1504- // TODO: Track whether the register is defined between
1505- // PrevMI and MI.
1506- if (MI.getOperand (1 ).isReg () &&
1507- RISCV::X0 != MI.getOperand (1 ).getReg ())
1508- return false ;
1488+ auto &AVL = MI.getOperand (1 );
1489+ auto &PrevAVL = PrevMI.getOperand (1 );
1490+ assert (MRI.isSSA ());
1491+
1492+ // If the AVL is a register, we need to make sure MI's AVL dominates PrevMI.
1493+ // For now just check that PrevMI uses the same virtual register.
1494+ if (AVL.isReg () && AVL.getReg () != RISCV::X0) {
1495+ if (AVL.getReg ().isPhysical ())
1496+ return false ;
1497+ if (!PrevAVL.isReg () || PrevAVL.getReg () != AVL.getReg ())
1498+ return false ;
1499+ }
15091500 }
15101501
15111502 if (!PrevMI.getOperand (2 ).isImm () || !MI.getOperand (2 ).isImm ())
0 commit comments