Skip to content

Commit 446a427

Browse files
committed
[RISCV] fixup_riscv_rvc_imm may be linker relaxable
With Xqcili, `c.li` may be relaxed to `qc.e.li` (this is because `qc.e.li` is compressed into `c.li`, which needs to be undone). `qc.e.li` is relaxable, so we need to mark `c.li` as linker relaxable when it is emitted. This fixup cannot be emitted as a relocation, but we still mark it as requiring no R_RISCV_RELAX in case this changes in the future.
1 parent c64d4ce commit 446a427

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ static bool relaxableFixupNeedsRelocation(const MCFixupKind Kind) {
823823
break;
824824
case RISCV::fixup_riscv_rvc_jump:
825825
case RISCV::fixup_riscv_rvc_branch:
826+
case RISCV::fixup_riscv_rvc_imm:
826827
case RISCV::fixup_riscv_jal:
827828
return false;
828829
}

llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ uint64_t RISCVMCCodeEmitter::getImmOpValue(const MCInst &MI, unsigned OpNo,
688688
// the `jal` again in the assembler.
689689
} else if (MIFrm == RISCVII::InstFormatCI) {
690690
FixupKind = RISCV::fixup_riscv_rvc_imm;
691+
AsmRelaxToLinkerRelaxableWithFeature(RISCV::FeatureVendorXqcili);
691692
} else if (MIFrm == RISCVII::InstFormatI) {
692693
FixupKind = RISCV::fixup_riscv_12_i;
693694
} else if (MIFrm == RISCVII::InstFormatQC_EB) {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
# RUN: llvm-mc --triple=riscv32 -mattr=+relax,+experimental-xqcili \
3+
# RUN: %s -filetype=obj -o - -riscv-add-build-attributes \
4+
# RUN: | llvm-objdump -dr -M no-aliases - \
5+
# RUN: | FileCheck %s
6+
7+
## This tests that we correctly emit relocations for linker relaxation when
8+
## emitting `QC.E.LI` and `QC.LI`.
9+
10+
.section .text.ex1, "ax", @progbits
11+
.global ex1
12+
ex1:
13+
# CHECK-LABEL: <ex1>:
14+
blez a1, .L1
15+
# CHECK-NEXT: bge zero, a1, 0x0 <ex1>
16+
# CHECK-NEXT: R_RISCV_BRANCH .L1{{$}}
17+
qc.e.li a0, sym
18+
# CHECK-NEXT: qc.e.li a0, 0x0
19+
# CHECK-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
20+
# CHECK-NEXT: R_RISCV_CUSTOM194 sym{{$}}
21+
# CHECK-NEXT: R_RISCV_RELAX *ABS*{{$}}
22+
.L1:
23+
# CHECK: <.L1>:
24+
ret
25+
# CHECK-NEXT: c.jr ra
26+
27+
28+
.section .text.ex2, "ax", @progbits
29+
.global ex2
30+
ex2:
31+
# CHECK-LABEL: <ex2>:
32+
blez a1, .L2
33+
# CHECK-NEXT: bge zero, a1, 0x0 <ex2>
34+
# CHECK-NEXT: R_RISCV_BRANCH .L2{{$}}
35+
qc.li a0, %qc.abs20(sym)
36+
# CHECK-NEXT: qc.li a0, 0x0
37+
# CHECK-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
38+
# CHECK-NEXT: R_RISCV_CUSTOM192 sym{{$}}
39+
# CHECK-NEXT: R_RISCV_RELAX *ABS*{{$}}
40+
.L2:
41+
# CHECK: <.L2>:
42+
ret
43+
# CHECK-NEXT: c.jr ra

0 commit comments

Comments
 (0)