summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorDan Gohman <dan433584@gmail.com>2016-02-12 21:19:25 +0000
committerDan Gohman <dan433584@gmail.com>2016-02-12 21:19:25 +0000
commita187ab2aeb4666d799a24b6c9472e6e67d640e1f (patch)
tree045e170fda28d86b70c69303e5801ab63c38daaa /llvm
parentf1d598c2f65cf8d3ca3cb379c6c72023cd35f5a3 (diff)
downloadbcm5719-llvm-a187ab2aeb4666d799a24b6c9472e6e67d640e1f.tar.gz
bcm5719-llvm-a187ab2aeb4666d799a24b6c9472e6e67d640e1f.zip
[WebAssembly] Fix insertion of a BLOCK in a loop header that also ends a BLOCK.
llvm-svn: 260737
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp4
-rw-r--r--llvm/test/CodeGen/WebAssembly/cfg-stackify.ll62
2 files changed, 65 insertions, 1 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
index 9b987650d2f..7581687a7d6 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
@@ -334,8 +334,10 @@ static void PlaceBlockMarker(MachineBasicBlock &MBB, MachineFunction &MF,
MachineLoop *HeaderLoop = MLI.getLoopFor(Header);
if (HeaderLoop && MBB.getNumber() > LoopBottom(HeaderLoop)->getNumber()) {
// Header is the header of a loop that does not lexically contain MBB, so
- // the BLOCK needs to be above the LOOP.
+ // the BLOCK needs to be above the LOOP, after any END constructs.
InsertPos = Header->begin();
+ while (InsertPos->getOpcode() != WebAssembly::LOOP)
+ ++InsertPos;
} else {
// Otherwise, insert the BLOCK as late in Header as we can, but before the
// beginning of the local expression tree and any nested BLOCKs.
diff --git a/llvm/test/CodeGen/WebAssembly/cfg-stackify.ll b/llvm/test/CodeGen/WebAssembly/cfg-stackify.ll
index 31f5ba05db1..fdfe489f1b7 100644
--- a/llvm/test/CodeGen/WebAssembly/cfg-stackify.ll
+++ b/llvm/test/CodeGen/WebAssembly/cfg-stackify.ll
@@ -1228,3 +1228,65 @@ bb48:
bb50:
ret void
}
+
+; Test that a block boundary which ends one block, begins another block, and
+; also begins a loop, has the markers placed in the correct order.
+
+; CHECK-LABEL: test15:
+; CHECK: block
+; CHECK-NEXT: i32.const $push{{.*}}=, 1{{$}}
+; CHECK-NEXT: br_if 0, $pop{{.*}}{{$}}
+; CHECK-NEXT: .LBB24_1:
+; CHECK-NEXT: block
+; CHECK-NEXT: loop
+; OPT-LABEL: test15:
+; OPT: block
+; OPT-NEXT: i32.const $push
+; OPT-NEXT: i32.const $push
+; OPT-NEXT: i32.eq $push{{.*}}=, $pop{{.*}}, $pop{{.*}}{{$}}
+; OPT-NEXT: br_if 0, $pop{{.*}}{{$}}
+; OPT-NEXT: call test15_callee1@FUNCTION{{$}}
+; OPT-NEXT: return{{$}}
+; OPT-NEXT: .LBB24_2:
+; OPT-NEXT: end_block
+; OPT-NEXT: block
+; OPT-NEXT: loop
+%0 = type { i8, i32 }
+declare void @test15_callee0()
+declare void @test15_callee1()
+define void @test15() {
+bb:
+ %tmp1 = icmp eq i8 1, 0
+ br i1 %tmp1, label %bb2, label %bb14
+
+bb2:
+ %tmp3 = phi %0** [ %tmp6, %bb5 ], [ null, %bb ]
+ %tmp4 = icmp eq i32 0, 11
+ br i1 %tmp4, label %bb5, label %bb8
+
+bb5:
+ %tmp = bitcast i8* null to %0**
+ %tmp6 = getelementptr %0*, %0** %tmp3, i32 1
+ %tmp7 = icmp eq %0** %tmp6, null
+ br i1 %tmp7, label %bb10, label %bb2
+
+bb8:
+ %tmp9 = icmp eq %0** null, undef
+ br label %bb10
+
+bb10:
+ %tmp11 = phi %0** [ null, %bb8 ], [ %tmp, %bb5 ]
+ %tmp12 = icmp eq %0** null, %tmp11
+ br i1 %tmp12, label %bb15, label %bb13
+
+bb13:
+ call void @test15_callee0()
+ ret void
+
+bb14:
+ call void @test15_callee1()
+ ret void
+
+bb15:
+ ret void
+}
OpenPOWER on IntegriCloud