[llvm] r359038 - [WebAssembly] Emit br_table for most switch instructions
Heejin Ahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 23 14:30:30 PDT 2019
Author: aheejin
Date: Tue Apr 23 14:30:30 2019
New Revision: 359038
URL: http://llvm.org/viewvc/llvm-project?rev=359038&view=rev
Log:
[WebAssembly] Emit br_table for most switch instructions
Summary:
Always convert switches to br_tables unless there is only one case,
which is equivalent to a simple branch. This reduces code size for wasm,
and we defer possible jump table optimizations to the VM.
Addresses PR41502.
Reviewers: kripken, sunfish
Subscribers: dschuff, sbc100, jgravelle-google, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60966
Modified:
llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
llvm/trunk/test/CodeGen/WebAssembly/cfg-stackify.ll
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp?rev=359038&r1=359037&r2=359038&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp Tue Apr 23 14:30:30 2019
@@ -270,6 +270,11 @@ WebAssemblyTargetLowering::WebAssemblyTa
MaxStoresPerMemset = 1;
MaxStoresPerMemsetOptSize = 1;
}
+
+ // Always convert switches to br_tables unless there is only one case, which
+ // is equivalent to a simple branch. This reduces code size for wasm, and we
+ // defer possible jump table optimizations to the VM.
+ setMinimumJumpTableEntries(2);
}
TargetLowering::AtomicExpansionKind
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=359038&r1=359037&r2=359038&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/cfg-stackify.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/cfg-stackify.ll Tue Apr 23 14:30:30 2019
@@ -384,18 +384,12 @@ if.end:
; CHECK-NEXT: .functype test4 (i32) -> (){{$}}
; CHECK: block {{$}}
; CHECK-NEXT: block {{$}}
-; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
-; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
-; CHECK: br 1{{$}}
-; CHECK-NEXT: .LBB{{[0-9]+}}_3:
-; CHECK-NEXT: end_block{{$}}
-; CHECK-NEXT: block {{$}}
-; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
-; CHECK: br_if 1, $pop{{[0-9]+}}{{$}}
-; CHECK-NEXT: .LBB{{[0-9]+}}_5:
+; CHECK: br_if 0, $pop{{[0-9]+}}{{$}}
+; CHECK: br 1{{$}}
+; CHECK-NEXT: .LBB{{[0-9]+}}_2:
; CHECK-NEXT: end_block{{$}}
-; CHECK-NEXT: return{{$}}
-; CHECK-NEXT: .LBB{{[0-9]+}}_6:
+; CHECK-NEXT: br_table $0, 0, 0, 0, 0, 0, 0{{$}}
+; CHECK-NEXT: .LBB{{[0-9]+}}_3:
; CHECK-NEXT: end_block{{$}}
; CHECK-NEXT: return{{$}}
define void @test4(i32 %t) {
@@ -646,29 +640,30 @@ end:
; CHECK-LABEL: test10:
; CHECK: .LBB{{[0-9]+}}_1:
; CHECK-NEXT: loop {{$}}
-; CHECK-NOT: block
-; CHECK: br_if 0, {{[^,]+}}{{$}}
+; CHECK: br_if 0, {{[^,]+}}{{$}}
; CHECK: .LBB{{[0-9]+}}_3:
; CHECK-NEXT: block {{$}}
; CHECK-NEXT: loop {{$}}
-; CHECK-NOT: block
; CHECK: .LBB{{[0-9]+}}_4:
; CHECK-NEXT: loop {{$}}
-; CHECK-NOT: block
-; CHECK: br_if 0, {{[^,]+}}{{$}}
+; CHECK: br_if 0, {{[^,]+}}{{$}}
; CHECK-NEXT: end_loop{{$}}
-; CHECK: br_if 1, {{[^,]+}}{{$}}
-; CHECK-NOT: block
-; CHECK: br_if 0, {{[^,]+}}{{$}}
+; CHECK-NEXT: block {{$}}
+; CHECK: br_if 0, {{[^,]+}}{{$}}
+; CHECK: br 3{{$}}
+; CHECK-NEXT: .LBB{{[0-9]+}}_7:
+; CHECK-NEXT: end_block{{$}}
+; CHECK: block {{$}}
+; CHECK-NEXT: br_table $0, 0, 3, 1, 2, 0
+; CHECK-NEXT: .LBB{{[0-9]+}}_8:
+; CHECK-NEXT: end_block{{$}}
; CHECK-NEXT: end_loop{{$}}
-; CHECK-NOT: block
-; CHECK: br_if 1, {{[^,]+}}{{$}}
; CHECK-NEXT: return{{$}}
; CHECK-NEXT: .LBB{{[0-9]+}}_9:
; CHECK-NEXT: end_block{{$}}
-; CHECK-NOT: block
-; CHECK: br 0{{$}}
+; CHECK: br 0{{$}}
; CHECK-NEXT: .LBB{{[0-9]+}}_10:
+; CHECK-NEXT: end_loop{{$}}
define void @test10() {
bb0:
br label %bb1
@@ -772,31 +767,25 @@ bb8:
; CHECK-LABEL: test12:
; CHECK: .LBB{{[0-9]+}}_1:
-; CHECK-NEXT: block {{$}}
; CHECK-NEXT: loop {{$}}
-; CHECK-NOT: block
-; CHECK: block {{$}}
; CHECK-NEXT: block {{$}}
-; CHECK: br_if 0, {{[^,]+}}{{$}}
-; CHECK-NOT: block
-; CHECK: br_if 1, {{[^,]+}}{{$}}
-; CHECK-NOT: block
-; CHECK: br_if 1, {{[^,]+}}{{$}}
-; CHECK-NEXT: br 3{{$}}
+; CHECK-NEXT: block {{$}}
+; CHECK-NEXT: block {{$}}
+; CHECK: br_if 0, {{[^,]+}}{{$}}
+; CHECK: br_if 2, {{[^,]+}}{{$}}
+; CHECK: br_if 1, {{[^,]+}}{{$}}
+; CHECK-NEXT: br 2{{$}}
; CHECK-NEXT: .LBB{{[0-9]+}}_4:
; CHECK-NEXT: end_block{{$}}
-; CHECK-NOT: block
-; CHECK: br_if 0, {{[^,]+}}{{$}}
-; CHECK-NOT: block
-; CHECK: br_if 2, {{[^,]+}}{{$}}
+; CHECK-NEXT: br_table $2, 1, 0, 0, 0, 1, 1{{$}}
+; CHECK-NEXT: .LBB{{[0-9]+}}_5:
+; CHECK-NEXT: end_block{{$}}
+; CHECK-NEXT: return{{$}}
; CHECK-NEXT: .LBB{{[0-9]+}}_6:
; CHECK-NEXT: end_block{{$}}
-; CHECK-NOT: block
-; CHECK: br 0{{$}}
+; CHECK: br 0{{$}}
; CHECK-NEXT: .LBB{{[0-9]+}}_7:
; CHECK-NEXT: end_loop{{$}}
-; CHECK-NEXT: end_block{{$}}
-; CHECK-NEXT: return{{$}}
define void @test12(i8* %arg) {
bb:
br label %bb1
More information about the llvm-commits
mailing list