1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -simplifycfg -switch-to-lookup -S -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
3 ; RUN: opt < %s -passes='simplify-cfg<switch-to-lookup>' -S -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
5 ; In the presence of "-no-jump-tables"="true", simplifycfg should not convert switches to lookup tables.
7 define i32 @foo(i32 %c) "no-jump-tables"="true" {
10 ; CHECK-NEXT: switch i32 [[C:%.*]], label [[SW_DEFAULT:%.*]] [
11 ; CHECK-NEXT: i32 42, label [[RETURN:%.*]]
12 ; CHECK-NEXT: i32 43, label [[SW_BB1:%.*]]
13 ; CHECK-NEXT: i32 44, label [[SW_BB2:%.*]]
14 ; CHECK-NEXT: i32 45, label [[SW_BB3:%.*]]
17 ; CHECK-NEXT: br label [[RETURN]]
19 ; CHECK-NEXT: br label [[RETURN]]
21 ; CHECK-NEXT: br label [[RETURN]]
23 ; CHECK-NEXT: br label [[RETURN]]
25 ; CHECK-NEXT: [[RETVAL_0:%.*]] = phi i32 [ 15, [[SW_DEFAULT]] ], [ -1, [[SW_BB3]] ], [ 0, [[SW_BB2]] ], [ 123, [[SW_BB1]] ], [ 55, [[ENTRY:%.*]] ]
26 ; CHECK-NEXT: ret i32 [[RETVAL_0]]
29 switch i32 %c, label %sw.default [
36 sw.bb1: br label %return
37 sw.bb2: br label %return
38 sw.bb3: br label %return
39 sw.default: br label %return
41 %retval.0 = phi i32 [ 15, %sw.default ], [ -1, %sw.bb3 ], [ 0, %sw.bb2 ], [ 123, %sw.bb1 ], [ 55, %entry ]
46 define i32 @bar(i32 %c) {
49 ; CHECK-NEXT: [[SWITCH_TABLEIDX:%.*]] = sub i32 [[C:%.*]], 42
50 ; CHECK-NEXT: [[TMP0:%.*]] = icmp ult i32 [[SWITCH_TABLEIDX]], 4
51 ; CHECK-NEXT: br i1 [[TMP0]], label [[SWITCH_LOOKUP:%.*]], label [[RETURN:%.*]]
52 ; CHECK: switch.lookup:
53 ; CHECK-NEXT: [[SWITCH_GEP:%.*]] = getelementptr inbounds [4 x i32], [4 x i32]* @switch.table.bar, i32 0, i32 [[SWITCH_TABLEIDX]]
54 ; CHECK-NEXT: [[SWITCH_LOAD:%.*]] = load i32, i32* [[SWITCH_GEP]]
55 ; CHECK-NEXT: ret i32 [[SWITCH_LOAD]]
57 ; CHECK-NEXT: ret i32 15
60 switch i32 %c, label %sw.default [
67 sw.bb1: br label %return
68 sw.bb2: br label %return
69 sw.bb3: br label %return
70 sw.default: br label %return
72 %retval.0 = phi i32 [ 15, %sw.default ], [ -1, %sw.bb3 ], [ 0, %sw.bb2 ], [ 123, %sw.bb1 ], [ 55, %entry ]