<div dir="ltr">You can avoid at least some of it by using the Instruction interfaces (e.g. CallInst::Create()) directly instead of IRBuilder.<div><br><div>But (a) I'm not sure if this will change what happens in this particular case, and (b) I would strongly suggest you not do this, though, unless you have a really good reason (you're trying to generate a specific instruction sequence for, say, fuzzing).</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 30 December 2016 at 19:20, Mehdi Amini via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On Dec 30, 2016, at 3:03 PM, Alex Susu via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
> Hello.<br>
> I'm writing an LLVM pass that is working on LLVM IR.<br>
> To my surprise the following LLVM pass code generates optimized code - it does copy propagation on it.<br>
<br>
</span>It does *constant* propagation to be exact.<br>
<span class=""><br>
> Value *vecShuffleOnePtr = Builder.CreateGEP(ptr_B, vecShuffleOne, "VectorGep");<br>
> ...<br>
> packed_gather_params.push_<wbr>back(vecShuffleOnePtr);<br>
> CallInst *callGather = Builder.CreateCall(func_llvm_<wbr>masked_gather_v128i16,<br>
> packed_gather_params);<br>
> callGather->addAttribute(<wbr>AttributeSet::FunctionIndex, Attribute::NoUnwind);<br>
><br>
> DEBUG(dbgs() << "callGather: " << *callGather << "\n");<br>
><br>
> When running this code we get at stderr something like:<br>
> callgather: %50 = call <4 x i16> @llvm.masked.gather.v4i16(<4 x i16*> getelementptr (i16, i16* inttoptr (i16 51 to i16*), <4 x i64> <i64 1, i64 1, i64 1, i64 1>), i32 0, <4 x i1> <i1 true, i1 true, i1 true, i1 true>, <4 x i16> undef)<br>
> Also, more importantly, the resulting LLVM program will also contain this 1 gather LLVM IR instruction.<br>
><br>
> So, although I instructed LLVM to generate 2 instructions, it creates only one instruction, a call to gather containing as parameter not the VectorGep variable name, but its value/definition, the getelementptr instruction (and this happens even if VectorGep is used more than once in my program).<br>
><br>
> Is there a way to specify programmatically in my LLVM pass to avoid doing this copy propagation optimization (and obtain an LLVM program with a separate getelementptr instruction, besides the gather instruction)?<br>
<br>
</span>No: you can’t really force constant to not be propagated (At least I don’t know an easy way for that).<br>
<br>
—<br>
Mehdi<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
</div></div></blockquote></div><br></div>