Skip to content

release/19.x: [RISCV] Don't delete all fixups in RISCVMCCodeEmitter::expandLongCondBr. (#109513) #114089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,18 @@ void RISCVMCCodeEmitter::expandLongCondBr(const MCInst &MI,
Offset = 4;
}

// Save the number fixups.
size_t FixupStartIndex = Fixups.size();

// Emit an unconditional jump to the destination.
MCInst TmpInst =
MCInstBuilder(RISCV::JAL).addReg(RISCV::X0).addOperand(SrcSymbol);
uint32_t Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI);
support::endian::write(CB, Binary, llvm::endianness::little);

Fixups.clear();
// Drop any fixup added so we can add the correct one.
Fixups.resize(FixupStartIndex);

if (SrcSymbol.isExpr()) {
Fixups.push_back(MCFixup::create(Offset, SrcSymbol.getExpr(),
MCFixupKind(RISCV::fixup_riscv_jal),
Expand Down
6 changes: 6 additions & 0 deletions llvm/test/MC/RISCV/rv64-relax-all.s
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ c.beqz a0, NEAR
# INSTR: c.j 0x0 <NEAR>
# RELAX-INSTR: jal zero, 0x0 <NEAR>
c.j NEAR

bnez s0, .foo
j .foo
beqz s0, .foo
.foo:
ret
Loading