<div dir="ltr">Right, that's where I'm going with this.  Many intrinsics already make use of constant-only parameters, but I'm wondering if there are any documented requirements for passes that make sure this works, or if we have just been getting lucky with the current intrinsics.<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, May 1, 2014 at 11:44 AM, Reid Kleckner <span dir="ltr"><<a href="mailto:rnk@google.com" target="_blank">rnk@google.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">Looks like LLVM won't tolerate that optimization.  There are a bunch of intrinsics that require constant args.  The verifier checks that they are constant args in Verifier::visitIntrinsicFunctionCall(), and this fails verification:<div>

<br></div><div><div>define void @myprefetch(i8* nocapture %p, i32 %rw) {</div><div>  tail call void @llvm.prefetch(i8* %p, i32 %rw, i32 3, i32 1)</div><div>  ret void</div><div>}</div><div><br></div><div>We should probably note which args have to be constant in the .td file so passes can avoid breaking these intrinsics in exactly this way.</div>

</div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div class="h5">On Thu, May 1, 2014 at 5:10 AM, Justin Holewinski <span dir="ltr"><<a href="mailto:justin.holewinski@gmail.com" target="_blank">justin.holewinski@gmail.com</a>></span> wrote:<br>

</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div><div><div><div>My understanding of intrinsics in LLVM is that an optimization pass cannot touch an intrinsic unless it (1) is specifically programmed to have knowledge of the intrinsic, or (2) uses only declared properties of the intrinsic, like IntrNoMem.  So, for example, a pass may move an unknown intrinsic around memory ops if its defined IntrNoMem, but it cannot hoist constants for arbitrary intrinsics.  Is this correct?  I can't find this codified anywhere in the documentation.<br>


<br></div><div>The context for this question is adding an intrinsic that requires a constant parameter.  There is no way to define this property in the tablegen description currently.  I want to verify that if I add such an intrinsic, it would be illegal for any existing optimization pass to hoist the constant parameter.  For example, if I add a target intrinsic llvm.foo that takes two parameters: i32 and i1, where the i1 parameter must be a constant (same as llvm.cttz), I want to verify that the following optimization is illegal without having to change any LLVM passes:<br>


</div><div><br></div></div>Input:<br><br>define i32 @f0(i32 %a, i1 %pred) {<br>  br i1 %pred, label %first, label %second<br>first:<br>  %r0 = tail call i32 @llvm.foo.i32(i32 %a, i1 true)<br>  br label %end<br>second:<br>


  %r1 = tail call i32 @llvm.foo.i32(i32 %a, i1 false)<br>  br label %end<br>end:<br>  %r = phi i32 [%r0, %first], [%r1, %second]<br>  ret i32 %r<br>}<br><br></div>Output:<br><br>define i32 @f1(i32 %a, i1 %pred) {<br>  %r = tail call i32 @llvm.foo.i32(i32 %a, i1 %pred)<br>


  ret i32 %r<br>}<span><font color="#888888"><br><br></font></span></div><span><font color="#888888"><div><div><div><div><div>-- <br><br><div>Thanks,</div><div><br></div><div>Justin Holewinski</div>

</div></div></div></div></div></font></span></div>
<br></div></div><div class="">_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">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></div></blockquote></div><br></div>
</blockquote></div><br><br clear="all"><br>-- <br><br><div>Thanks,</div><div><br></div><div>Justin Holewinski</div>
</div>