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 i32* @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: .LBB0_1: # %entry 30; RV32-PIC-NEXT: # Label of block must be emitted 31; RV32-PIC-NEXT: auipc a0, %got_pcrel_hi(external_var) 32; RV32-PIC-NEXT: lw a0, %pcrel_lo(.LBB0_1)(a0) 33; RV32-PIC-NEXT: ret 34; 35; RV64-STATIC-LABEL: f1: 36; RV64-STATIC: # %bb.0: # %entry 37; RV64-STATIC-NEXT: lui a0, %hi(external_var) 38; RV64-STATIC-NEXT: addi a0, a0, %lo(external_var) 39; RV64-STATIC-NEXT: ret 40; 41; RV64-PIC-LABEL: f1: 42; RV64-PIC: # %bb.0: # %entry 43; RV64-PIC-NEXT: .LBB0_1: # %entry 44; RV64-PIC-NEXT: # Label of block must be emitted 45; RV64-PIC-NEXT: auipc a0, %got_pcrel_hi(external_var) 46; RV64-PIC-NEXT: ld a0, %pcrel_lo(.LBB0_1)(a0) 47; RV64-PIC-NEXT: ret 48entry: 49 ret i32* @external_var 50} 51 52 53; internal address 54 55define i32* @f2() nounwind { 56; RV32-STATIC-LABEL: f2: 57; RV32-STATIC: # %bb.0: # %entry 58; RV32-STATIC-NEXT: lui a0, %hi(internal_var) 59; RV32-STATIC-NEXT: addi a0, a0, %lo(internal_var) 60; RV32-STATIC-NEXT: ret 61; 62; RV32-PIC-LABEL: f2: 63; RV32-PIC: # %bb.0: # %entry 64; RV32-PIC-NEXT: .LBB1_1: # %entry 65; RV32-PIC-NEXT: # Label of block must be emitted 66; RV32-PIC-NEXT: auipc a0, %pcrel_hi(internal_var) 67; RV32-PIC-NEXT: addi a0, a0, %pcrel_lo(.LBB1_1) 68; RV32-PIC-NEXT: ret 69; 70; RV64-STATIC-LABEL: f2: 71; RV64-STATIC: # %bb.0: # %entry 72; RV64-STATIC-NEXT: lui a0, %hi(internal_var) 73; RV64-STATIC-NEXT: addi a0, a0, %lo(internal_var) 74; RV64-STATIC-NEXT: ret 75; 76; RV64-PIC-LABEL: f2: 77; RV64-PIC: # %bb.0: # %entry 78; RV64-PIC-NEXT: .LBB1_1: # %entry 79; RV64-PIC-NEXT: # Label of block must be emitted 80; RV64-PIC-NEXT: auipc a0, %pcrel_hi(internal_var) 81; RV64-PIC-NEXT: addi a0, a0, %pcrel_lo(.LBB1_1) 82; RV64-PIC-NEXT: ret 83entry: 84 ret i32* @internal_var 85} 86