[LLVMdev] [PATCH] Emit rbit, clz on ARM for __builtin_ctz

Chris Lattner
Fri, 15 Jan 2010 18:03:39 -0000

On Jan 14, 2010, at 10:13 PM, David Conrad wrote:

> Hi,
>
> On ARMv6T2 this turns cttz into rbit, clz instead of the 4
> instruction sequence it is now.
>
> I'm not sure if adding RBIT to ARMISD and doing this optimization in
> the legalize pass is the best option, but the only better way I
> could think of doing it was to add a bitreverse intrinsic to llvm
> ir, which itself might not be the best option since bitreverse
> probably isn't too common.

I haven't looked at the patch in detail, but this approach makes sense
to me.

> Other targets that I know of that could potentially benefit from
> this optimization being global (that have a clz and bitreverse
> instruction but not ctz) are AVR32 and C64x, neither of which llvm
> has backends for yet.

When/if another target wants this, we could add a ISD::RBIT operation,
it doesn't need to be added at the llvm ir level,

-Chris