llvm/llvm/test/CodeGen/RISCV/GlobalISel/instruction-select/global-value64.mir

# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 3
# RUN: llc -mtriple=riscv64 -run-pass=instruction-select -relocation-model=pic \
# RUN:   %s -o - | FileCheck --check-prefix=RV64-PIE %s
# RUN: llc -mtriple=riscv64 -run-pass=instruction-select \
# RUN:   -mattr=+tagged-globals %s -o - | FileCheck  \
# RUN:   --check-prefix=RV64-NOPIE-TAG %s
# RUN: llc -mtriple=riscv64 -run-pass=instruction-select -code-model=small \
# RUN:   %s -o - | FileCheck --check-prefix=RV64-SMALL-NOPIE-NOTAG %s
# RUN: llc -mtriple=riscv64 -run-pass=instruction-select -code-model=medium \
# RUN:   %s -o - | FileCheck --check-prefix=RV64-MED %s

--- |
  @x = global i32 0, align 4
  define ptr @global_addr() {
  entry:
    ret ptr @x
  }
  @y = extern_weak global i32, align 4
  define ptr @extern_weak_global_addr() {
  entry:
    ret ptr @y
  }
  @z = dso_local global i32 0, align 4
  define ptr @local_global_addr() {
  entry:
    ret ptr @z
  }
...
---
name:            global_addr
legalized:       true
regBankSelected: true
tracksRegLiveness: true
registers:
  - { id: 0, class: gprb, preferred-register: '' }
body:             |
  bb.1.entry:
    ; RV64-PIE-LABEL: name: global_addr
    ; RV64-PIE: [[PseudoLGA:%[0-9]+]]:gpr = PseudoLGA @x :: (dereferenceable invariant load (p0) from got)
    ; RV64-PIE-NEXT: $x10 = COPY [[PseudoLGA]]
    ; RV64-PIE-NEXT: PseudoRET implicit $x10
    ;
    ; RV64-NOPIE-TAG-LABEL: name: global_addr
    ; RV64-NOPIE-TAG: [[PseudoLGA:%[0-9]+]]:gpr = PseudoLGA @x :: (dereferenceable invariant load (p0) from got)
    ; RV64-NOPIE-TAG-NEXT: $x10 = COPY [[PseudoLGA]]
    ; RV64-NOPIE-TAG-NEXT: PseudoRET implicit $x10
    ;
    ; RV64-SMALL-NOPIE-NOTAG-LABEL: name: global_addr
    ; RV64-SMALL-NOPIE-NOTAG: [[LUI:%[0-9]+]]:gpr = LUI target-flags(riscv-hi) @x
    ; RV64-SMALL-NOPIE-NOTAG-NEXT: [[ADDI:%[0-9]+]]:gpr = ADDI [[LUI]], target-flags(riscv-lo) @x
    ; RV64-SMALL-NOPIE-NOTAG-NEXT: $x10 = COPY [[ADDI]]
    ; RV64-SMALL-NOPIE-NOTAG-NEXT: PseudoRET implicit $x10
    ;
    ; RV64-MED-LABEL: name: global_addr
    ; RV64-MED: [[PseudoLLA:%[0-9]+]]:gpr = PseudoLLA @x
    ; RV64-MED-NEXT: $x10 = COPY [[PseudoLLA]]
    ; RV64-MED-NEXT: PseudoRET implicit $x10
    %0:gprb(p0) = G_GLOBAL_VALUE @x
    $x10 = COPY %0(p0)
    PseudoRET implicit $x10
...
---
name:            extern_weak_global_addr
legalized:       true
regBankSelected: true
tracksRegLiveness: true
registers:
  - { id: 0, class: gprb, preferred-register: '' }
body:             |
  bb.1.entry:
    ; RV64-PIE-LABEL: name: extern_weak_global_addr
    ; RV64-PIE: [[PseudoLGA:%[0-9]+]]:gpr = PseudoLGA @y :: (dereferenceable invariant load (p0) from got)
    ; RV64-PIE-NEXT: $x10 = COPY [[PseudoLGA]]
    ; RV64-PIE-NEXT: PseudoRET implicit $x10
    ;
    ; RV64-NOPIE-TAG-LABEL: name: extern_weak_global_addr
    ; RV64-NOPIE-TAG: [[PseudoLGA:%[0-9]+]]:gpr = PseudoLGA @y :: (dereferenceable invariant load (p0) from got)
    ; RV64-NOPIE-TAG-NEXT: $x10 = COPY [[PseudoLGA]]
    ; RV64-NOPIE-TAG-NEXT: PseudoRET implicit $x10
    ;
    ; RV64-SMALL-NOPIE-NOTAG-LABEL: name: extern_weak_global_addr
    ; RV64-SMALL-NOPIE-NOTAG: [[LUI:%[0-9]+]]:gpr = LUI target-flags(riscv-hi) @y
    ; RV64-SMALL-NOPIE-NOTAG-NEXT: [[ADDI:%[0-9]+]]:gpr = ADDI [[LUI]], target-flags(riscv-lo) @y
    ; RV64-SMALL-NOPIE-NOTAG-NEXT: $x10 = COPY [[ADDI]]
    ; RV64-SMALL-NOPIE-NOTAG-NEXT: PseudoRET implicit $x10
    ;
    ; RV64-MED-LABEL: name: extern_weak_global_addr
    ; RV64-MED: [[PseudoLGA:%[0-9]+]]:gpr = PseudoLGA @y :: (dereferenceable invariant load (p0) from got)
    ; RV64-MED-NEXT: $x10 = COPY [[PseudoLGA]]
    ; RV64-MED-NEXT: PseudoRET implicit $x10
    %0:gprb(p0) = G_GLOBAL_VALUE @y
    $x10 = COPY %0(p0)
    PseudoRET implicit $x10
...
---
name:            local_global_addr
legalized:       true
regBankSelected: true
tracksRegLiveness: true
registers:
  - { id: 0, class: gprb, preferred-register: '' }
body:             |
  bb.1.entry:
    ; RV64-PIE-LABEL: name: local_global_addr
    ; RV64-PIE: [[PseudoLLA:%[0-9]+]]:gpr = PseudoLLA @z
    ; RV64-PIE-NEXT: $x10 = COPY [[PseudoLLA]]
    ; RV64-PIE-NEXT: PseudoRET implicit $x10
    ;
    ; RV64-NOPIE-TAG-LABEL: name: local_global_addr
    ; RV64-NOPIE-TAG: [[PseudoLGA:%[0-9]+]]:gpr = PseudoLGA @z :: (dereferenceable invariant load (p0) from got)
    ; RV64-NOPIE-TAG-NEXT: $x10 = COPY [[PseudoLGA]]
    ; RV64-NOPIE-TAG-NEXT: PseudoRET implicit $x10
    ;
    ; RV64-SMALL-NOPIE-NOTAG-LABEL: name: local_global_addr
    ; RV64-SMALL-NOPIE-NOTAG: [[LUI:%[0-9]+]]:gpr = LUI target-flags(riscv-hi) @z
    ; RV64-SMALL-NOPIE-NOTAG-NEXT: [[ADDI:%[0-9]+]]:gpr = ADDI [[LUI]], target-flags(riscv-lo) @z
    ; RV64-SMALL-NOPIE-NOTAG-NEXT: $x10 = COPY [[ADDI]]
    ; RV64-SMALL-NOPIE-NOTAG-NEXT: PseudoRET implicit $x10
    ;
    ; RV64-MED-LABEL: name: local_global_addr
    ; RV64-MED: [[PseudoLLA:%[0-9]+]]:gpr = PseudoLLA @z
    ; RV64-MED-NEXT: $x10 = COPY [[PseudoLLA]]
    ; RV64-MED-NEXT: PseudoRET implicit $x10
    %0:gprb(p0) = G_GLOBAL_VALUE @z
    $x10 = COPY %0(p0)
    PseudoRET implicit $x10
...