Skip to content

Commit c9c3edf

Browse files
committed
Fix Tests, Relaxation
1 parent a41bb06 commit c9c3edf

File tree

5 files changed

+16
-3
lines changed

5 files changed

+16
-3
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,11 @@ void RISCVMCCodeEmitter::expandLongCondBr(const MCInst &MI,
340340
// Drop any fixup added so we can add the correct one.
341341
Fixups.resize(FixupStartIndex);
342342

343-
if (SrcSymbol.isExpr())
343+
if (SrcSymbol.isExpr()) {
344344
addFixup(Fixups, Offset, SrcSymbol.getExpr(), RISCV::fixup_riscv_jal);
345+
if (STI.hasFeature(RISCV::FeatureRelax))
346+
Fixups.back().setLinkerRelaxable();
347+
}
345348
}
346349

347350
// Expand PseudoLongQC_(E_)Bxxx to an inverted conditional branch and an
@@ -388,8 +391,11 @@ void RISCVMCCodeEmitter::expandQCLongCondBrImm(const MCInst &MI,
388391
support::endian::write(CB, JBinary, llvm::endianness::little);
389392
// Drop any fixup added so we can add the correct one.
390393
Fixups.resize(FixupStartIndex);
391-
if (SrcSymbol.isExpr())
394+
if (SrcSymbol.isExpr()) {
392395
addFixup(Fixups, Offset, SrcSymbol.getExpr(), RISCV::fixup_riscv_jal);
396+
if (STI.hasFeature(RISCV::FeatureRelax))
397+
Fixups.back().setLinkerRelaxable();
398+
}
393399
}
394400

395401
void RISCVMCCodeEmitter::encodeInstruction(const MCInst &MI,

llvm/test/MC/RISCV/Relocations/expr.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ call relax
1414
jal zero, .LBB0+16
1515
# CHECK-INSTR: jal zero, 0x10
1616
# CHECK-RELOC: R_RISCV_JAL
17+
# CHECK-RELOC-NEXT: R_RISCV_RELAX
1718

1819
beq a0, a1, .LBB1+32
1920
# CHECK-INSTR: beq a0, a1, 0x20
@@ -31,4 +32,5 @@ c.beqz a0, .-2
3132

3233
call relax
3334
# CHECK-RELOC-NEXT: R_RISCV_CALL_PLT
35+
# CHECK-RELOC-NEXT: R_RISCV_RELAX
3436
.LBB2:

llvm/test/MC/RISCV/compressed-relocations.s

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+c < %s \
44
# RUN: | llvm-readobj -r - | FileCheck -check-prefix=RELOC %s
55
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+c,+relax < %s \
6-
# RUN: | llvm-readobj -r - | FileCheck -check-prefix=RELOC %s
6+
# RUN: | llvm-readobj -r - | FileCheck -check-prefixes=RELOC,RELAX %s
77

88
# Check prefixes:
99
# RELOC - Check the relocation in the object.
1010
# INSTR - Check the instruction is handled properly by the ASMPrinter
1111
c.jal foo
1212
# A compressed jump (c.j) to an unresolved symbol will be relaxed to a (jal).
1313
# RELOC: R_RISCV_JAL
14+
# RELAX-NEXT: R_RISCV_RELAX
1415
# INSTR: c.jal foo
1516

1617
c.bnez a0, foo
1718
# A compressed branch (c.bnez) to an unresolved symbol will be relaxed to a (bnez).
1819
# The (bnez) to an unresolved symbol will in turn be relaxed to (beqz; jal)
1920
# RELOC-NEXT: R_RISCV_JAL
21+
# RELAX-NEXT: R_RISCV_RELAX
2022
# INSTR: c.bnez a0, foo

llvm/test/MC/RISCV/option-relax.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ call bar
3939

4040
.dword .L2-.L1
4141
# CHECK-RELOC-NEXT: R_RISCV_JAL
42+
# CHECK-RELOC-NEXT: R_RISCV_RELAX
4243
jal zero, .L1
4344
# CHECK-RELOC-NEXT: R_RISCV_BRANCH
4445
beq s1, s1, .L1

llvm/test/MC/RISCV/xqcibi-relocations.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,14 @@ qc.e.bgeui s2, 24, same_section
9191
# OBJ: qc.beqi t1, 0xa, 0x42 <same_section_extern+0x16>
9292
# OBJ-NEXT: j 0x3e <same_section_extern+0x12>
9393
# OBJ-NEXT: R_RISCV_JAL undef{{$}}
94+
# OBJ-NEXT: R_RISCV_RELAX *ABS*{{$}}
9495
qc.bnei t1, 10, undef
9596

9697
# ASM: qc.e.bgeui s0, 40, undef
9798
# OBJ-NEXT: qc.e.bltui s0, 0x28, 0x4c <same_section_extern+0x20>
9899
# OBJ-NEXT: j 0x48 <same_section_extern+0x1c>
99100
# OBJ-NEXT: R_RISCV_JAL undef{{$}}
101+
# OBJ-NEXT: R_RISCV_RELAX *ABS*{{$}}
100102
qc.e.bgeui s0, 40, undef
101103

102104
.section .text.second, "ax", @progbits

0 commit comments

Comments
 (0)