<div dir="ltr">A fix is out for review here: <a href="http://reviews.llvm.org/D8350">http://reviews.llvm.org/D8350</a></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Mar 15, 2015 at 12:23 PM, Mat Hostetter <span dir="ltr"><<a href="mailto:mjhostetter@gmail.com" target="_blank">mjhostetter@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>This kind of pattern is very common when dealing with bit arrays:</div><div><br></div><div>unsigned long clear_mask(int bit)<br></div><div>{</div><div> return ~(1UL << bit);</div><div>}</div><div><br></div><div>clang 3.6 at -O3 compiles this in the straightforward way, moving 1 into register, shifting it, then flipping all the bits:</div><div><br></div><div><div><span style="white-space:pre-wrap"> </span>movl<span style="white-space:pre-wrap"> </span>$1, %eax</div><div><span style="white-space:pre-wrap"> </span>movb<span style="white-space:pre-wrap"> </span>%dil, %cl</div><div><span style="white-space:pre-wrap"> </span>shlq<span style="white-space:pre-wrap"> </span>%cl, %rax</div><div><span style="white-space:pre-wrap"> </span>notq<span style="white-space:pre-wrap"> </span>%rax</div></div><div><br></div><div>gcc 4.8.2, however, is more clever. It moves -2, i.e. ~1, into a register then rotates that into place, saving one instruction:<br><br></div><div><div><span style="white-space:pre-wrap"> </span>movl<span style="white-space:pre-wrap"> </span>%edi, %ecx</div><div><span style="white-space:pre-wrap"> </span>movq<span style="white-space:pre-wrap"> </span>$-2, %rax</div><div><span style="white-space:pre-wrap"> </span>rolq<span style="white-space:pre-wrap"> </span>%cl, %rax</div></div><div><br></div><div><br></div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>