[all-commits] [llvm/llvm-project] bb03cd: RISCV: Remove shouldForceRelocation and unneeded r...
Fangrui Song via All-commits
all-commits at lists.llvm.org
Fri May 23 18:44:36 PDT 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: bb03cdcb441fd68da9d1ebb7d5f39f73667cd39c
https://github.com/llvm/llvm-project/commit/bb03cdcb441fd68da9d1ebb7d5f39f73667cd39c
Author: Fangrui Song <i at maskray.me>
Date: 2025-05-23 (Fri, 23 May 2025)
Changed paths:
M bolt/test/RISCV/reloc-label-diff.s
M bolt/test/RISCV/reorder-blocks-reverse.s
M llvm/include/llvm/MC/MCAssembler.h
M llvm/include/llvm/MC/MCFixup.h
M llvm/include/llvm/MC/MCSection.h
M llvm/lib/MC/MCAssembler.cpp
M llvm/lib/MC/MCELFStreamer.cpp
M llvm/lib/MC/MCExpr.cpp
M llvm/lib/MC/MCSection.cpp
M llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
M llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCCodeEmitter.cpp
M llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
M llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
M llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h
M llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
M llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp
M llvm/test/CodeGen/RISCV/option-relax-relocation.ll
M llvm/test/MC/RISCV/fixups-binary-expression.s
M llvm/test/MC/RISCV/linker-relaxation.s
M llvm/test/MC/RISCV/long-conditional-jump.s
M llvm/test/MC/RISCV/option-relax.s
M llvm/test/MC/RISCV/xqcibi-long-conditional-jump.s
Log Message:
-----------
RISCV: Remove shouldForceRelocation and unneeded relocations
Follow-up to #140494
`shouldForceRelocation` is conservative and produces redundant
relocations.
For example, RISCVAsmBackend::ForceRelocs (introduced to support mixed
relax/norelax code) leads to redundant relocations in the following
example adapted from #77436
```
.option norelax
j label
// For assembly input, RISCVAsmParser::ParseInstruction sets ForceRelocs (https://reviews.llvm.org/D46423).
// For direct object emission, RISCVELFStreamer sets ForceRelocs (#77436)
.option relax
call foo // linker-relaxable
.option norelax
j label // redundant relocation due to ForceRelocs
.option relax
label:
```
Root problem: The `isSymbolRefDifferenceFullyResolvedImpl` condition in
MCAssembler::evaluateFixup does not check whether two locations are
separated by a fragment whose size can be indeterminate due to linker
instruction (e.g. MCDataFragment with relaxation, or MCAlignFragment
due to indeterminate start offst).
This patch
* Updates the fragment walk code in
`attemptToFoldSymbolOffsetDifference` to treat MCRelaxableFragment
(for --riscv-asm-relax-branches) as fixed size after finishLayout.
* Adds a condition in `addReloc` to complement
`isSymbolRefDifferenceFullyResolvedImpl`.
* Removes the no longer needed `shouldForceRelocation`.
This fragment walk code path handles nicely handles
mixed relax/norelax case from
https://discourse.llvm.org/t/possible-problem-related-to-subtarget-usage/75283
and allows us to remove `MCSubtargetInfo` argument (#73721) as a follow-up.
This fragment walk code should be avoided in the absence of
linker-relaxable fragments within the current section.
Adjust two bolt/test/RISCV tests (#141310)
Pull Request: https://github.com/llvm/llvm-project/pull/140692
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