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

Paschalis Mpeis via All-commits all-commits at lists.llvm.org
Wed Oct 2 02:56:54 PDT 2024


  Branch: refs/heads/users/paschalis-mpeis/lite-split-functions-cold-layout
  Home:   https://github.com/llvm/llvm-project
  Commit: 0df1465d9a00d1e6c1b640eea340e07b06b7081a
      https://github.com/llvm/llvm-project/commit/0df1465d9a00d1e6c1b640eea340e07b06b7081a
  Author: Paschalis Mpeis <Paschalis.Mpeis at arm.com>
  Date:   2024-10-02 (Wed, 02 Oct 2024)

  Changed paths:
    M bolt/lib/Passes/LongJmp.cpp
    A bolt/test/AArch64/split-funcs-lite.s
    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: 683beaa612495ef17900b2ac4f43f743415b760a
      https://github.com/llvm/llvm-project/commit/683beaa612495ef17900b2ac4f43f743415b760a
  Author: Paschalis Mpeis <Paschalis.Mpeis at arm.com>
  Date:   2024-10-02 (Wed, 02 Oct 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 split functions is used, BOLT may skip tentative code layout
estimation in some cases, like:
- when there is no profile data for some blocks (ie cold blocks)
- when there are cold functions in lite mode
- when skip functions is used

However, when rewriting the binary we still need to compute PC-relative
distances between hot and cold basic blocks. Without cold layout
estimation, BOLT uses '0x0' as the address of the first cold block,
leading to incorrect estimations of any PC-relative addresses.

This affects large binaries as the relaxStub method expands more
branches than necessary using the short-jump sequence, at it wrongly
believes it has exceeded the branch distance boundary.

This increases code size with a larger and slower sequence; however,
performance regression is expected to be minimal since this only affects
called cold code.

Example of such an unnecessary relaxation:
from:
```armasm
b       .Ltmp1234
```

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


  Commit: 8cc07ed1d76dd2609ea62af3a2ab76b8ca234774
      https://github.com/llvm/llvm-project/commit/8cc07ed1d76dd2609ea62af3a2ab76b8ca234774
  Author: Paschalis Mpeis <Paschalis.Mpeis at arm.com>
  Date:   2024-10-02 (Wed, 02 Oct 2024)

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

  Log Message:
  -----------
  Addressing reviewers.


  Commit: 104f14bb309e38af9931f6ebc34cd764e457a997
      https://github.com/llvm/llvm-project/commit/104f14bb309e38af9931f6ebc34cd764e457a997
  Author: Paschalis Mpeis <Paschalis.Mpeis at arm.com>
  Date:   2024-10-02 (Wed, 02 Oct 2024)

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

  Log Message:
  -----------
  Addressing reviewers - 02


Compare: https://github.com/llvm/llvm-project/compare/690d4857e8d9...104f14bb309e

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