1; RUN: llc -verify-machineinstrs -o - %s -mtriple=aarch64-none-linux-gnu -aarch64-atomic-cfg-tidy=0 | FileCheck %s
2; RUN: llc -code-model=large -verify-machineinstrs -o - %s -mtriple=aarch64-none-linux-gnu -aarch64-atomic-cfg-tidy=0 | FileCheck --check-prefix=CHECK-LARGE %s
3; RUN: llc -mtriple=aarch64-none-linux-gnu -verify-machineinstrs -relocation-model=pic -aarch64-atomic-cfg-tidy=0 -o - %s | FileCheck --check-prefix=CHECK-PIC %s
4
5define i32 @test_jumptable(i32 %in) {
6; CHECK: test_jumptable
7
8  switch i32 %in, label %def [
9    i32 0, label %lbl1
10    i32 1, label %lbl2
11    i32 2, label %lbl3
12    i32 4, label %lbl4
13  ]
14; CHECK: adrp [[JTPAGE:x[0-9]+]], .LJTI0_0
15; CHECK: add x[[JT:[0-9]+]], [[JTPAGE]], {{#?}}:lo12:.LJTI0_0
16; CHECK: ldr [[DEST:x[0-9]+]], [x[[JT]], {{x[0-9]+}}, lsl #3]
17; CHECK: br [[DEST]]
18
19; CHECK-LARGE: movz x[[JTADDR:[0-9]+]], #:abs_g3:.LJTI0_0
20; CHECK-LARGE: movk x[[JTADDR]], #:abs_g2_nc:.LJTI0_0
21; CHECK-LARGE: movk x[[JTADDR]], #:abs_g1_nc:.LJTI0_0
22; CHECK-LARGE: movk x[[JTADDR]], #:abs_g0_nc:.LJTI0_0
23; CHECK-LARGE: ldr [[DEST:x[0-9]+]], [x[[JTADDR]], {{x[0-9]+}}, lsl #3]
24; CHECK-LARGE: br [[DEST]]
25
26; CHECK-PIC: adrp [[JTPAGE:x[0-9]+]], .LJTI0_0
27; CHECK-PIC: add x[[JT:[0-9]+]], [[JTPAGE]], {{#?}}:lo12:.LJTI0_0
28; CHECK-PIC: ldrsw [[DEST:x[0-9]+]], [x[[JT]], {{x[0-9]+}}, lsl #2]
29; CHECK-PIC: add [[TABLE:x[0-9]+]], [[DEST]], x[[JT]]
30; CHECK-PIC: br [[TABLE]]
31
32def:
33  ret i32 0
34
35lbl1:
36  ret i32 1
37
38lbl2:
39  ret i32 2
40
41lbl3:
42  ret i32 4
43
44lbl4:
45  ret i32 8
46
47}
48
49; CHECK: .rodata
50
51; CHECK: .LJTI0_0:
52; CHECK-NEXT: .xword
53; CHECK-NEXT: .xword
54; CHECK-NEXT: .xword
55; CHECK-NEXT: .xword
56; CHECK-NEXT: .xword
57
58; CHECK-PIC-NOT: .data_region
59; CHECK-PIC-NOT: .LJTI0_0
60; CHECK-PIC: .LJTI0_0:
61; CHECK-PIC-NEXT: .word .LBB{{.*}}-.LJTI0_0
62; CHECK-PIC-NEXT: .word .LBB{{.*}}-.LJTI0_0
63; CHECK-PIC-NEXT: .word .LBB{{.*}}-.LJTI0_0
64; CHECK-PIC-NEXT: .word .LBB{{.*}}-.LJTI0_0
65; CHECK-PIC-NEXT: .word .LBB{{.*}}-.LJTI0_0
66; CHECK-PIC-NOT: .end_data_region
67