Skip to content

Commit 5f449b9

Browse files
committed
[RISCV] Allow RISCVMCExpr folding in the absence of linker relaxaxation
In the AArch64 target, `bar: add x0, x0, :lo12:foo-bar; foo:` can be folded. Remove the restriction (https://reviews.llvm.org/D104473), which became unnecessary after https://reviews.llvm.org/D155357
1 parent 56b05a0 commit 5f449b9

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,7 @@ const MCFixup *RISCVMCExpr::getPCRelHiFixup(const MCFragment **DFOut) const {
9191
bool RISCVMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
9292
const MCAssembler *Asm,
9393
const MCFixup *Fixup) const {
94-
// Explicitly drop the layout and assembler to prevent any symbolic folding in
95-
// the expression handling. This is required to preserve symbolic difference
96-
// expressions to emit the paired relocations.
97-
if (!getSubExpr()->evaluateAsRelocatable(Res, nullptr, nullptr))
94+
if (!getSubExpr()->evaluateAsRelocatable(Res, Asm, Fixup))
9895
return false;
9996

10097
Res =

llvm/test/MC/RISCV/hilo-constaddr-expr.s

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
# RUN: not llvm-mc -filetype=obj -triple=riscv32 -mattr=+relax %s -o /dev/null 2>&1 | FileCheck %s
2-
# RUN: not llvm-mc -filetype=obj -triple=riscv32 -mattr=-relax %s -o /dev/null 2>&1 | FileCheck %s
2+
# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=-relax %s | llvm-objdump -d - | FileCheck %s --check-prefix=NORELAX
33

44
# Check the assembler rejects hi and lo expressions with constant expressions
55
# involving labels when diff expressions are emitted as relocation pairs.
66
# Test case derived from test/MC/Mips/hilo-addressing.s
77

8+
# NORELAX: lui t0, 0x0
9+
# NORELAX-NEXT: lw ra, 0x8(t0)
10+
# NORELAX: lui t1, 0x0
11+
# NORELAX-NEXT: lw sp, -0x8(t1)
12+
813
tmp1:
914
tmp2:
1015
# CHECK: :[[#@LINE+1]]:[[#]]: error: expected relocatable expression

0 commit comments

Comments
 (0)