[MachinePipeliner] Fix risky iterator usage R++, --R

When we calculate MII, we use two loops, one with iterator R++ to
check whether we can reserve the resource, then --R to move back
the iterator to do reservation.

This is risky, as R++, --R may not point to the same element at all.
The can cause wrong MII.

Differential Revision: https://reviews.llvm.org/D63536

llvm-svn: 364353
This commit is contained in:
Jinsong Ji 2019-06-25 21:50:56 +00:00
parent c32d307a49
commit fee855b5bc
2 changed files with 4 additions and 8 deletions

View File

@ -1012,17 +1012,13 @@ unsigned SwingSchedulerDAG::calculateResMII() {
});
for (unsigned C = 0; C < NumCycles; ++C)
while (RI != RE) {
if ((*RI++)->canReserveResources(*MI)) {
if ((*RI)->canReserveResources(*MI)) {
(*RI)->reserveResources(*MI);
++ReservedCycles;
break;
}
RI++;
}
// Start reserving resources using existing DFAs.
for (unsigned C = 0; C < ReservedCycles; ++C) {
--RI;
(*RI)->reserveResources(*MI);
}
LLVM_DEBUG(dbgs() << "ReservedCycles:" << ReservedCycles
<< ", NumCycles:" << NumCycles << "\n");
// Add new DFAs, if needed, to reserve resources.

View File

@ -5,7 +5,7 @@
%0 = type { i32, [16 x double] }
; CHECK: MII = 7 MAX_II = 17
; CHECK: MII = 8 MAX_II = 18
define dso_local fastcc void @_ZN3povL9polysolveEiPdS0_() unnamed_addr #0 {
br label %1