[PATCH] D107240: [LLVM][Support][NFC] Make multiple bitwise MathExtras functions constexpr
Alf via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 7 09:35:20 PDT 2021
gAlfonso-bit added a comment.
I think I got it
================
Comment at: llvm/include/llvm/Support/MathExtras.h:192
unsigned long Index;
_BitScanReverse(&Index, Val);
return Index ^ 31;
----------------
gAlfonso-bit wrote:
> craig.topper wrote:
> > gAlfonso-bit wrote:
> > > craig.topper wrote:
> > > > gAlfonso-bit wrote:
> > > > > craig.topper wrote:
> > > > > > Does _BitScanReverse work in a constexpr in MSVC? The implementation in clang-cl doesn't work in constexpr, but clang-cl would use __builtin_clz.
> > > > > Yes it does. This is one of those exceptions where you can pass a reference because you don't read Index, but only write to it, and Index is in a constexpr anyway
> > > > I tried it on godbolt and it didn't seem to work. Am I doing something wrong? https://godbolt.org/z/MnEY763E4
> > > Not sure, but so far LLVM compiles on Windows without a hitch, and the testbot is not having issues either
> > Maybe that just means llvm never uses it in a context where it needs to be evaluated as a constexpr since your patch didn't add any new usages. So it might fail if someone tries to use the constexpr capability?
> Well, the other functions I made constexpr calls them, so that isn't it.
So I think I figured it out. Since I made the FIRST count function constexpr where the second value in the <> braces isn't constant, the compiler is using that instead of the non constexpr ones in these cases.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D107240/new/
https://reviews.llvm.org/D107240
More information about the llvm-commits
mailing list