[all-commits] [llvm/llvm-project] b9b39d: RISCVAsmParser: Don't treat operands with relocati...
Fangrui Song via All-commits
all-commits at lists.llvm.org
Sat Mar 29 11:13:01 PDT 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: b9b39db5d7677710f1d00dc8ff5844ad2abb269f
https://github.com/llvm/llvm-project/commit/b9b39db5d7677710f1d00dc8ff5844ad2abb269f
Author: Fangrui Song <i at maskray.me>
Date: 2025-03-29 (Sat, 29 Mar 2025)
Changed paths:
M llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
M llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp
M llvm/test/MC/RISCV/insn.s
M llvm/test/MC/RISCV/linker-relaxation.s
M llvm/test/MC/RISCV/rv32i-aliases-valid.s
M llvm/test/MC/RISCV/rv64i-aliases-valid.s
M llvm/test/MC/RISCV/rv64i-valid.s
M llvm/test/MC/RISCV/rvd-valid.s
M llvm/test/MC/RISCV/rvf-valid.s
M llvm/test/MC/RISCV/rvi-valid.s
M llvm/test/MC/RISCV/rvzfbfmin-valid.s
M llvm/test/MC/RISCV/rvzfh-valid.s
M llvm/test/MC/RISCV/rvzfhmin-valid.s
Log Message:
-----------
RISCVAsmParser: Don't treat operands with relocation specifier as parse-time constants
An immediate operand is encoded as an `MCExpr`, with `RISCVMCExpr`
specifying an operand that includes a relocation specifier. When
https://reviews.llvm.org/D23568 added initial fixup and relocation
support in 2017, it adapted code from `PPCMCExpr` (for `@l` `@ha`) to
evaluate the `RISCVMCExpr` operand. (PPCAsmParser had considerable
technical debt, though I’ve recently streamlined it somewhat, e.g.
8560da28c69de481f3ad147722577e87b902facb)
Evaluating RISCVMCExpr during parsing is unnecessary. For example,
there's no need to treat `lui a0, %hi(2)` differently from `lui a0,
%hi(foo)` when foo has not been defined yet.
This evaluation introduces unnecessary complexity. For instance, parser
functions require an extra check like `VK == RISCVMCExpr::VK_None`, as
seen in these examples:
```
if (!evaluateConstantImm(getImm(), Imm, VK) || VK != RISCVMCExpr::VK_None)
return IsConstantImm && isUInt<N>(Imm) && VK == RISCVMCExpr::VK_None;
```
This PR eliminates the parse-time evaluation of `RISCVMCExpr`, aligning
it more closely with other targets.
---
`abs = 0x12345; lui t3, %hi(abs)` now generates
R_RISCV_HI20/R_RISCV_RELAX with linker relaxation.
(Tested by test/MC/RISCV/linker-relaxation.s)
(Notably, since commit ba2de8f22d0cac86d89c1806fb54ed3463349342 in
lld/ELF, the linker can handle R_RISCV_HI relocations with a symbol
index of 0 in -pie mode.)
Pull Request: https://github.com/llvm/llvm-project/pull/133377
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list