[llvm-dev] BUGS n code generated for target i386 compiling __bswapdi3, and for target x86-64 compiling __bswapsi2()

Fabian Giesen via llvm-dev llvm-dev at lists.llvm.org
Mon Nov 26 11:11:37 PST 2018


On 11/26/2018 4:11 AM, Stefan Kanthak via llvm-dev wrote:
> The other part of my post but holds: the following function, compiled for
> x86-64, is NOT properly optimized (see <https://godbolt.org/z/uM9nvN>):
> 
> unsigned long __bswapsi2 (unsigned long ul)
> {
>      return (ul >> 3 * 8) & 0xff000000ul
>           | (ul >>     8) & 0x00ff0000ul
>           | (ul <<     8) & 0x0000ff00ul
>           | (ul << 3 * 8) & 0x000000fful;
> }

That looks like another instance of truncation in the wrong places 
causing the pattern matches to fail. There have been a couple of those 
in the past with other things like rotates.

This is indeed a bug, but if you need a quick workaround, the pattern 
does work when you use a 32-bit (e.g. unsigned int or uint32_t) type.

-Fabian


More information about the llvm-dev mailing list