<div dir="ltr">Thanks Andrea. I will check that out and resubmit the patch.<div><br></div><div>Filipe</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, May 16, 2014 at 12:47 PM, Andrea Di Biagio <span dir="ltr"><<a href="mailto:Andrea_DiBiagio@sn.scee.net" target="_blank">Andrea_DiBiagio@sn.scee.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">> Hi Andrea,<br>
><br>
> Wouldn't the tablegen patterns be problematic when we use the load result<br>
> several times?<br>
> If we use it several times, then we shouldn't generate additional loads. Or<br>
> do you think it doesn't matter since they should be close together, since<br>
> we're generating for one BB only?<br>
<br>
</div>The ISel pattern matcher will only reduce a dag sequence if the chain is "profitable to fold". A chain is never profitable, for example, if it contains nodes with more than one use.<br>
<br>
In the case of your new test function 'insertps_from_vector_load', if I add another use for variable %1, then the following rule will no longer trigger.<br>
<div class=""><br>
  def : Pat<(v4f32 (X86insertps (v4f32 VR128:$src1), (loadv4f32 addr:$src2),<br>
                  imm:$src3)),<br>
              (INSERTPSrm VR128:$src1, addr:$src2, imm:$src3)>;<br>
<br>
</div>That is because eventually, method 'X86DAGtoDAGISel::IsProfitableToFold' will return false if the 'loadv4f32' has more than one use (see X86ISelDAGToDAG.cpp - around line 303). Basically, the matcher will try to verify that all the intermediate nodes between the X86Insertps (excluded) and the loadv4f32 (included), only have a single use.<br>

<br>
Given how the ISel Matcher works, in case of a load result used several times, we will not generate additional loads.<br>
<div class=""><br>
> That was the reasoning behind doing it with code and guarding them with<br>
> MayFoldLoad, which includes hasOneUse().<br>
<br>
</div>That reasoning is correct. However, the pattern Matcher will do the same and will never try to fold the loadv4f32 if it has more than one use. (P.s.: you can see it by yourself if you some experiments adding more uses for the load instruction and then you debug ISel passing flag -debug to llc).<br>

<br>
I hope this helps.<br>
<br>
<a href="http://reviews.llvm.org/D3581" target="_blank">http://reviews.llvm.org/D3581</a><br>
<br>
<br>
</blockquote></div><br></div>