<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, May 1, 2019 at 3:55 PM Przemyslaw Ossowski <<a href="mailto:przemyslaw.ossowski@googlemail.com">przemyslaw.ossowski@googlemail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr"> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><br></div><div>I
 want to customize handling of 'load' instruction during processing DAG,
 but on IR level I want the 'load' to be treated in different passes as 
common load. So I'm afraid that replacing 'load' with Intrinsic would 
cause different handling it comparing to LoadInst.</div></div></div></div></div></blockquote><div dir="auto"><br></div><div dir="auto">Yes this is the kind of replacement you would do after the general optimizations.</div><div dir="auto">If
 you need to attach this information when you create the IR (from the 
front-end directly for example) then intrinsics or metadatas are the 
only two ways I know of.</div><div dir="auto">Depending on what is it 
exactly that you are trying to model, function attributes can be used 
but they would apply to the whole function (or specific arguments). It 
may also be possible to use an intrinsic to mark the pointer itself 
instead of the instructions manipulating it, again it depends on what 
you are modelling.</div><div dir="auto"><br></div></div></div></blockquote><div>So you are suggesting to replace something like:</div><div><span style="font-family:monospace,monospace">%ptr = alloca i32                                                         <br>%val = load i32, i32* %ptr</span><br></div><div> with</div><div>
<div><span style="font-family:monospace,monospace">%ptr = alloca i32              <br>%custom.ptr = call i32* @llvm.customhandling(i32* %ptr)                                           <br>%val = load i32, i32* %custom.ptr</span></div></div></div><div dir="ltr">?<br></div></div></div></div></blockquote><div><br></div><div>I had in mind something like:</div><div><br></div><div><span style="font-family:monospace,monospace">%ptr = alloca i32</span><br style="font-family:monospace,monospace"></div><div><span style="font-family:monospace,monospace">%custom.ptr = call i32* @llvm.customhandling(i32* %ptr)  </span></div><div><span style="font-family:monospace,monospace">                       </span><span style="font-family:monospace,monospace">                  </span><br></div><div>Then use only the `custom.ptr`, never `ptr`.</div><div>But every approach will have its tradeoff, so it really depends on the use-case.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><div class="gmail_quote"><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>I've found that in the DAGBuilder metadata information connected with LoadInst instruction is utilized:</div><div><span style="font-family:monospace,monospace">bool isInvariant = I.getMetadata(LLVMContext::MD_invariant_load) != nullptr;</span></div><div><br></div><div>Is this metadata somehow protected against dropping - as you mentioned?</div></div></div></div></div></blockquote><div dir="auto"><br></div><div dir="auto">Nothing is protected as far as I know, the design is that it should always be legal to drop a metadata.</div><div dir="auto">I
 don’t know what the invariant_load information is used for at the place
 you looked at, but I assume that I can take the IR, strip it out of the
 “invariant_load” metadata from the loads, and optimizations/codegen 
should still be correct. If your use-case fits in this model then 
metadata is likely a good starting point.</div><div dir="auto"><br></div></div></div></blockquote>

</div></div><div>In my case dropping metadata shouldn't cause functional issues, eventual only performance - different pattern would be chosen. So I will start with utilizing metadata.</div><div><br></div><div>Regards,</div><div>Przemek<br></div><div dir="ltr"><br></div><div dir="ltr"><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, May 2, 2019 at 12:05 AM Mehdi AMINI <<a href="mailto:joker.eph@gmail.com" target="_blank">joker.eph@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><br></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, May 1, 2019 at 2:48 PM Przemyslaw Ossowski <<a href="mailto:przemyslaw.ossowski@googlemail.com" target="_blank">przemyslaw.ossowski@googlemail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Thanks Mehdi for the suggestion.<br></div><div>I want to customize handling of 'load' instruction during processing DAG, but on IR level I want the 'load' to be treated in different passes as common load. So I'm afraid that replacing 'load' with Intrinsic would cause different handling it comparing to LoadInst.</div></div></div></div></div></blockquote><div dir="auto"><br></div><div dir="auto">Yes this is the kind of replacement you would do after the general optimizations.</div><div dir="auto">If you need to attach this information when you create the IR (from the front-end directly for example) then intrinsics or metadatas are the only two ways I know of.</div><div dir="auto">Depending on what is it exactly that you are trying to model, function attributes can be used but they would apply to the whole function (or specific arguments). It may also be possible to use an intrinsic to mark the pointer itself instead of the instructions manipulating it, again it depends on what you are modelling.</div><div dir="auto"><br></div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div></div><div>I've found that in the DAGBuilder metadata information connected with LoadInst instruction is utilized:</div><div><span style="font-family:monospace,monospace">bool isInvariant = I.getMetadata(LLVMContext::MD_invariant_load) != nullptr;</span></div><div><br></div><div>Is this metadata somehow protected against dropping - as you mentioned?</div></div></div></div></div></blockquote><div dir="auto"><br></div><div dir="auto">Nothing is protected as far as I know, the design is that it should always be legal to drop a metadata.</div><div dir="auto">I don’t know what the invariant_load information is used for at the place you looked at, but I assume that I can take the IR, strip it out of the “invariant_load” metadata from the loads, and optimizations/codegen should still be correct. If your use-case fits in this model then metadata is likely a good starting point.</div><div dir="auto"><br></div><div dir="auto">Best,</div><div dir="auto"><br></div><div dir="auto">— </div><div dir="auto">Mehdi</div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div></div><div><br></div><div>Thanks,</div><div>Przemek<br></div></div></div></div></div><div dir="ltr"><div dir="ltr"><div dir="ltr"><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, May 1, 2019 at 5:57 AM Mehdi AMINI <<a href="mailto:joker.eph@gmail.com" target="_blank">joker.eph@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 30, 2019 at 3:51 PM Przemyslaw Ossowski via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi,</div><div>as I wrote in mu previous post I wanted to somehow mark one IR instruction (in this particular case it would be 'load') during dedicated pass, which will set the marking based on neighboring instructions. Next I wanted to somehow to convey this marking from 'load' IR instruction to 'load' SDNode in order to use it during DAG Instruction Selection - information stored in this marking would 'enable' or 'disable' particular pattern... I was thinking about usage metadata for it, but I didn't get any feedback. <br></div><div>So now I'm wondering if solution with metadata is the best one or it maybe it doesn't make any sense an something else would be better.<br></div><div><br></div><div>I don't have big experience with metadata, but what I've read it would allow for customizing IR instruction without modifying the instruction. Or maybe I'm unnecessarily thinking about metadata, because 'load' instruction has already some fields which could be used for storing 'flags', which might represent any custom information. Obviously I don't want to modify 'load'.<br></div><div>
Any suggestions? <br></div><div></div></div></blockquote><div><br></div><div>In general metadata aren't recommended for carrying semantically important information as they can be dropped at any time.</div><div><br></div><div>What about using a target specific intrinsic? Your pass could convert the instructions to your intrinsic that you can then easily match in SelectionDAG.</div><div><br></div><div>-- </div><div>Mehdi</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div> <br><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 25, 2019 at 11:54 AM Przemyslaw Ossowski <<a href="mailto:przemyslaw.ossowski@googlemail.com" target="_blank">przemyslaw.ossowski@googlemail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">



















<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">Hello,<span></span></p>

<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif"><span> </span></p>

<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">I’m looking for the best approach which would allow for marking
given LLVM IR instruction during IR custom pass and later utilizing that
information during DAG Instruction Selection in order to match given pattern
based on this marking.<span></span></p>

<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif"><span> </span></p>

<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">I’m wondering if marking IR instruction utilizing Metadata
is good idea.<span></span></p>

<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">But how later pass that information to DAG and appropriately
mark in DAGBuilder SDNode, which represents the earlier marked instruction in
IR?<span></span></p>

<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif"><span> </span></p>

<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">Any suggestion how to implement the most efficiently?<span></span></p>

<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">I’m expecting there are already similar solutions – maybe someone
would be able to indicate the exact example?<span></span></p>

<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif"><span> </span></p>

<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">Thanks in advance,<span></span></p>

<p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">Przemek<span></span></p>





</div>
</blockquote></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>
</blockquote></div></div></div></div>
</blockquote></div></div>
</blockquote></div></div></div></div>
</blockquote></div></div></div></div></div>