[llvm] r256953 - [WebAssembly] Don't use range-based loop for a list that's being modified
Dan Gohman via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 6 10:29:35 PST 2016
Author: djg
Date: Wed Jan 6 12:29:35 2016
New Revision: 256953
URL: http://llvm.org/viewvc/llvm-project?rev=256953&view=rev
Log:
[WebAssembly] Don't use range-based loop for a list that's being modified
The first instruction in a block is what the rend() iterator points to, so
if it moves, we need to re-evaluate rend() so that we continue to iterate
through the rest of the instructions.
Modified:
llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp
llvm/trunk/test/CodeGen/WebAssembly/cfg-stackify.ll
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp?rev=256953&r1=256952&r2=256953&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp Wed Jan 6 12:29:35 2016
@@ -147,8 +147,10 @@ bool WebAssemblyRegStackify::runOnMachin
// block boundaries, and the blocks aren't ordered so the block visitation
// order isn't significant, but we may want to change this in the future.
for (MachineBasicBlock &MBB : MF) {
- for (MachineInstr &MI : reverse(MBB)) {
- MachineInstr *Insert = &MI;
+ // Don't use a range-based for loop, because we modify the list as we're
+ // iterating over it and the end iterator may change.
+ for (auto MII = MBB.rbegin(); MII != MBB.rend(); ++MII) {
+ MachineInstr *Insert = &*MII;
// Don't nest anything inside a phi.
if (Insert->getOpcode() == TargetOpcode::PHI)
break;
@@ -221,7 +223,7 @@ bool WebAssemblyRegStackify::runOnMachin
Insert = Def;
}
if (AnyStackified)
- ImposeStackOrdering(&MI);
+ ImposeStackOrdering(&*MII);
}
}
Modified: llvm/trunk/test/CodeGen/WebAssembly/cfg-stackify.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/cfg-stackify.ll?rev=256953&r1=256952&r2=256953&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/cfg-stackify.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/cfg-stackify.ll Wed Jan 6 12:29:35 2016
@@ -93,6 +93,7 @@ back:
; Test that a simple loop is handled as expected.
; CHECK-LABEL: test2:
+; CHECK-NOT: local
; CHECK: block BB2_2{{$}}
; CHECK: br_if {{[^,]*}}, BB2_2{{$}}
; CHECK: BB2_1:
More information about the llvm-commits
mailing list