<div class="gmail_quote">On Tue, May 24, 2011 at 8:35 AM, roy rosen <span dir="ltr"><<a href="mailto:roy.1rosen@gmail.com">roy.1rosen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
2011/5/24 Justin Holewinski <<a href="mailto:justin.holewinski@gmail.com">justin.holewinski@gmail.com</a>>:<br>
<div><div></div><div class="h5">> On Tue, May 24, 2011 at 3:02 AM, roy rosen <<a href="mailto:roy.1rosen@gmail.com">roy.1rosen@gmail.com</a>> wrote:<br>
>><br>
>> Hi,<br>
>><br>
>> I was wondering if LLVM supports predicates and conditional execution.<br>
>> Something like we have in IA64.<br>
>> There is a register class of predicates and then every instruction may<br>
>> be predicated by a register from this class.<br>
>> For example:<br>
>><br>
>> cmp_less p, x, y // p is a predicate which gets the result of x < y<br>
>> p add x, x, 2 // if p then do the add instruction<br>
>><br>
>> Is there support in LLVM to something like that?<br>
>><br>
>> Which architecture can show a good example for the implementation of that?<br>
><br>
> You may want to look at the PTX back-end.  The PTX assembly language<br>
> supports exactly what you are describing, and we currently use it to<br>
> implement conditional branching.  There is a register class for predicates<br>
> (i1 in LLVM) and all machine instructions have a predicate operand and<br>
> predicate filter (PTX supports inverted predicates).  For un-predicated<br>
> instructions, the predicate operand is just set to the special NoRegister<br>
> constant.<br>
><br>
>><br>
>> Thanks, Roy.<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>
><br>
><br>
> --<br>
><br>
> Thanks,<br>
> Justin Holewinski<br>
><br>
<br>
</div></div>I see that PTX has predicated execution for all instructions.<br>
in LLVM you implement conditional execution only for branches?<br>
Do you know what it takes to make it work for all instructions?<br></blockquote><div><br></div><div>It already works for all instructions, as long as you supply a predicate operand in the machine instruction (not to be confused with an LLVM IR instruction).  Currently, this feature is only being used to implement conditional branches, but that is just because we have not implemented it for other cases.</div>
<div><br></div><div>The primary difficulty here is deciding when and how to use predicates.  LLVM IR does not support predicated execution, so we need to match specific LLVM IR patterns into predicated instructions when compiling for PTX.  It is somewhat trivial in cases such as conditional branches, where predicates are the only way to implement them in PTX, and some LLVM IR constructs such as the select instruction.  For more interesting cases, such as converting simple if-then-else statements into predicated instruction blocks, we still have yet to decide how best to handle this.</div>
<div><br></div><div>Can you provide a little more information on what you want to do in LLVM?  Are you wanting to generate an Itanium back-end, or are you just using that as an example?</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<br>
Thanks, Roy.<br>
</blockquote></div><br><br clear="all"><br>-- <br><br><div>Thanks,</div><div><br></div><div>Justin Holewinski</div><br>