1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=rel-lookup-table-converter -mtriple=x86_64-linux -S | FileCheck %s
3 ; RUN: opt < %s -passes=rel-lookup-table-converter -mtriple=i386-unknown-unknown -relocation-model=pic -S | FileCheck %s
4 ; RUN: opt < %s -passes=rel-lookup-table-converter -mtriple=x86_64-linux -relocation-model=pic -code-model=medium -S | FileCheck %s
5 ; RUN: opt < %s -passes=rel-lookup-table-converter -mtriple=x86_64-linux -relocation-model=pic -code-model=large -S | FileCheck %s
6 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
8 @.str = private unnamed_addr constant [5 x i8] c"zero\00", align 1
9 @.str.1 = private unnamed_addr constant [4 x i8] c"one\00", align 1
10 @.str.2 = private unnamed_addr constant [4 x i8] c"two\00", align 1
11 @.str.3 = private unnamed_addr constant [8 x i8] c"default\00", align 1
13 @switch.table.string_table = private unnamed_addr constant [3 x ptr]
21 ; CHECK: @switch.table.string_table = private unnamed_addr constant [3 x ptr]
23 ; CHECK-SAME: ptr @.str,
24 ; CHECK-SAME: ptr @.str.1,
25 ; CHECK-SAME: ptr @.str.2
26 ; CHECK-SAME: ], align 8
28 ; ; Relative switch lookup table for strings
29 define ptr @string_table(i32 %cond) {
30 ; CHECK-LABEL: @string_table(
32 ; CHECK-NEXT: [[TMP0:%.*]] = icmp ult i32 [[COND:%.*]], 3
33 ; CHECK-NEXT: br i1 [[TMP0]], label [[SWITCH_LOOKUP:%.*]], label [[RETURN:%.*]]
34 ; CHECK: switch.lookup:
35 ; CHECK-NEXT: [[SWITCH_GEP:%.*]] = getelementptr inbounds [3 x ptr], ptr @switch.table.string_table, i32 0, i32 [[COND]]
36 ; CHECK-NEXT: [[SWITCH_LOAD:%.*]] = load ptr, ptr [[SWITCH_GEP]], align 8
37 ; CHECK-NEXT: ret ptr [[SWITCH_LOAD]]
39 ; CHECK-NEXT: ret ptr @.str.3
42 %0 = icmp ult i32 %cond, 3
43 br i1 %0, label %switch.lookup, label %return
45 switch.lookup: ; preds = %entry
46 %switch.gep = getelementptr inbounds [3 x ptr], ptr @switch.table.string_table, i32 0, i32 %cond
47 %switch.load = load ptr, ptr %switch.gep, align 8
50 return: ; preds = %entry