Lewis Revill | 39263ac | 2019-06-19 08:40:59 +0000 | [diff] [blame^] | 1 | ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py |
| 2 | ; RUN: llc -mtriple=riscv32 -relocation-model=pic < %s \ |
| 3 | ; RUN: | FileCheck -check-prefix=RV32-PIC %s |
| 4 | ; RUN: llc -mtriple=riscv64 -relocation-model=pic < %s \ |
| 5 | ; RUN: | FileCheck -check-prefix=RV64-PIC %s |
| 6 | ; RUN: llc -mtriple=riscv32 < %s | FileCheck -check-prefix=NOPIC %s |
| 7 | ; RUN: llc -mtriple=riscv64 < %s | FileCheck -check-prefix=NOPIC %s |
| 8 | |
| 9 | ; Check that TLS symbols are lowered correctly based on the specified |
| 10 | ; model. |
| 11 | |
| 12 | @unspecified = thread_local global i32 42 |
| 13 | @ld = thread_local(localdynamic) global i32 42 |
| 14 | @ie = thread_local(initialexec) global i32 42 |
| 15 | @le = thread_local(localexec) global i32 42 |
| 16 | |
| 17 | |
| 18 | ; No model specified |
| 19 | |
| 20 | define i32* @f1() nounwind { |
| 21 | ; RV32-PIC-LABEL: f1: |
| 22 | ; RV32-PIC: # %bb.0: # %entry |
| 23 | ; RV32-PIC-NEXT: addi sp, sp, -16 |
| 24 | ; RV32-PIC-NEXT: sw ra, 12(sp) |
| 25 | ; RV32-PIC-NEXT: .LBB0_1: # %entry |
| 26 | ; RV32-PIC-NEXT: # Label of block must be emitted |
| 27 | ; RV32-PIC-NEXT: auipc a0, %tls_gd_pcrel_hi(unspecified) |
| 28 | ; RV32-PIC-NEXT: addi a0, a0, %pcrel_lo(.LBB0_1) |
| 29 | ; RV32-PIC-NEXT: call __tls_get_addr@plt |
| 30 | ; RV32-PIC-NEXT: lw ra, 12(sp) |
| 31 | ; RV32-PIC-NEXT: addi sp, sp, 16 |
| 32 | ; RV32-PIC-NEXT: ret |
| 33 | ; |
| 34 | ; RV64-PIC-LABEL: f1: |
| 35 | ; RV64-PIC: # %bb.0: # %entry |
| 36 | ; RV64-PIC-NEXT: addi sp, sp, -16 |
| 37 | ; RV64-PIC-NEXT: sd ra, 8(sp) |
| 38 | ; RV64-PIC-NEXT: .LBB0_1: # %entry |
| 39 | ; RV64-PIC-NEXT: # Label of block must be emitted |
| 40 | ; RV64-PIC-NEXT: auipc a0, %tls_gd_pcrel_hi(unspecified) |
| 41 | ; RV64-PIC-NEXT: addi a0, a0, %pcrel_lo(.LBB0_1) |
| 42 | ; RV64-PIC-NEXT: call __tls_get_addr@plt |
| 43 | ; RV64-PIC-NEXT: ld ra, 8(sp) |
| 44 | ; RV64-PIC-NEXT: addi sp, sp, 16 |
| 45 | ; RV64-PIC-NEXT: ret |
| 46 | ; |
| 47 | ; NOPIC-LABEL: f1: |
| 48 | ; NOPIC: # %bb.0: # %entry |
| 49 | ; NOPIC-NEXT: lui a0, %tprel_hi(unspecified) |
| 50 | ; NOPIC-NEXT: add a0, a0, tp, %tprel_add(unspecified) |
| 51 | ; NOPIC-NEXT: addi a0, a0, %tprel_lo(unspecified) |
| 52 | ; NOPIC-NEXT: ret |
| 53 | entry: |
| 54 | ret i32* @unspecified |
| 55 | } |
| 56 | |
| 57 | |
| 58 | ; localdynamic specified |
| 59 | |
| 60 | define i32* @f2() nounwind { |
| 61 | ; RV32-PIC-LABEL: f2: |
| 62 | ; RV32-PIC: # %bb.0: # %entry |
| 63 | ; RV32-PIC-NEXT: addi sp, sp, -16 |
| 64 | ; RV32-PIC-NEXT: sw ra, 12(sp) |
| 65 | ; RV32-PIC-NEXT: .LBB1_1: # %entry |
| 66 | ; RV32-PIC-NEXT: # Label of block must be emitted |
| 67 | ; RV32-PIC-NEXT: auipc a0, %tls_gd_pcrel_hi(ld) |
| 68 | ; RV32-PIC-NEXT: addi a0, a0, %pcrel_lo(.LBB1_1) |
| 69 | ; RV32-PIC-NEXT: call __tls_get_addr@plt |
| 70 | ; RV32-PIC-NEXT: lw ra, 12(sp) |
| 71 | ; RV32-PIC-NEXT: addi sp, sp, 16 |
| 72 | ; RV32-PIC-NEXT: ret |
| 73 | ; |
| 74 | ; RV64-PIC-LABEL: f2: |
| 75 | ; RV64-PIC: # %bb.0: # %entry |
| 76 | ; RV64-PIC-NEXT: addi sp, sp, -16 |
| 77 | ; RV64-PIC-NEXT: sd ra, 8(sp) |
| 78 | ; RV64-PIC-NEXT: .LBB1_1: # %entry |
| 79 | ; RV64-PIC-NEXT: # Label of block must be emitted |
| 80 | ; RV64-PIC-NEXT: auipc a0, %tls_gd_pcrel_hi(ld) |
| 81 | ; RV64-PIC-NEXT: addi a0, a0, %pcrel_lo(.LBB1_1) |
| 82 | ; RV64-PIC-NEXT: call __tls_get_addr@plt |
| 83 | ; RV64-PIC-NEXT: ld ra, 8(sp) |
| 84 | ; RV64-PIC-NEXT: addi sp, sp, 16 |
| 85 | ; RV64-PIC-NEXT: ret |
| 86 | ; |
| 87 | ; NOPIC-LABEL: f2: |
| 88 | ; NOPIC: # %bb.0: # %entry |
| 89 | ; NOPIC-NEXT: lui a0, %tprel_hi(ld) |
| 90 | ; NOPIC-NEXT: add a0, a0, tp, %tprel_add(ld) |
| 91 | ; NOPIC-NEXT: addi a0, a0, %tprel_lo(ld) |
| 92 | ; NOPIC-NEXT: ret |
| 93 | entry: |
| 94 | ret i32* @ld |
| 95 | } |
| 96 | |
| 97 | |
| 98 | ; initialexec specified |
| 99 | |
| 100 | define i32* @f3() nounwind { |
| 101 | ; RV32-PIC-LABEL: f3: |
| 102 | ; RV32-PIC: # %bb.0: # %entry |
| 103 | ; RV32-PIC-NEXT: .LBB2_1: # %entry |
| 104 | ; RV32-PIC-NEXT: # Label of block must be emitted |
| 105 | ; RV32-PIC-NEXT: auipc a0, %tls_ie_pcrel_hi(ie) |
| 106 | ; RV32-PIC-NEXT: lw a0, %pcrel_lo(.LBB2_1)(a0) |
| 107 | ; RV32-PIC-NEXT: add a0, a0, tp |
| 108 | ; RV32-PIC-NEXT: ret |
| 109 | ; |
| 110 | ; RV64-PIC-LABEL: f3: |
| 111 | ; RV64-PIC: # %bb.0: # %entry |
| 112 | ; RV64-PIC-NEXT: .LBB2_1: # %entry |
| 113 | ; RV64-PIC-NEXT: # Label of block must be emitted |
| 114 | ; RV64-PIC-NEXT: auipc a0, %tls_ie_pcrel_hi(ie) |
| 115 | ; RV64-PIC-NEXT: ld a0, %pcrel_lo(.LBB2_1)(a0) |
| 116 | ; RV64-PIC-NEXT: add a0, a0, tp |
| 117 | ; RV64-PIC-NEXT: ret |
| 118 | ; |
| 119 | ; NOPIC-LABEL: f3: |
| 120 | ; NOPIC: # %bb.0: # %entry |
| 121 | ; NOPIC-NEXT: lui a0, %tprel_hi(ie) |
| 122 | ; NOPIC-NEXT: add a0, a0, tp, %tprel_add(ie) |
| 123 | ; NOPIC-NEXT: addi a0, a0, %tprel_lo(ie) |
| 124 | ; NOPIC-NEXT: ret |
| 125 | entry: |
| 126 | ret i32* @ie |
| 127 | } |
| 128 | |
| 129 | |
| 130 | ; localexec specified |
| 131 | |
| 132 | define i32* @f4() nounwind { |
| 133 | ; RV32-PIC-LABEL: f4: |
| 134 | ; RV32-PIC: # %bb.0: # %entry |
| 135 | ; RV32-PIC-NEXT: lui a0, %tprel_hi(le) |
| 136 | ; RV32-PIC-NEXT: add a0, a0, tp, %tprel_add(le) |
| 137 | ; RV32-PIC-NEXT: addi a0, a0, %tprel_lo(le) |
| 138 | ; RV32-PIC-NEXT: ret |
| 139 | ; |
| 140 | ; RV64-PIC-LABEL: f4: |
| 141 | ; RV64-PIC: # %bb.0: # %entry |
| 142 | ; RV64-PIC-NEXT: lui a0, %tprel_hi(le) |
| 143 | ; RV64-PIC-NEXT: add a0, a0, tp, %tprel_add(le) |
| 144 | ; RV64-PIC-NEXT: addi a0, a0, %tprel_lo(le) |
| 145 | ; RV64-PIC-NEXT: ret |
| 146 | ; |
| 147 | ; NOPIC-LABEL: f4: |
| 148 | ; NOPIC: # %bb.0: # %entry |
| 149 | ; NOPIC-NEXT: lui a0, %tprel_hi(le) |
| 150 | ; NOPIC-NEXT: add a0, a0, tp, %tprel_add(le) |
| 151 | ; NOPIC-NEXT: addi a0, a0, %tprel_lo(le) |
| 152 | ; NOPIC-NEXT: ret |
| 153 | entry: |
| 154 | ret i32* @le |
| 155 | } |