[llvm-dev] [RFC][RISCV] Selection of complex codegen patterns into RISCV bit manipulation instructions

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Wed Aug 14 05:30:20 PDT 2019

Hi Paolo,

On Wed, 14 Aug 2019 at 13:13, paolo via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> Take for intsance the count leading zeros operation:

The example implementation has a couple of problems (no uint32_t will
be negative, and any shift you'd think might turn a positive number
into a negative one is undefined behaviour).

But there is some code in lib/Transforms/Scalar/LoopIdiomRecognize.cpp
designed to spot loops that really are calculating ctlz etc and
replace them with the proper intrinsic call. The tests seem to give
some examples of the kind of thing it can see:

> Another point of view that I've been suggested and that I'd like to
> discuss is: does it make sense to implement such lowering for operations
> that normally a user wouldn't implement from scratch when an intrinsic
> function is already available for that?

Probably not during CodeGen since that mostly works at the basic block
level, but in general yes (hence LoopIdiomRecognize)



More information about the llvm-dev mailing list