[llvm-dev] LoopIdiomRecognize is not recognizing the ctpop idiom

Craig Topper via llvm-dev llvm-dev at lists.llvm.org
Sat Jun 2 09:04:31 PDT 2018


LLVM doesn't have any support for transforming the first loop into ctpop.
We only recognize the second form in your popcount_Yang_i32 function.

I don't know of any papers myself, I've just spent some time looking at the
popcount recognition code recently.

~Craig


On Sat, Jun 2, 2018 at 4:24 AM Alex Susu via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

>    Hello.
>      Could you please tell me why am I not able to recognize (with LLVM
> built from the SVN
> code in Apr 25, 2018) the LLVM IR intrinsic ctpop (described at
> https://llvm.org/docs/LangRef.html#llvm-ctpop-intrinsic) in the following
> program:
>        int PopCnt_Simple(int x) {
>            int numBits = 0;
>            int i;
>
>            //for (i = 0; i < 32; i++) {
>            for (i = 0; x != 0; i++) {
>                if (x & 1)
>                    numBits++;
>                x >>= 1;
>            }
>
>            return numBits;
>        }
>
>      I also did check the following code, getting inspired from the
> discussion at
>
> http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20121119/156300.html
> :
>        int popcount_Yang_i32(int a) {
>              int c = 0;
>              while (a) {
>                  c++;
>                  //...  // both a & c would be used multiple times in or
> out of
>                  //loop
>                  a &= a - 1;
>                  //...
>              }
>
>              return c;
>        }
>
>
>      Is there any good paper discussing this type of loop idiom
> recognitions? I found only
> a vaguely related paper: "Automatic Recognition of Performance Idioms in
> Scientific
> Applications", IPDPS 2011  (http://www.sdsc.edu/~allans/ipdps11.pdf).
>
>    Thank you very much,
>      Alex
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180602/883a4444/attachment.html>


More information about the llvm-dev mailing list