[llvm] r260737 - [WebAssembly] Fix insertion of a BLOCK in a loop header that also ends a BLOCK.
Dan Gohman via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 12 13:19:26 PST 2016
Author: djg
Date: Fri Feb 12 15:19:25 2016
New Revision: 260737
URL: http://llvm.org/viewvc/llvm-project?rev=260737&view=rev
Log:
[WebAssembly] Fix insertion of a BLOCK in a loop header that also ends a BLOCK.
Modified:
llvm/trunk/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
llvm/trunk/test/CodeGen/WebAssembly/cfg-stackify.ll
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp?rev=260737&r1=260736&r2=260737&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp Fri Feb 12 15:19:25 2016
@@ -334,8 +334,10 @@ static void PlaceBlockMarker(MachineBasi
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.
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=260737&r1=260736&r2=260737&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/cfg-stackify.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/cfg-stackify.ll Fri Feb 12 15:19:25 2016
@@ -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 at 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
+}
More information about the llvm-commits
mailing list