[all-commits] [llvm/llvm-project] d98c6b: BOLT may never run the tentative code layout for c...

Paschalis Mpeis via All-commits all-commits at lists.llvm.org
Tue Jun 25 02:06:28 PDT 2024


  Branch: refs/heads/users/paschalis-mpeis/lite-split-functions-cold-layout
  Home:   https://github.com/llvm/llvm-project
  Commit: d98c6b973fbde67274584620172d91a6233110c1
      https://github.com/llvm/llvm-project/commit/d98c6b973fbde67274584620172d91a6233110c1
  Author: Paschalis Mpeis <Paschalis.Mpeis at arm.com>
  Date:   2024-06-25 (Tue, 25 Jun 2024)

  Changed paths:
    M bolt/lib/Passes/LongJmp.cpp
    A bolt/test/AArch64/split-funcs-lite.test

  Log Message:
  -----------
  BOLT may never run the tentative code layout for cold BBs.

However, it might later require the addresses of cold BBs to compute
PC-relative jumps between hot and cold fragments of a function. Since
the addresses were never estimated, it uses 0x0 for cold BBs, resulting
in incorrect estimated addresses for any instructions within them.

As a result, LongJump often expands a branch that would otherwise fit in
a single instruction into a short jump.

For example, `relaxStub` might expand from:
```armasm
b       .Ltmp1234
```

to:
```armasm
adrp    x16, .Ltmp1234
add     x16, x16, :lo12:.Ltmp1234
br      x16
```

While this expansion is not wrong, it is unnecessary. Moreover, in some
large binaries this expansion has lead to runtime crashes. This should
be investigated further, as such expansions should not cause crashes.


  Commit: 7cd7950ee0825e1187c4d8b7d20aeef647809039
      https://github.com/llvm/llvm-project/commit/7cd7950ee0825e1187c4d8b7d20aeef647809039
  Author: Paschalis Mpeis <Paschalis.Mpeis at arm.com>
  Date:   2024-06-25 (Tue, 25 Jun 2024)

  Changed paths:
    M bolt/lib/Passes/LongJmp.cpp
    M bolt/test/AArch64/split-funcs-lite.test

  Log Message:
  -----------
  [AArch64][BOLT] Ensure tentative code layout for cold BBs runs.

When BOLT is not processing all functions (e.g., when lite mode is
enabled or when multiple functions are ignored via the 'skip-funcs' flag),
we might skip the tentative code layout estimation for cold basic blocks.
However, due to the `-split-functions`` flag, we still need to compute
PC-relative distances between hot and cold basic blocks.

In such cases, BOLT will use '0x0' as the first address of the basic
block, leading to incorrect estimations of the necessary PC-relative
addresses. Consequently, the relaxStub method expands all those branches
to the short-jump sequence unnecessarily.

Such an unnecessary expansion by `relaxStub` is from:
```armasm
b       .Ltmp1234
```

to:
```armasm
adrp    x16, .Ltmp1234
add     x16, x16, :lo12:.Ltmp1234
br      x16
```


Compare: https://github.com/llvm/llvm-project/compare/d98c6b973fbd%5E...7cd7950ee082

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