xref: /llvm-project/llvm/test/CodeGen/RISCV/pic-models.ll (revision 1456b68686808fa7c6ed7327aba65b639f81d5b8)
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc -mtriple=riscv32 -relocation-model=static < %s \
3; RUN:     | FileCheck -check-prefix=RV32-STATIC %s
4; RUN: llc -mtriple=riscv32 -relocation-model=pic < %s \
5; RUN:     | FileCheck -check-prefix=RV32-PIC %s
6; RUN: llc -mtriple=riscv64 -relocation-model=static < %s \
7; RUN:     | FileCheck -check-prefix=RV64-STATIC %s
8; RUN: llc -mtriple=riscv64 -relocation-model=pic < %s \
9; RUN:     | FileCheck -check-prefix=RV64-PIC %s
10
11; Check basic lowering of PIC addressing.
12; TODO: Check other relocation models?
13
14@external_var = external global i32
15@internal_var = internal global i32 42
16
17
18; external address
19
20define ptr @f1() nounwind {
21; RV32-STATIC-LABEL: f1:
22; RV32-STATIC:       # %bb.0: # %entry
23; RV32-STATIC-NEXT:    lui a0, %hi(external_var)
24; RV32-STATIC-NEXT:    addi a0, a0, %lo(external_var)
25; RV32-STATIC-NEXT:    ret
26;
27; RV32-PIC-LABEL: f1:
28; RV32-PIC:       # %bb.0: # %entry
29; RV32-PIC-NEXT:  .Lpcrel_hi0:
30; RV32-PIC-NEXT:    auipc a0, %got_pcrel_hi(external_var)
31; RV32-PIC-NEXT:    lw a0, %pcrel_lo(.Lpcrel_hi0)(a0)
32; RV32-PIC-NEXT:    ret
33;
34; RV64-STATIC-LABEL: f1:
35; RV64-STATIC:       # %bb.0: # %entry
36; RV64-STATIC-NEXT:    lui a0, %hi(external_var)
37; RV64-STATIC-NEXT:    addi a0, a0, %lo(external_var)
38; RV64-STATIC-NEXT:    ret
39;
40; RV64-PIC-LABEL: f1:
41; RV64-PIC:       # %bb.0: # %entry
42; RV64-PIC-NEXT:  .Lpcrel_hi0:
43; RV64-PIC-NEXT:    auipc a0, %got_pcrel_hi(external_var)
44; RV64-PIC-NEXT:    ld a0, %pcrel_lo(.Lpcrel_hi0)(a0)
45; RV64-PIC-NEXT:    ret
46entry:
47  ret ptr @external_var
48}
49
50
51; internal address
52
53define ptr @f2() nounwind {
54; RV32-STATIC-LABEL: f2:
55; RV32-STATIC:       # %bb.0: # %entry
56; RV32-STATIC-NEXT:    lui a0, %hi(internal_var)
57; RV32-STATIC-NEXT:    addi a0, a0, %lo(internal_var)
58; RV32-STATIC-NEXT:    ret
59;
60; RV32-PIC-LABEL: f2:
61; RV32-PIC:       # %bb.0: # %entry
62; RV32-PIC-NEXT:  .Lpcrel_hi1:
63; RV32-PIC-NEXT:    auipc a0, %pcrel_hi(internal_var)
64; RV32-PIC-NEXT:    addi a0, a0, %pcrel_lo(.Lpcrel_hi1)
65; RV32-PIC-NEXT:    ret
66;
67; RV64-STATIC-LABEL: f2:
68; RV64-STATIC:       # %bb.0: # %entry
69; RV64-STATIC-NEXT:    lui a0, %hi(internal_var)
70; RV64-STATIC-NEXT:    addi a0, a0, %lo(internal_var)
71; RV64-STATIC-NEXT:    ret
72;
73; RV64-PIC-LABEL: f2:
74; RV64-PIC:       # %bb.0: # %entry
75; RV64-PIC-NEXT:  .Lpcrel_hi1:
76; RV64-PIC-NEXT:    auipc a0, %pcrel_hi(internal_var)
77; RV64-PIC-NEXT:    addi a0, a0, %pcrel_lo(.Lpcrel_hi1)
78; RV64-PIC-NEXT:    ret
79entry:
80  ret ptr @internal_var
81}
82