[all-commits] [llvm/llvm-project] debb25: [MC] Fuse relaxation and layout into a single forw...

Fangrui Song via All-commits all-commits at lists.llvm.org
Tue Mar 3 22:39:47 PST 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: debb2514ea7f062a29e5e4740f9d6ee4cea3b978
      https://github.com/llvm/llvm-project/commit/debb2514ea7f062a29e5e4740f9d6ee4cea3b978
  Author: Fangrui Song <i at maskray.me>
  Date:   2026-03-04 (Wed, 04 Mar 2026)

  Changed paths:
    M llvm/include/llvm/MC/MCAssembler.h
    M llvm/lib/MC/MCAssembler.cpp
    M llvm/test/MC/ELF/relax-branch-align.s
    A llvm/test/MC/X86/align-branch-convergence.s

  Log Message:
  -----------
  [MC] Fuse relaxation and layout into a single forward pass (#184544)

Replace the two-pass inner loop in relaxOnce (relaxFragment +
layoutSection) with a single forward pass that sets each fragment's
offset before processing it.

- Extract relaxAlign from layoutSection's FT_Align handling and call
  it from relaxFragment. FT_Align padding is computed inline with the
  tracked Offset, so alignment fragments always see fresh upstream
  offsets. This structurally eliminates the O(N) convergence pitfall
  where stale offsets caused each iteration to fix only one more
  alignment fragment.

- The new MCAssembler::Stretch field tracks the cumulative upstream size
  delta. In evaluateFixup, for PCRel fixups during relaxation, Stretch
  is added to forward-reference target values (LayoutOrder comparison).
  This makes displacement = target_old - source_old, identical to the
  old two-pass approach, preventing premature relaxation for
  span-dependent instructions.

- FT_Fill/FT_Org removed from relaxFragment; `if (F.Offset != Offset) in
  the fused loop detects their size changes.

- layoutSection is retained for initial layout and post-finishLayout.

This fixes the FT_BoundaryAlign linear time convergence issue reported
by #176535. In addition, backward branches near the short/near boundary
may benefit from tighter encoding when a .p2align between the target and
the branch absorbs upstream growth (see relax-branch-align.s).

Key commits that updated relaxFragment/layoutSection:
- 742ecfc13e8a [MC] Relax MCFillFragment and compute fragment offsets
eagerly
- 9f66ebe42715 MC: Eliminate redundant fragment relaxation
- df71243fa885 MC: Evaluate .org during fragment relaxation
- b1d58f025e83 MCAssembler: Simplify fragment relaxation
- 58d16db8b5d2 MCAssembler: Simplify relaxation of FT_Fill and FT_Org



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