<div dir="ltr">LLVM doesn't have any support for transforming the first loop into ctpop. We only recognize the second form in your <span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">popcount_Yang_i32 function.</span><div><br></div><div>I don't know of any papers myself, I've just spent some time looking at the popcount recognition code recently.<br><div><br></div><div>~Craig<br></div><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Sat, Jun 2, 2018 at 4:24 AM Alex Susu via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> Hello.<br>
Could you please tell me why am I not able to recognize (with LLVM built from the SVN <br>
code in Apr 25, 2018) the LLVM IR intrinsic ctpop (described at <br>
<a href="https://llvm.org/docs/LangRef.html#llvm-ctpop-intrinsic" rel="noreferrer" target="_blank">https://llvm.org/docs/LangRef.html#llvm-ctpop-intrinsic</a>) in the following program:<br>
int PopCnt_Simple(int x) {<br>
int numBits = 0;<br>
int i;<br>
<br>
//for (i = 0; i < 32; i++) {<br>
for (i = 0; x != 0; i++) {<br>
if (x & 1)<br>
numBits++;<br>
x >>= 1;<br>
}<br>
<br>
return numBits;<br>
}<br>
<br>
I also did check the following code, getting inspired from the discussion at <br>
<a href="http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20121119/156300.html" rel="noreferrer" target="_blank">http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20121119/156300.html</a>:<br>
int popcount_Yang_i32(int a) {<br>
int c = 0;<br>
while (a) {<br>
c++;<br>
//... // both a & c would be used multiple times in or out of<br>
//loop<br>
a &= a - 1;<br>
//...<br>
}<br>
<br>
return c;<br>
}<br>
<br>
<br>
Is there any good paper discussing this type of loop idiom recognitions? I found only <br>
a vaguely related paper: "Automatic Recognition of Performance Idioms in Scientific <br>
Applications", IPDPS 2011 (<a href="http://www.sdsc.edu/~allans/ipdps11.pdf" rel="noreferrer" target="_blank">http://www.sdsc.edu/~allans/ipdps11.pdf</a>).<br>
<br>
Thank you very much,<br>
Alex<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>