[all-commits] [llvm/llvm-project] 82ada7: [clang] Optimize EmbedExpr child iterator callback...

Timm Baeder via All-commits all-commits at lists.llvm.org
Thu Aug 28 07:46:31 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 82ada737b1cd05d69f15283415691e8411c0789a
      https://github.com/llvm/llvm-project/commit/82ada737b1cd05d69f15283415691e8411c0789a
  Author: Timm Baeder <tbaeder at redhat.com>
  Date:   2025-08-28 (Thu, 28 Aug 2025)

  Changed paths:
    M clang/include/clang/AST/APNumericStorage.h
    M clang/include/clang/AST/Expr.h
    M clang/lib/AST/Expr.cpp
    M clang/lib/Serialization/ASTWriterStmt.cpp

  Log Message:
  -----------
  [clang] Optimize EmbedExpr child iterator callback (#155803)

Instead of querying the bitwidth and signeness of the integer literal
for every iteration, get the bitwidth directly from the `APIntStorage`
and assume the signeness to be `true` since we set the type of the
`EmbedExpr` to `Ctx.IntTy` and the type of the integer literal to that
of the `EmbedExpr`, so it should always be signed, as long as
`ASTContext::IntTy` is signed.

Before:
```
$ hyperfine -r 50 -w 3 'bin/clang -c ../../benchmarks/embed.cpp -std=c++20 -fconstexpr-steps=1000000000'
Benchmark 1: bin/clang -c ../../benchmarks/embed.cpp -std=c++20 -fconstexpr-steps=1000000000
  Time (mean ± σ):      1.796 s ±  0.090 s    [User: 0.961 s, System: 0.834 s]
  Range (min … max):    1.640 s …  2.150 s    50 runs
```
After:
```
$ hyperfine -r 50 -w 3 'bin/clang -c ../../benchmarks/embed.cpp -std=c++20 -fconstexpr-steps=1000000000'
Benchmark 1: bin/clang -c ../../benchmarks/embed.cpp -std=c++20 -fconstexpr-steps=1000000000
  Time (mean ± σ):      1.700 s ±  0.050 s    [User: 0.909 s, System: 0.789 s]
  Range (min … max):    1.637 s …  1.880 s    50 runs
```

That is roughly .1s less, or whatever, 5% or something.

The benchmark is simply:
```c++
constexpr char str[] = {
#embed "sqlite3.c" suffix(,0)
};

constexpr char str2[] = {
#embed "sqlite3.c" suffix(,0)
};

constexpr char str3[] = {
#embed "sqlite3.c" suffix(,0)
};
```
where `sqlite3.c` contains the sqlite3 amalgamation (roughly 9 million
characters).



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