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"
@@ -1350,21 +1350,22 @@ bool RISCVVLOptimizer::runOnMachineFunction(MachineFunction &MF) {
13501350
13511351 TII = ST.getInstrInfo ();
13521352
1353- bool MadeChange = false ;
1354- for (MachineBasicBlock &MBB : MF) {
1355- // Avoid unreachable blocks as they have degenerate dominance
1356- if (!MDT->isReachableFromEntry (&MBB))
1357- continue ;
13581353
1359- // For each instruction that defines a vector, compute what VL its
1360- // downstream users demand.
1361- for (MachineInstr &MI : reverse (MBB)) {
1354+ // For each instruction that defines a vector, compute what VL its
1355+ // downstream users demand.
1356+ for (MachineBasicBlock *MBB : post_order (&MF)) {
1357+ // Avoid unreachable blocks as they have degenerate dominance
1358+ assert (MDT->isReachableFromEntry (MBB));
1359+ for (MachineInstr &MI : reverse (*MBB)) {
13621360 if (!isCandidate (MI))
13631361 continue ;
13641362 if (auto DemandedVL = checkUsers (MI))
13651363 DemandedVLs.insert ({&MI, *DemandedVL});
13661364 }
1365+ }
13671366
1367+ bool MadeChange = false ;
1368+ for (MachineBasicBlock &MBB : MF) {
13681369 // Then go through and see if we can reduce the VL of any instructions to
13691370 // only what's demanded.
13701371 for (auto &MI : MBB) {
@@ -1374,8 +1375,6 @@ bool RISCVVLOptimizer::runOnMachineFunction(MachineFunction &MF) {
13741375 continue ;
13751376 MadeChange = true ;
13761377 }
1377-
1378- DemandedVLs.clear ();
13791378 }
13801379
13811380 return MadeChange;
0 commit comments