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

# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 3
# RUN: llc -mtriple=riscv32 -run-pass=instruction-select -relocation-model=pic \
# RUN:   %s -o - | FileCheck --check-prefix=RV32-PIE %s
# RUN: llc -mtriple=riscv32 -run-pass=instruction-select \
# RUN:   -mattr=+tagged-globals %s -o - | FileCheck  \
# RUN:   --check-prefix=RV32-NOPIE-TAG %s
# RUN: llc -mtriple=riscv32 -run-pass=instruction-select -code-model=small \
# RUN:   %s -o - | FileCheck --check-prefix=RV32-SMALL-NOPIE-NOTAG %s
# RUN: llc -mtriple=riscv32 -run-pass=instruction-select -code-model=medium \
# RUN:   %s -o - | FileCheck --check-prefix=RV32-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:
    ; RV32-PIE-LABEL: name: global_addr
    ; RV32-PIE: [[PseudoLGA:%[0-9]+]]:gpr = PseudoLGA @x :: (dereferenceable invariant load (p0) from got)
    ; RV32-PIE-NEXT: $x10 = COPY [[PseudoLGA]]
    ; RV32-PIE-NEXT: PseudoRET implicit $x10
    ;
    ; RV32-NOPIE-TAG-LABEL: name: global_addr
    ; RV32-NOPIE-TAG: [[PseudoLGA:%[0-9]+]]:gpr = PseudoLGA @x :: (dereferenceable invariant load (p0) from got)
    ; RV32-NOPIE-TAG-NEXT: $x10 = COPY [[PseudoLGA]]
    ; RV32-NOPIE-TAG-NEXT: PseudoRET implicit $x10
    ;
    ; RV32-SMALL-NOPIE-NOTAG-LABEL: name: global_addr
    ; RV32-SMALL-NOPIE-NOTAG: [[LUI:%[0-9]+]]:gpr = LUI target-flags(riscv-hi) @x
    ; RV32-SMALL-NOPIE-NOTAG-NEXT: [[ADDI:%[0-9]+]]:gpr = ADDI [[LUI]], target-flags(riscv-lo) @x
    ; RV32-SMALL-NOPIE-NOTAG-NEXT: $x10 = COPY [[ADDI]]
    ; RV32-SMALL-NOPIE-NOTAG-NEXT: PseudoRET implicit $x10
    ;
    ; RV32-MED-LABEL: name: global_addr
    ; RV32-MED: [[PseudoLLA:%[0-9]+]]:gpr = PseudoLLA @x
    ; RV32-MED-NEXT: $x10 = COPY [[PseudoLLA]]
    ; RV32-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:
    ; RV32-PIE-LABEL: name: extern_weak_global_addr
    ; RV32-PIE: [[PseudoLGA:%[0-9]+]]:gpr = PseudoLGA @y :: (dereferenceable invariant load (p0) from got)
    ; RV32-PIE-NEXT: $x10 = COPY [[PseudoLGA]]
    ; RV32-PIE-NEXT: PseudoRET implicit $x10
    ;
    ; RV32-NOPIE-TAG-LABEL: name: extern_weak_global_addr
    ; RV32-NOPIE-TAG: [[PseudoLGA:%[0-9]+]]:gpr = PseudoLGA @y :: (dereferenceable invariant load (p0) from got)
    ; RV32-NOPIE-TAG-NEXT: $x10 = COPY [[PseudoLGA]]
    ; RV32-NOPIE-TAG-NEXT: PseudoRET implicit $x10
    ;
    ; RV32-SMALL-NOPIE-NOTAG-LABEL: name: extern_weak_global_addr
    ; RV32-SMALL-NOPIE-NOTAG: [[LUI:%[0-9]+]]:gpr = LUI target-flags(riscv-hi) @y
    ; RV32-SMALL-NOPIE-NOTAG-NEXT: [[ADDI:%[0-9]+]]:gpr = ADDI [[LUI]], target-flags(riscv-lo) @y
    ; RV32-SMALL-NOPIE-NOTAG-NEXT: $x10 = COPY [[ADDI]]
    ; RV32-SMALL-NOPIE-NOTAG-NEXT: PseudoRET implicit $x10
    ;
    ; RV32-MED-LABEL: name: extern_weak_global_addr
    ; RV32-MED: [[PseudoLGA:%[0-9]+]]:gpr = PseudoLGA @y :: (dereferenceable invariant load (p0) from got)
    ; RV32-MED-NEXT: $x10 = COPY [[PseudoLGA]]
    ; RV32-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:
    ; RV32-PIE-LABEL: name: local_global_addr
    ; RV32-PIE: [[PseudoLLA:%[0-9]+]]:gpr = PseudoLLA @z
    ; RV32-PIE-NEXT: $x10 = COPY [[PseudoLLA]]
    ; RV32-PIE-NEXT: PseudoRET implicit $x10
    ;
    ; RV32-NOPIE-TAG-LABEL: name: local_global_addr
    ; RV32-NOPIE-TAG: [[PseudoLGA:%[0-9]+]]:gpr = PseudoLGA @z :: (dereferenceable invariant load (p0) from got)
    ; RV32-NOPIE-TAG-NEXT: $x10 = COPY [[PseudoLGA]]
    ; RV32-NOPIE-TAG-NEXT: PseudoRET implicit $x10
    ;
    ; RV32-SMALL-NOPIE-NOTAG-LABEL: name: local_global_addr
    ; RV32-SMALL-NOPIE-NOTAG: [[LUI:%[0-9]+]]:gpr = LUI target-flags(riscv-hi) @z
    ; RV32-SMALL-NOPIE-NOTAG-NEXT: [[ADDI:%[0-9]+]]:gpr = ADDI [[LUI]], target-flags(riscv-lo) @z
    ; RV32-SMALL-NOPIE-NOTAG-NEXT: $x10 = COPY [[ADDI]]
    ; RV32-SMALL-NOPIE-NOTAG-NEXT: PseudoRET implicit $x10
    ;
    ; RV32-MED-LABEL: name: local_global_addr
    ; RV32-MED: [[PseudoLLA:%[0-9]+]]:gpr = PseudoLLA @z
    ; RV32-MED-NEXT: $x10 = COPY [[PseudoLLA]]
    ; RV32-MED-NEXT: PseudoRET implicit $x10
    %0:gprb(p0) = G_GLOBAL_VALUE @z
    $x10 = COPY %0(p0)
    PseudoRET implicit $x10
...