If the compiler supports __builtin_bit_cast we should try to use it instead of std::memcpy (and avoid including the cstring header).
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
If the compiler supports __builtin_bit_cast we should try to use it instead of std::memcpy (and avoid including the cstring header).
Why? Maintaining non-portable code has some cost, if we can get similar/sufficient/the same performance without special casing, that seems better. Do we not get adequate performance with std::memcpy? Is the header especially expensive to include?
Half a point is that __builtin_bit_cast can be used in constant expressions. "Half", because llvm::bit_cast is not constexpr :)
This was part of a general attempt to get our bit.h as close to c++ <bit> as possible - especially when I realised that all latest supported compilers already implement '__builtin_bit_cast' : https://godbolt.org/z/YWM4GcceE
I'd say unless there's some significant gain - maintaining #ifdef'd non-portable(to all supported compilers) codepaths isn't worth the maintenance burden. But I don't feel strongly enough to insist on a revert - up to you.
Hey @RKSimon, it seems this patch is cause lldb's macOS ASAN bot to fail. Could you take a look ?
/Users/buildslave/jenkins/workspace/lldb-cmake-sanitized/llvm-project/llvm/include/llvm/ADT/bit.h:55:3: error: non-void function 'bit_cast' should return a value [-Wreturn-type] return __builtin_bit_cast(To, from); ^
https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake-sanitized/3475/console