Skip to content

Commit fee855b

Browse files
author
Jinsong Ji
committed
[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
1 parent c32d307 commit fee855b

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

llvm/lib/CodeGen/MachinePipeliner.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,17 +1012,13 @@ unsigned SwingSchedulerDAG::calculateResMII() {
10121012
});
10131013
for (unsigned C = 0; C < NumCycles; ++C)
10141014
while (RI != RE) {
1015-
if ((*RI++)->canReserveResources(*MI)) {
1015+
if ((*RI)->canReserveResources(*MI)) {
1016+
(*RI)->reserveResources(*MI);
10161017
++ReservedCycles;
10171018
break;
10181019
}
1020+
RI++;
10191021
}
1020-
// Start reserving resources using existing DFAs.
1021-
for (unsigned C = 0; C < ReservedCycles; ++C) {
1022-
--RI;
1023-
(*RI)->reserveResources(*MI);
1024-
}
1025-
10261022
LLVM_DEBUG(dbgs() << "ReservedCycles:" << ReservedCycles
10271023
<< ", NumCycles:" << NumCycles << "\n");
10281024
// Add new DFAs, if needed, to reserve resources.

llvm/test/CodeGen/PowerPC/sms-iterator.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
%0 = type { i32, [16 x double] }
77

8-
; CHECK: MII = 7 MAX_II = 17
8+
; CHECK: MII = 8 MAX_II = 18
99

1010
define dso_local fastcc void @_ZN3povL9polysolveEiPdS0_() unnamed_addr #0 {
1111
br label %1

0 commit comments

Comments
 (0)