[llvm] [MC] Fix quadratic runtime within alignment boundary fragment relaxation (PR #176535)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 21 20:07:25 PST 2026
MaskRay wrote:
> Thanks for taking a look so quickly. I agree it's not the nicest fix. When you say it becomes less relevant, is there another alternative to achieve this kind of alignment for branch instructions? Or do you have anything in mind in which direction this code should be taken?
Some work could be done at `X86AsmBackend::finishLayout` instead. I haven't dived deep into it yet.
---
This is not related to spectre/meltdown mitigation. It's a 2020 assembler workaround for
Intel's Jump Conditional Code Erratum, than repurposed to implement a prefix padding optimization (with some issues; disabled by default).
The history is like:
* `-mbranches-within-32B-boundaries`. See [Align branches within 32-Byte boundary(NOP padding)](https://reviews.llvm.org/D70157)
* [[X86] Relax existing instructions to reduce the number of nops needed for alignment purposes](https://reviews.llvm.org/D75203)
* ["Enhanced relaxation"](https://reviews.llvm.org/D76286): The feature allows x86 prefix padding for all instructions, effectively making all instructions span-dependent and requiring its own fragment.
My [D94542](https://reviews.llvm.org/D94542) disabled this by default due to concern of `-g` vs `-g0` differences.
The last comment in D94542 mentioned that there was some issues. Nobody has analyzed it.
Thanks for the additional context, but I hope you can elaborate on the BOLT and JIT use cases.
https://discourse.llvm.org/t/rfc-lightweight-fault-isolation-lfi-efficient-native-code-sandboxing-upstream-lfi-target-and-compiler-changes/88380 also describes a use case requiring some alignment dance.
Given these parallels, we should carefully review our overall direction.
https://github.com/llvm/llvm-project/pull/176535
More information about the llvm-commits
mailing list