1 ; RUN: llc -mtriple=x86_64-- -asm-verbose=false < %s -jump-table-density=40 -switch-peel-threshold=101 | FileCheck %s
3 ; This switch should use bit tests, and the third bit test case is just
4 ; testing for one possible value, so it doesn't need a bt.
6 ; CHECK: movabsq $2305843009482129440, %r
7 ; CHECK-NEXT: btq %rax, %r
9 ; CHECK: movl $671088640, %e
10 ; CHECK-NEXT: btq %rax, %r
12 ; CHECK: testq %rax, %r
15 define void @test(i8* %l) nounwind {
17 %l.addr = alloca i8*, align 8 ; <i8**> [#uses=2]
18 store i8* %l, i8** %l.addr
19 %tmp = load i8*, i8** %l.addr ; <i8*> [#uses=1]
20 %tmp1 = load i8, i8* %tmp ; <i8> [#uses=1]
21 %conv = sext i8 %tmp1 to i32 ; <i32> [#uses=1]
22 switch i32 %conv, label %sw.default [
31 sw.bb: ; preds = %entry, %entry
35 sw.bb2: ; preds = %entry, %entry, %entry
39 sw.bb4: ; preds = %entry
43 sw.default: ; preds = %entry
44 call void @foo(i32 97)
47 sw.epilog: ; preds = %sw.default, %sw.bb4, %sw.bb2, %sw.bb
51 declare void @foo(i32)
53 ; Don't zero extend the test operands to pointer type if it can be avoided.
55 define void @test2(i32 %x) nounwind ssp {
60 ; CHECK-NEXT: movl $91
65 switch i32 %x, label %if.end [
73 if.then: ; preds = %entry, %entry, %entry, %entry, %entry
74 tail call void @bar() nounwind
77 if.end: ; preds = %entry
83 define void @test3(i32 %x) nounwind {
89 switch i32 %x, label %if.end [
97 tail call void @bar() nounwind
103 ; Ensure that optimizing for jump tables doesn't needlessly deteriorate the
104 ; created binary tree search. See PR22262.
105 define void @test4(i32 %x, i32* %y) {
106 ; CHECK-LABEL: test4:
109 switch i32 %x, label %sw.default [
111 i32 20, label %sw.bb1
112 i32 30, label %sw.bb2
113 i32 40, label %sw.bb3
114 i32 50, label %sw.bb4
115 i32 60, label %sw.bb5
141 ; The balanced binary switch here would start with a comparison against 39, but
142 ; it is currently starting with 29 because of the density-sum heuristic.
160 ; Omit the range check when the default case is unreachable, see PR43129.
162 define void @test5(i32 %x) {
167 ; 73 = 2^0 + 2^3 + 2^6
172 ; 146 = 2^1 + 2^4 + 2^7
173 ; CHECK-NEXT: movl $146
179 switch i32 %x, label %return [
192 bb0: tail call void @g(i32 0) br label %return
193 bb1: tail call void @g(i32 1) br label %return
194 bb2: tail call void @g(i32 2) br label %return