A few options:
- Make them a builtin, have libc implementations forward to the builtin.
- Teach clang / LLVM about these function’s semantics (i.e. if conditions met, same as memset).
I think 1. is the best approach.
Could you expand on why 1 looks better than 2?
There’s a lot of code that can be handled via clang builtin or via pattern matching IR pass. All of libm for example. Some functions have both styles, some even get converted from clang builtin to libm call to llvm intrinsic.
I’m in favour of recognising function calls and translating them to IR intrinsics. This simplifies testing (via opt). It moves an optimisation out of clang and into an IR pass which feels right. It also means &sin works, though I know this to be forbidden.
As such I’m interested in your preference for doing this in clang, and whether it generalises to other magic library functions.