Skip to content

Commit 69b4c06

Browse files
lenaryaokblast
authored andcommitted
[RISCV] fixup_riscv_rvc_imm may be linker relaxable (llvm#161797)
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 e7f95b9 commit 69b4c06

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# RUN: llvm-mc --triple=riscv32 -mattr=+relax,+experimental-xqcili \
2+
# RUN: %s -filetype=obj -o - -riscv-add-build-attributes \
3+
# RUN: | llvm-objdump -dr -M no-aliases - \
4+
# RUN: | FileCheck %s
5+
6+
## This tests that we correctly emit relocations for linker relaxation when
7+
## emitting `QC.E.LI` and `QC.LI`.
8+
9+
.section .text.ex1, "ax", @progbits
10+
# CHECK-LABEL: <.text.ex1>:
11+
blez a1, .L1
12+
# CHECK-NEXT: bge zero, a1, 0x0 <.text.ex1>
13+
# CHECK-NEXT: R_RISCV_BRANCH .L1{{$}}
14+
qc.e.li a0, sym
15+
# CHECK-NEXT: qc.e.li a0, 0x0
16+
# CHECK-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
17+
# CHECK-NEXT: R_RISCV_CUSTOM194 sym{{$}}
18+
# CHECK-NEXT: R_RISCV_RELAX *ABS*{{$}}
19+
.L1:
20+
# CHECK: <.L1>:
21+
ret
22+
# CHECK-NEXT: c.jr ra
23+
24+
.section .text.ex2, "ax", @progbits
25+
# CHECK-LABEL: <.text.ex2>:
26+
blez a1, .L2
27+
# CHECK-NEXT: bge zero, a1, 0x0 <.text.ex2>
28+
# CHECK-NEXT: R_RISCV_BRANCH .L2{{$}}
29+
qc.li a0, %qc.abs20(sym)
30+
# CHECK-NEXT: qc.li a0, 0x0
31+
# CHECK-NEXT: R_RISCV_VENDOR QUALCOMM{{$}}
32+
# CHECK-NEXT: R_RISCV_CUSTOM192 sym{{$}}
33+
# CHECK-NEXT: R_RISCV_RELAX *ABS*{{$}}
34+
.L2:
35+
# CHECK: <.L2>:
36+
ret
37+
# CHECK-NEXT: c.jr ra

0 commit comments

Comments
 (0)