Clang’s -O0 output: branch displacement and size increase

# · ✸ 93 · 💬 13 · 11 days ago · maskray.me · todsacerdoti · 📷
Tl;dr Clang 19 will remove the -mrelax-all default at -O0, significantly decreasing the text section size for x86. A 1978 paper by Thomas G. Szymanski used the term "Span-dependent instructions" to refer to such instructions with short and long forms. Assemblers grapple with the challenge of choosing the optimal size for these instructions, often referred to as the "Branch displacement problem" since branches are the most common type. 12345678910111213 # -mrelax-allMCSectionMCDataFragment: emptyMCAlignFragment: alignment=4MCDataFragment: instructions including JE# -mno-relax-allMCSectionMCDataFragment: emptyMCAlignFragment: alignment=4MCDataFragment: instructions before JEMCRelaxableFragment: JE. This JE could be expanded, but not in this case. MCDataFragment: instructions after JE. The impact of -mrelax-all on text section size is significant, especially when there are many branch instructions. Text section size by 7.9%. This translates to a 5.4% increase in VM size and a 4.6% increase in the overall file size. Mrelax-all caused undesired interaction issues with RISC-V's conditional branch transforms, leading Craig Topper to remove -mrelax-all at -O0 for RISC-V recently.
Clang’s -O0 output: branch displacement and size increase



Send Feedback | WebAssembly Version (beta)