[PATCH] D154958: [RISCV][MC] Relax conditional branches to unresolved symbols

Job Noorman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 11 06:21:50 PDT 2023


jobnoorman created this revision.
jobnoorman added reviewers: asb, jrtc27, craig.topper, kito-cheng, MaskRay, reames.
Herald added subscribers: luke, pmatos, VincentWu, vkmr, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
jobnoorman requested review of this revision.
Herald added subscribers: llvm-commits, wangpc, eopXD.
Herald added a project: LLVM.

D108961 <https://reviews.llvm.org/D108961> introduced relaxation for out-of-range conditional branches.
However, relaxation was only performed when the branch target could be
resolved. I believe this has two undesired consequences:

- `b<cc> ... foo`, where `foo` is undefined, would not be relaxed although there is no guarantee the offset to `foo` will fit;
- Conditional branches are never relaxed with `-mattr=+relax` because MC considers fixups where `shouldForceRelocation` returns true (which will be the case with `+relax`) to be unresolved.

Note that binutils performs conditional branch relaxation in both cases.

This patch proposes to perform conditional branch relaxation even when
the target cannot be resolved.

Note on llvm/test/MC/RISCV/long-conditional-jump.s: I've removed the
`.p2align` because this causes alignment nops to be inserted for the
`+relax` tests. This in turn causes all the branch targets to change
compared to the non-`+relax` tests. Since `+relax` shouldn't change
these offsets, I found this confusing and hence chose to remove the
alignment.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154958

Files:
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
  llvm/test/MC/RISCV/compressed-relocations.s
  llvm/test/MC/RISCV/long-conditional-jump.s
  llvm/test/MC/RISCV/relocations.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154958.539057.patch
Type: text/x-patch
Size: 7970 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230711/5615425e/attachment.bin>


More information about the llvm-commits mailing list