[PATCH] D63536: [MachinePipeliner] Fix risky iterator usage R++, --R
Jinsong Ji via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 18 20:55:25 PDT 2019
jsji created this revision.
jsji added reviewers: bcahoon, hfinkel.
Herald added subscribers: hiraditya, nemanjai.
Herald added a project: LLVM.
When we calculateResMII, we use two loops, one with iterator
(*RI++)->canReserveResources
to check whether we can reserve the resource,
then later in another loop, we use
--RI;
(*RI)->reserveResources(*MI);
Trying to move back iterator to do reservation.
This is risky, as after several iterator `R++`,
**--R may not move back to point to the same Resource at all,**
so we may actually test with one Resource, but reserve in another Resources,
hence overbooking some Resource.
The can cause wrong MII being calculated.
Repository:
rL LLVM
https://reviews.llvm.org/D63536
Files:
llvm/lib/CodeGen/MachinePipeliner.cpp
llvm/test/CodeGen/PowerPC/sms-iterator.ll
Index: llvm/test/CodeGen/PowerPC/sms-iterator.ll
===================================================================
--- llvm/test/CodeGen/PowerPC/sms-iterator.ll
+++ llvm/test/CodeGen/PowerPC/sms-iterator.ll
@@ -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
Index: llvm/lib/CodeGen/MachinePipeliner.cpp
===================================================================
--- llvm/lib/CodeGen/MachinePipeliner.cpp
+++ llvm/lib/CodeGen/MachinePipeliner.cpp
@@ -1012,17 +1012,13 @@
});
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63536.205502.patch
Type: text/x-patch
Size: 1288 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190619/4f27f8df/attachment.bin>
More information about the llvm-commits
mailing list