<div class="gmail_quote">On Mon, Dec 12, 2011 at 1:14 AM, Duncan Sands <span dir="ltr"><<a href="mailto:baldrick@free.fr">baldrick@free.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Chandler,<br>
<div class="im"><br>
> Switch llvm.cttz and llvm.ctlz to accept a second i1 parameter which<br>
> indicates whether the intrinsic has a defined result for a first<br>
> argument equal to zero.<br>
<br>
</div>is this flag really useful, i.e. isn't the undef form enough?  To get the<br>
other form you can test the parameter against zero and use a select.  Then<br>
codegen can zap the select on targets where the processor instruction does<br>
the right thing for an argument of zero.<br></blockquote><div><br></div><div>I completely agree. Chris wanted it this way, and although it makes the implementation more complex and more work, I didn't feel like arguing. Feel free to do so, and if you win, I'll change it. =D</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">> --- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)<br>
> +++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Sun Dec 11 22:26:04 2011<br>
</div><div class="im">> @@ -1418,6 +1414,14 @@<br>
>             };<br>
>             return ConstantStruct::get(cast<StructType>(F->getReturnType()), Ops);<br>
>           }<br>
> +        case Intrinsic::cttz:<br>
> +          // FIXME: This should check for Op2 == 1, and become unreachable if<br>
<br>
</div>Don't you mean "undef" rather than "unreachable"?<br></blockquote><div><br></div><div>Yea, sorry, I'll clean up these comments when I start implementing the proper behavior for this case.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><br>
> +          // Op1 == 0.<br>
> +          return ConstantInt::get(Ty, Op1->getValue().countTrailingZeros());<br>
> +        case Intrinsic::ctlz:<br>
> +          // FIXME: This should check for Op2 == 1, and become unreachable if<br>
> +          // Op1 == 0.<br>
> +          return ConstantInt::get(Ty, Op1->getValue().countLeadingZeros());<br>
>           }<br>
>         }<br>
><br>
><br>
</div><div class="im">> --- llvm/trunk/lib/VMCore/AutoUpgrade.cpp (original)<br>
> +++ llvm/trunk/lib/VMCore/AutoUpgrade.cpp Sun Dec 11 22:26:04 2011<br>
> @@ -40,7 +40,20 @@<br>
><br>
>     switch (Name[0]) {<br>
>     default: break;<br>
> -  // SOMEDAY: Add some.<br>
> +  case 'c': {<br>
> +    Type *Tys[] = { F->arg_begin()->getType() };<br>
<br>
</div>If one day there is an llvm intrinsic with a name starting with "c" with no<br>
arguments, won't this explode?<br></blockquote><div><br></div><div>Yikes, good catch. Will fix. =]</div><div><br></div><div>Thanks for the review!</div></div>