summaryrefslogtreecommitdiff
path: root/test/Transforms
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2014-01-15 05:00:27 +0000
committerHans Wennborg <hans@hanshq.net>2014-01-15 05:00:27 +0000
commit89fa06ba0f54cc90dbdce4f6a91d09f30f033e0a (patch)
treefd021a5cd5388589f0382cc26741f45cb525a286 /test/Transforms
parent27a41c154721b38f0192d9bd2e1d90e43f5083e4 (diff)
downloadllvm-89fa06ba0f54cc90dbdce4f6a91d09f30f033e0a.tar.gz
llvm-89fa06ba0f54cc90dbdce4f6a91d09f30f033e0a.tar.bz2
llvm-89fa06ba0f54cc90dbdce4f6a91d09f30f033e0a.tar.xz
Switch-to-lookup tables: set threshold to 3 cases
There has been an old FIXME to find the right cut-off for when it's worth analyzing and potentially transforming a switch to a lookup table. The switches always have two or more cases. I could not measure any speed-up by transforming a switch with two cases. A switch with three cases gets a nice speed-up, and I couldn't measure any compile-time regression, so I think this is the right threshold. In a Clang self-host, this causes 480 new switches to be transformed, and reduces the final binary size with 8 KB. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199294 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Transforms')
-rw-r--r--test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll b/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll
index 4ac02dbdf3..b47fa02af2 100644
--- a/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll
+++ b/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll
@@ -856,3 +856,39 @@ return:
; CHECK-NOT: @switch.table
; CHECK: switch i32
}
+
+; We build lookup tables for switches with three or more cases.
+define i32 @threecases(i32 %c) {
+entry:
+ switch i32 %c, label %sw.default [
+ i32 0, label %return
+ i32 1, label %sw.bb1
+ i32 2, label %sw.bb2
+ ]
+sw.bb1: br label %return
+sw.bb2: br label %return
+sw.default: br label %return
+return:
+ %x = phi i32 [ 3, %sw.default ], [ 5, %sw.bb2 ], [ 7, %sw.bb1 ], [ 9, %entry ]
+ ret i32 %x
+; CHECK-LABEL: @threecases(
+; CHECK-NOT: switch i32
+; CHECK: @switch.table
+}
+
+; We don't build tables for switches with two cases.
+define i32 @twocases(i32 %c) {
+entry:
+ switch i32 %c, label %sw.default [
+ i32 0, label %return
+ i32 1, label %sw.bb1
+ ]
+sw.bb1: br label %return
+sw.default: br label %return
+return:
+ %x = phi i32 [ 3, %sw.default ], [ 7, %sw.bb1 ], [ 9, %entry ]
+ ret i32 %x
+; CHECK-LABEL: @twocases(
+; CHECK: switch i32
+; CHECK-NOT: @switch.table
+}