This patch is improved version of patch https://reviews.llvm.org/D113291 submitted by @djtodoro
Credit goes to @djtodoro for his submission.
I have added fix in AArch64 backend and I have followed an approach suggested by @craig.topper here -
https://github.com/llvm/llvm-project/issues/45779#issuecomment-1022851172
It generates below assembly -
rbit w8, w0 clz w8, w8 and w0, w8, #0x1f ret
which is similar assembly emitted by GCC AArch64 - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90838
Patch fixes - https://github.com/llvm/llvm-project/issues/45779
clang-format: please reformat the code