146 lines · plain
1# REQUIRES: loongarch2# RUN: rm -rf %t && split-file %s %t && cd %t3 4# RUN: llvm-mc --filetype=obj --triple=loongarch64 a.s -o a.o5# RUN: llvm-mc --filetype=obj --triple=loongarch64 unpaired.s -o unpaired.o6# RUN: llvm-mc --filetype=obj --triple=loongarch64 lone-ldr.s -o lone-ldr.o7 8# RUN: ld.lld a.o -T within-range.t -o a9# RUN: llvm-objdump -d --no-show-raw-insn a | FileCheck %s10 11## This test verifies the encoding when the register $a0 is used.12# CHECK: pcalau12i $a0, 013# CHECK-NEXT: addi.d $a0, $a0, -204814 15## PCALAU12I contains a nonzero addend, no relaxations should be applied.16# CHECK-NEXT: pcalau12i $a1, 217# CHECK-NEXT: ld.d $a1, $a1, -204818 19## LD contains a nonzero addend, no relaxations should be applied.20# CHECK-NEXT: pcalau12i $a2, 221# CHECK-NEXT: ld.d $a2, $a2, -204022 23## PCALAU12I and LD use different registers, no relaxations should be applied.24# CHECK-NEXT: pcalau12i $a3, 225# CHECK-NEXT: ld.d $a4, $a3, -204826 27## PCALAU12I and LD use different registers, no relaxations should be applied.28# CHECK-NEXT: pcalau12i $a5, 229# CHECK-NEXT: ld.d $a5, $a6, -204830 31# RUN: ld.lld a.o -T underflow-range.t -o a-underflow32# RUN: llvm-objdump -d --no-show-raw-insn a-underflow | FileCheck --check-prefix=OUTRANGE %s33 34# RUN: ld.lld a.o -T overflow-range.t -o a-overflow35# RUN: llvm-objdump -d --no-show-raw-insn a-overflow | FileCheck --check-prefix=OUTRANGE %s36 37# OUTRANGE: pcalau12i $a0, 138# OUTRANGE-NEXT: ld.d $a0, $a0, 039 40## Relocations do not appear in pairs, no relaxations should be applied.41# RUN: ld.lld unpaired.o -T within-range.t -o unpaired42# RUN: llvm-objdump --no-show-raw-insn -d unpaired | FileCheck --check-prefix=UNPAIRED %s43 44# UNPAIRED: pcalau12i $a0, 245# UNPAIRED-NEXT: b 846# UNPAIRED-NEXT: pcalau12i $a0, 247# UNPAIRED: ld.d $a0, $a0, -204848 49## Relocations do not appear in pairs, no relaxations should be applied.50# RUN: ld.lld lone-ldr.o -T within-range.t -o lone-ldr51# RUN: llvm-objdump --no-show-raw-insn -d lone-ldr | FileCheck --check-prefix=LONE-LDR %s52 53# LONE-LDR: ld.d $a0, $a0, -204854 55## 32-bit code is mostly the same. We only test a few variants.56# RUN: llvm-mc --filetype=obj --triple=loongarch32 a.32.s -o a.32.o57# RUN: ld.lld a.32.o -T within-range.t -o a3258# RUN: llvm-objdump -d --no-show-raw-insn a32 | FileCheck --check-prefix=CHECK32 %s59 60## This test verifies the encoding when the register $a0 is used.61# CHECK32: pcalau12i $a0, 062# CHECK32-NEXT: addi.w $a0, $a0, -204863 64 65## This linker script ensures that .rodata and .text are sufficiently close to66## each other so that the pcalau12i + ld pair can be relaxed to pcalau12i + add.67#--- within-range.t68SECTIONS {69 .rodata 0x1800: { *(.rodata) }70 .text 0x2800: { *(.text) }71 .got 0x3800: { *(.got) }72}73 74## This linker script ensures that .rodata and .text are sufficiently far apart75## so that the pcalau12i + ld pair cannot be relaxed to pcalau12i + add.76#--- underflow-range.t77SECTIONS {78 .rodata 0x800-4: { *(.rodata) }79 .got 0x80002000: { *(.got) }80 .text 0x80001000: { *(.text) } /* (0x800-4)+2GB+0x800+4 */81}82 83#--- overflow-range.t84SECTIONS {85 .text 0x1000: { *(.text) }86 .got 0x2000: { *(.got) }87 .rodata 0x80000800 : { *(.rodata) } /* 0x1000+2GB-0x800 */88}89 90#--- a.s91## Symbol 'x' is nonpreemptible, the optimization should be applied.92.rodata93.hidden x94x:95.word 1096 97.text98.global _start99_start:100 pcalau12i $a0, %got_pc_hi20(x)101 ld.d $a0, $a0, %got_pc_lo12(x)102 pcalau12i $a1, %got_pc_hi20(x+1)103 ld.d $a1, $a1, %got_pc_lo12(x)104 pcalau12i $a2, %got_pc_hi20(x)105 ld.d $a2, $a2, %got_pc_lo12(x+8)106 pcalau12i $a3, %got_pc_hi20(x)107 ld.d $a4, $a3, %got_pc_lo12(x)108 pcalau12i $a5, %got_pc_hi20(x)109 ld.d $a5, $a6, %got_pc_lo12(x)110 111#--- unpaired.s112.text113.hidden x114x:115 nop116.global _start117_start:118 pcalau12i $a0, %got_pc_hi20(x)119 b L120 pcalau12i $a0, %got_pc_hi20(x)121L:122 ld.d $a0, $a0, %got_pc_lo12(x)123 124#--- lone-ldr.s125.text126.hidden x127x:128 nop129.global _start130_start:131 ld.d $a0, $a0, %got_pc_lo12(x)132 133 134#--- a.32.s135## Symbol 'x' is nonpreemptible, the optimization should be applied.136.rodata137.hidden x138x:139.word 10140 141.text142.global _start143_start:144 pcalau12i $a0, %got_pc_hi20(x)145 ld.w $a0, $a0, %got_pc_lo12(x)146