<div dir="ltr"><div><br></div><div>If I understand correctly, this patch is trying to change the meaning of __builtin_ctz (et al.) under some extremely specific conditions. I don't think that is the right direction since it will cause surprising undefined behavior bugs across platforms. The intrinsic is documented to have undefined behavior in the 0 case (everywhere I looked, including our internal docs); a user that relies on the 0 case has a bug. It would be nice to add a UBSan check for this undefined behavior though to help users fix their code.</div><div><br></div><div>It would be better to just ensure that we always generate optimal code in the presence of a manual guard for the 0 case. For example, in the middle-end we could fold a manual 0 guard followed by @llvm.ctlz.*(X, true) into @llvm.ctlz.*(X, false).</div><div><br></div><div>-- Sean Silva</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 23, 2014 at 4:40 PM, Robinson, Paul <span dir="ltr"><<a href="mailto:Paul_Robinson@playstation.sony.com" target="_blank">Paul_Robinson@playstation.sony.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In general, count-zeros instructions are undefined for a zero input value.<br>
However the X86 TZCNT and LZCNT instructions do return the bit-width on a<br>
zero input, so make Clang tell LLVM so.<br>
One quirk is that these instructions aren't necessarily both defined, so<br>
also create a separate predicate so we can do the right thing for all CPUs.<br>
--paulr<br>
<br>
<br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br></div>