1; RUN: llc -mtriple=riscv32 --code-model=small \
2; RUN:    -stop-after riscv-expand-pseudo %s -o %t.mir
3; RUN: llc -mtriple=riscv32 -run-pass none %t.mir -o - | \
4; RUN:   FileCheck %s -check-prefix=RV32-SMALL
5;
6; RUN: llc -mtriple=riscv32 --code-model=medium --relocation-model=pic \
7; RUN:   -stop-after riscv-expand-pseudo %s -o %t.mir
8; RUN: llc -mtriple=riscv32 -run-pass none %t.mir -o - | \
9; RUN:   FileCheck %s -check-prefix=RV32-MED
10
11; This tests the RISC-V-specific serialization and deserialization of
12; `target-flags(...)`
13
14@g_e = external global i32
15@g_i = internal global i32 0
16@t_un = external thread_local global i32
17@t_ld = external thread_local(localdynamic) global i32
18@t_ie = external thread_local(initialexec) global i32
19@t_le = external thread_local(localexec) global i32
20
21declare i32 @callee(i32) nounwind
22
23define i32 @caller(i32 %a) nounwind {
24; RV32-SMALL-LABEL: name: caller
25; RV32-SMALL:      target-flags(riscv-hi) @g_e
26; RV32-SMALL-NEXT: target-flags(riscv-lo) @g_e
27; RV32-SMALL-NEXT: target-flags(riscv-hi) @g_i
28; RV32-SMALL-NEXT: target-flags(riscv-lo) @g_i
29; RV32-SMALL:      target-flags(riscv-tls-got-hi) @t_un
30; RV32-SMALL-NEXT: target-flags(riscv-pcrel-lo) %bb.1
31; RV32-SMALL:      target-flags(riscv-tls-got-hi) @t_ld
32; RV32-SMALL-NEXT: target-flags(riscv-pcrel-lo) %bb.2
33; RV32-SMALL:      target-flags(riscv-tls-got-hi) @t_ie
34; RV32-SMALL-NEXT: target-flags(riscv-pcrel-lo) %bb.3
35; RV32-SMALL:      target-flags(riscv-tprel-hi) @t_le
36; RV32-SMALL-NEXT: target-flags(riscv-tprel-add) @t_le
37; RV32-SMALL-NEXT: target-flags(riscv-tprel-lo) @t_le
38; RV32-SMALL:      target-flags(riscv-call) @callee
39;
40; RV32-MED-LABEL: name: caller
41; RV32-MED:      target-flags(riscv-got-hi) @g_e
42; RV32-MED-NEXT: target-flags(riscv-pcrel-lo) %bb.1
43; RV32-MED:      target-flags(riscv-pcrel-hi) @g_i
44; RV32-MED-NEXT: target-flags(riscv-pcrel-lo) %bb.2
45; RV32-MED:      target-flags(riscv-tls-gd-hi) @t_un
46; RV32-MED-NEXT: target-flags(riscv-pcrel-lo) %bb.3
47; RV32-MED-NEXT: target-flags(riscv-plt) &__tls_get_addr
48; RV32-MED:      target-flags(riscv-tls-gd-hi) @t_ld
49; RV32-MED-NEXT: target-flags(riscv-pcrel-lo) %bb.4
50; RV32-MED-NEXT: target-flags(riscv-plt) &__tls_get_addr
51; RV32-MED:      target-flags(riscv-tls-got-hi) @t_ie
52; RV32-MED-NEXT: target-flags(riscv-pcrel-lo) %bb.5
53; RV32-MED:      target-flags(riscv-tprel-hi) @t_le
54; RV32-MED-NEXT: target-flags(riscv-tprel-add) @t_le
55; RV32-MED-NEXT: target-flags(riscv-tprel-lo) @t_le
56; RV32-MED:      target-flags(riscv-plt) @callee
57;
58  %b = load i32, i32* @g_e
59  %c = load i32, i32* @g_i
60  %d = load i32, i32* @t_un
61  %e = load i32, i32* @t_ld
62  %f = load i32, i32* @t_ie
63  %g = load i32, i32* @t_le
64  %sum = bitcast i32 0 to i32
65  %sum.a = add i32 %sum, %a
66  %sum.b = add i32 %sum.a, %b
67  %sum.c = add i32 %sum.b, %c
68  %sum.d = add i32 %sum.c, %d
69  %sum.e = add i32 %sum.d, %e
70  %sum.f = add i32 %sum.e, %f
71  %sum.g = add i32 %sum.f, %g
72  %retval = call i32 @callee(i32 %sum.g)
73  ret i32 %retval
74}
75