1818
1919#include " RISCV.h"
2020#include " RISCVSubtarget.h"
21- #include " llvm/ADT/SetVector .h"
21+ #include " llvm/ADT/PostOrderIterator .h"
2222#include " llvm/CodeGen/MachineDominators.h"
2323#include " llvm/CodeGen/MachineFunctionPass.h"
2424#include " llvm/InitializePasses.h"
@@ -1343,21 +1343,22 @@ bool RISCVVLOptimizer::runOnMachineFunction(MachineFunction &MF) {
13431343
13441344 TII = ST.getInstrInfo ();
13451345
1346- bool MadeChange = false ;
1347- for (MachineBasicBlock &MBB : MF) {
1348- // Avoid unreachable blocks as they have degenerate dominance
1349- if (!MDT->isReachableFromEntry (&MBB))
1350- continue ;
13511346
1352- // For each instruction that defines a vector, compute what VL its
1353- // downstream users demand.
1354- for (MachineInstr &MI : reverse (MBB)) {
1347+ // For each instruction that defines a vector, compute what VL its
1348+ // downstream users demand.
1349+ for (MachineBasicBlock *MBB : post_order (&MF)) {
1350+ // Avoid unreachable blocks as they have degenerate dominance
1351+ assert (MDT->isReachableFromEntry (MBB));
1352+ for (MachineInstr &MI : reverse (*MBB)) {
13551353 if (!isCandidate (MI))
13561354 continue ;
13571355 if (auto DemandedVL = checkUsers (MI))
13581356 DemandedVLs.insert ({&MI, *DemandedVL});
13591357 }
1358+ }
13601359
1360+ bool MadeChange = false ;
1361+ for (MachineBasicBlock &MBB : MF) {
13611362 // Then go through and see if we can reduce the VL of any instructions to
13621363 // only what's demanded.
13631364 for (auto &MI : MBB) {
@@ -1367,8 +1368,6 @@ bool RISCVVLOptimizer::runOnMachineFunction(MachineFunction &MF) {
13671368 continue ;
13681369 MadeChange = true ;
13691370 }
1370-
1371- DemandedVLs.clear ();
13721371 }
13731372
13741373 return MadeChange;
0 commit comments