[clang] [llvm] [Transforms] Implement always_specialize attribute lowering (PR #143983)

Jon Chesterfield via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 13 09:25:48 PDT 2025


JonChesterfield wrote:

A user perspective is useful here, thanks for stopping by! The docs might be too concise. There's a nice example in the discourse thread,

```
void qsort( void* ptr, size_t count,
   size_t __attribute__((always_specialize)) size,
   int (* __attribute__((always_specialize)) comp)(const void*, const void*) ) {...}
```

Calls to that with constant values for size and/or the comparison will then hit this transform, including at O0.

1. Builds static copies of the function specialised to the constant arguments with that attribute
2. Changes calls to point to the specialisations.

I'll add a recursive sort to the clang test suite, since replacing the function pointer with a direct call without unrolling the recursion is a nice example of this doing something that inlining struggles with. Thanks!

https://github.com/llvm/llvm-project/pull/143983


More information about the llvm-commits mailing list