Skip to content

Commit e256eda

Browse files
wangleiattstellar
authored andcommitted
[LoongArch][MC] Add relocation support for fld fst [x]vld [x]vst
This also fixes errors when using Clang with step-by-step compilation. Because the optimization will pass relocation information to memory access instructions. For example: t.c: ``` float f = 0.1; float foo() { return f;} ``` ``` clang --target=loongarch64 -O2 -c t.c --save-temps ``` Reviewed By: tangaac, SixWeining Pull Request: #133225 (cherry picked from commit d055e58)
1 parent ba00d9f commit e256eda

File tree

6 files changed

+36
-31
lines changed

6 files changed

+36
-31
lines changed

llvm/lib/Target/LoongArch/LoongArchFloatInstrFormats.td

+2-2
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class FP_LOAD_3R<bits<32> op, RegisterClass rc = FPR32>
206206
: FPFmtMEM<op, (outs rc:$fd), (ins GPR:$rj, GPR:$rk),
207207
"$fd, $rj, $rk">;
208208
class FP_LOAD_2RI12<bits<32> op, RegisterClass rc = FPR32>
209-
: FPFmt2RI12<op, (outs rc:$fd), (ins GPR:$rj, simm12:$imm12),
209+
: FPFmt2RI12<op, (outs rc:$fd), (ins GPR:$rj, simm12_addlike:$imm12),
210210
"$fd, $rj, $imm12">;
211211
} // hasSideEffects = 0, mayLoad = 1, mayStore = 0
212212

@@ -215,7 +215,7 @@ class FP_STORE_3R<bits<32> op, RegisterClass rc = FPR32>
215215
: FPFmtMEM<op, (outs), (ins rc:$fd, GPR:$rj, GPR:$rk),
216216
"$fd, $rj, $rk">;
217217
class FP_STORE_2RI12<bits<32> op, RegisterClass rc = FPR32>
218-
: FPFmt2RI12<op, (outs), (ins rc:$fd, GPR:$rj, simm12:$imm12),
218+
: FPFmt2RI12<op, (outs), (ins rc:$fd, GPR:$rj, simm12_addlike:$imm12),
219219
"$fd, $rj, $imm12">;
220220
} // hasSideEffects = 0, mayLoad = 0, mayStore = 1
221221

llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td

+2-2
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ class LASX2RI10_Load<bits<32> op, Operand ImmOpnd = simm10_lsl2>
186186
class LASX2RI11_Load<bits<32> op, Operand ImmOpnd = simm11_lsl1>
187187
: Fmt2RI11_XRI<op, (outs LASX256:$xd), (ins GPR:$rj, ImmOpnd:$imm11),
188188
"$xd, $rj, $imm11">;
189-
class LASX2RI12_Load<bits<32> op, Operand ImmOpnd = simm12>
189+
class LASX2RI12_Load<bits<32> op, Operand ImmOpnd = simm12_addlike>
190190
: Fmt2RI12_XRI<op, (outs LASX256:$xd), (ins GPR:$rj, ImmOpnd:$imm12),
191191
"$xd, $rj, $imm12">;
192-
class LASX2RI12_Store<bits<32> op, Operand ImmOpnd = simm12>
192+
class LASX2RI12_Store<bits<32> op, Operand ImmOpnd = simm12_addlike>
193193
: Fmt2RI12_XRI<op, (outs), (ins LASX256:$xd, GPR:$rj, ImmOpnd:$imm12),
194194
"$xd, $rj, $imm12">;
195195

llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td

+2-2
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,10 @@ class LSX2RI10_Load<bits<32> op, Operand ImmOpnd = simm10_lsl2>
374374
class LSX2RI11_Load<bits<32> op, Operand ImmOpnd = simm11_lsl1>
375375
: Fmt2RI11_VRI<op, (outs LSX128:$vd), (ins GPR:$rj, ImmOpnd:$imm11),
376376
"$vd, $rj, $imm11">;
377-
class LSX2RI12_Load<bits<32> op, Operand ImmOpnd = simm12>
377+
class LSX2RI12_Load<bits<32> op, Operand ImmOpnd = simm12_addlike>
378378
: Fmt2RI12_VRI<op, (outs LSX128:$vd), (ins GPR:$rj, ImmOpnd:$imm12),
379379
"$vd, $rj, $imm12">;
380-
class LSX2RI12_Store<bits<32> op, Operand ImmOpnd = simm12>
380+
class LSX2RI12_Store<bits<32> op, Operand ImmOpnd = simm12_addlike>
381381
: Fmt2RI12_VRI<op, (outs), (ins LSX128:$vd, GPR:$rj, ImmOpnd:$imm12),
382382
"$vd, $rj, $imm12">;
383383

llvm/test/MC/LoongArch/Relocations/relocations.s

+18-13
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
# RUN: llvm-mc --filetype=obj --triple=loongarch64 < %s \
44
# RUN: | llvm-readobj -r - | FileCheck --check-prefix=RELOC %s
55

6-
# RUN: not llvm-mc --triple=loongarch64 --defsym=FIXME=1 < %s 2>&1 \
7-
# RUN: | FileCheck --check-prefix=ERROR %s
8-
96
## Check prefixes:
107
## RELOC - Check the relocation in the object.
118
## FIXUP - Check the fixup on the instruction.
@@ -312,24 +309,32 @@ pcaddi $t1, %desc_pcrel_20(foo)
312309
# INSTR: pcaddi $t1, %desc_pcrel_20(foo)
313310
# FIXUP: fixup A - offset: 0, value: %desc_pcrel_20(foo), kind: FK_NONE
314311

315-
.ifdef FIXME
316-
317312
fld.s $ft1, $a0, %pc_lo12(foo)
318-
# ERROR: :[[#@LINE-1]]:18: error: immediate must be an integer in the range [-2048, 2047]
313+
# RELOC: R_LARCH_PCALA_LO12 foo 0x0
314+
# INSTR: fld.s $ft1, $a0, %pc_lo12(foo)
315+
# FIXUP: fixup A - offset: 0, value: %pc_lo12(foo), kind: FK_NONE
319316

320317
fst.d $ft1, $a0, %pc_lo12(foo)
321-
# ERROR: :[[#@LINE-1]]:18: error: immediate must be an integer in the range [-2048, 2047]
318+
# RELOC: R_LARCH_PCALA_LO12 foo 0x0
319+
# INSTR: fst.d $ft1, $a0, %pc_lo12(foo)
320+
# FIXUP: fixup A - offset: 0, value: %pc_lo12(foo), kind: FK_NONE
322321

323322
vld $vr9, $a0, %pc_lo12(foo)
324-
# ERROR: :[[#@LINE-1]]:16: error: immediate must be an integer in the range [-2048, 2047]
323+
# RELOC: R_LARCH_PCALA_LO12 foo 0x0
324+
# INSTR: vld $vr9, $a0, %pc_lo12(foo)
325+
# FIXUP: fixup A - offset: 0, value: %pc_lo12(foo), kind: FK_NONE
325326

326327
vst $vr9, $a0, %pc_lo12(foo)
327-
# ERROR: :[[#@LINE-1]]:16: error: immediate must be an integer in the range [-2048, 2047]
328+
# RELOC: R_LARCH_PCALA_LO12 foo 0x0
329+
# INSTR: vst $vr9, $a0, %pc_lo12(foo)
330+
# FIXUP: fixup A - offset: 0, value: %pc_lo12(foo), kind: FK_NONE
328331

329332
xvld $xr9, $a0, %pc_lo12(foo)
330-
# ERROR: :[[#@LINE-1]]:17: error: immediate must be an integer in the range [-2048, 2047]
333+
# RELOC: R_LARCH_PCALA_LO12 foo 0x0
334+
# INSTR: xvld $xr9, $a0, %pc_lo12(foo)
335+
# FIXUP: fixup A - offset: 0, value: %pc_lo12(foo), kind: FK_NONE
331336

332337
xvst $xr9, $a0, %pc_lo12(foo)
333-
# ERROR: :[[#@LINE-1]]:17: error: immediate must be an integer in the range [-2048, 2047]
334-
335-
.endif
338+
# RELOC: R_LARCH_PCALA_LO12 foo 0x0
339+
# INSTR: xvst $xr9, $a0, %pc_lo12(foo)
340+
# FIXUP: fixup A - offset: 0, value: %pc_lo12(foo), kind: FK_NONE

llvm/test/MC/LoongArch/lasx/invalid-imm.s

+6-6
Original file line numberDiff line numberDiff line change
@@ -1167,22 +1167,22 @@ xvldrepl.h $xr0, $a0, 2048
11671167

11681168
## simm12
11691169
xvldrepl.b $xr0, $a0, -2049
1170-
# CHECK: :[[#@LINE-1]]:23: error: immediate must be an integer in the range [-2048, 2047]
1170+
# CHECK: :[[#@LINE-1]]:23: error: operand must be a symbol with modifier (e.g. %pc_lo12) or an integer in the range [-2048, 2047]
11711171

11721172
xvldrepl.b $xr0, $a0, 2048
1173-
# CHECK: :[[#@LINE-1]]:23: error: immediate must be an integer in the range [-2048, 2047]
1173+
# CHECK: :[[#@LINE-1]]:23: error: operand must be a symbol with modifier (e.g. %pc_lo12) or an integer in the range [-2048, 2047]
11741174

11751175
xvst $xr0, $a0, -2049
1176-
# CHECK: :[[#@LINE-1]]:17: error: immediate must be an integer in the range [-2048, 2047]
1176+
# CHECK: :[[#@LINE-1]]:17: error: operand must be a symbol with modifier (e.g. %pc_lo12) or an integer in the range [-2048, 2047]
11771177

11781178
xvst $xr0, $a0, 2048
1179-
# CHECK: :[[#@LINE-1]]:17: error: immediate must be an integer in the range [-2048, 2047]
1179+
# CHECK: :[[#@LINE-1]]:17: error: operand must be a symbol with modifier (e.g. %pc_lo12) or an integer in the range [-2048, 2047]
11801180

11811181
xvld $xr0, $a0, -2049
1182-
# CHECK: :[[#@LINE-1]]:17: error: immediate must be an integer in the range [-2048, 2047]
1182+
# CHECK: :[[#@LINE-1]]:17: error: operand must be a symbol with modifier (e.g. %pc_lo12) or an integer in the range [-2048, 2047]
11831183

11841184
xvld $xr0, $a0, 2048
1185-
# CHECK: :[[#@LINE-1]]:17: error: immediate must be an integer in the range [-2048, 2047]
1185+
# CHECK: :[[#@LINE-1]]:17: error: operand must be a symbol with modifier (e.g. %pc_lo12) or an integer in the range [-2048, 2047]
11861186

11871187
## simm13
11881188
xvldi $xr0, -4097

llvm/test/MC/LoongArch/lsx/invalid-imm.s

+6-6
Original file line numberDiff line numberDiff line change
@@ -1167,22 +1167,22 @@ vldrepl.h $vr0, $a0, 2048
11671167

11681168
## simm12
11691169
vldrepl.b $vr0, $a0, -2049
1170-
# CHECK: :[[#@LINE-1]]:22: error: immediate must be an integer in the range [-2048, 2047]
1170+
# CHECK: :[[#@LINE-1]]:22: error: operand must be a symbol with modifier (e.g. %pc_lo12) or an integer in the range [-2048, 2047]
11711171

11721172
vldrepl.b $vr0, $a0, 2048
1173-
# CHECK: :[[#@LINE-1]]:22: error: immediate must be an integer in the range [-2048, 2047]
1173+
# CHECK: :[[#@LINE-1]]:22: error: operand must be a symbol with modifier (e.g. %pc_lo12) or an integer in the range [-2048, 2047]
11741174

11751175
vst $vr0, $a0, -2049
1176-
# CHECK: :[[#@LINE-1]]:16: error: immediate must be an integer in the range [-2048, 2047]
1176+
# CHECK: :[[#@LINE-1]]:16: error: operand must be a symbol with modifier (e.g. %pc_lo12) or an integer in the range [-2048, 2047]
11771177

11781178
vst $vr0, $a0, 2048
1179-
# CHECK: :[[#@LINE-1]]:16: error: immediate must be an integer in the range [-2048, 2047]
1179+
# CHECK: :[[#@LINE-1]]:16: error: operand must be a symbol with modifier (e.g. %pc_lo12) or an integer in the range [-2048, 2047]
11801180

11811181
vld $vr0, $a0, -2049
1182-
# CHECK: :[[#@LINE-1]]:16: error: immediate must be an integer in the range [-2048, 2047]
1182+
# CHECK: :[[#@LINE-1]]:16: error: operand must be a symbol with modifier (e.g. %pc_lo12) or an integer in the range [-2048, 2047]
11831183

11841184
vld $vr0, $a0, 2048
1185-
# CHECK: :[[#@LINE-1]]:16: error: immediate must be an integer in the range [-2048, 2047]
1185+
# CHECK: :[[#@LINE-1]]:16: error: operand must be a symbol with modifier (e.g. %pc_lo12) or an integer in the range [-2048, 2047]
11861186

11871187
## simm13
11881188
vldi $vr0, -4097

0 commit comments

Comments
 (0)