4 ms·
I don't recall seeing bit counting in the LLVM idiom recognition, but it's been years since I pored over it. Could you maybe Godbolt an example where this subst
by vnorilo 7y ago
I don't recall seeing bit counting in the LLVM idiom recognition, but it's been years since I pored over it. Could you maybe Godbolt an example where this substitution happens? I'd be happy to be wrong in this case :)
- kardos 7y agoFrom the article, GCC: https://godbolt.org/z/JUzmD8 https://godbolt.org/z/JUzmD8 Clang: https://godbolt.org/z/AVqMGl https://godbolt.org/z/AVqMGl
- vnorilo 7y agoIndeed, thanks! Skimmed a bit too quickly.
- account42 7y agoAny idea why GCC zeroes out eax before overwriting it? It never fails to amaze me how smart compilers can be while also being so stupid sometimes.
- vnorilo 7y agoThis thread [1] might give you some idea of the complexity involved in a similar issue. OTOH, if you see RAX being zeroed before using EAX, it is likely to be about breaking false deps. 1: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86314 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86314
- vnorilo 7y agoIt could be a bug; I don't see an immediate reason to zero eax in this fragment. Sometimes it's easy to miss the reasons why compilers zero apparently unused things though: it can be about breaking data dependencies or making sure flags are in a known state.
- gpderetta 7y agoIt is a bug, but in the CPU. Until recently, on intel cpu, the popcnt instruction had an implicit dependency on its output register, which can be a performance issue. Explicitly clearing the register (which is very fast and almost free), is an easy way to workaround it.
- account42 7y agoOh, nice info. It's gone when using e.g. -march=znver1.