<div dir="ltr"><div>Hi Sjoerd,</div><div><br></div><div>I'm already using RDA in the pass I mentioned and it works great. Thanks Sam!</div><div><br></div><div>Regarding the root cause, I didn't see anything obviously suboptimal not in the copy coalescing or the register allocation, at least in my previous example. Alternatively we might want to improve what we pass onto RA: i.e. remove the redundant copy earlier. At this point however it doesn't (obviously) look like one (it still using different vregs) which suggests it might require a bit more of work to discover something that will ultimately lead to a redundant copy. I will investigate this option as well.<br></div><div><br></div><div>I'll take a look at the hardware-loop pass DCE code. Thanks for the pointer!</div><div><br></div><div>Kind regards,<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Missatge de Sjoerd Meijer <<a href="mailto:Sjoerd.Meijer@arm.com" target="_blank">Sjoerd.Meijer@arm.com</a>> del dia dj., 12 de març 2020 a les 20:50:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">




<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
+ Sam</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Hi Roger,</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
FWIW: we have observed redundant copies/movies, they are annoying us for some time now but we haven't got round to looking at it. Not sure we if we are looking at exactly the same problem, but I guess so.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Treating symptoms with post RA dead code elimination might be very effective, but it might also be worth to just have a look at the source of the problem (regalloc?) to see if we are not missing something obvious.
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Regarding a post RA pass: you may want to have a look at the ARM hardware-loop pass. In order to make that beneficial, we have to do quite some dead code elimination post RA, both in inside loops and in preheaders, see e.g. ARMLowOverheadLoops::IterationCountDCE.
 This is using ReachingDefAnalysis (RDA), which has been extended by Sam and made more generic to support this, which was also going to be his eurollvm talk:
<a href="http://llvm.org/devmtg/2020-04/talks.html#LightningTalk_26" id="m_-7900133916497045904m_-8987836798940242722gmail-m_4232067088832861442LPlnk296516" target="_blank">
http://llvm.org/devmtg/2020-04/talks.html#LightningTalk_26</a>. End of advertisement. ;-) Basically what I want to say is that this should provide most of the things you'll need.<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Cheers,</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Sjoerd.<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div id="m_-7900133916497045904m_-8987836798940242722gmail-m_4232067088832861442appendonsend"></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<hr style="display:inline-block;width:98%">
<div id="m_-7900133916497045904m_-8987836798940242722gmail-m_4232067088832861442divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>From:</b> llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>> on behalf of Roger Ferrer Ibáñez via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
<b>Sent:</b> 12 March 2020 18:06<br>
<b>To:</b> LLVM-Dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
<b>Subject:</b> [llvm-dev] Redundant copies</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div>Hi all,</div>
<div><br>
</div>
<div>we have encountered a case of redundant copies still left in the final code and we would like to, at least, mitigate it. The original motivating case comes from a context where we have large vector registers. In that context, copies are expensive and we
 would like to avoid them as much as possible.<br>
</div>
<div><br>
</div>
<div>This small testcase in C, similar to the original vector case, exposes the issue but using scalars.<br>
</div>
<div><br>
</div>
<div style="margin-left:40px">long a, b;<br>
long fn1();<br>
long fn2() {<br>
  long c = a, d = c;<br>
  for (; b;) {<br>
    long e = fn1();<br>
    d = d + e;<br>
  }<br>
  long f = d - c;<br>
  return f;<br>
}</div>
<div><br>
</div>
<div>For instance in RISC-V we emit something like this but other backends like ARM or X86 show the same behaviour.<br>
</div>
<div><br>
</div>
<div style="margin-left:40px">add s0, zero, s2   # ← copy<br>
beqz a0, .LBB0_3<br>
# %bb.1:                                # %for.body.preheader<br>
add s0, zero, s2  # ← not needed<br>
.LBB0_2:                                # %for.body<br>
</div>
<div><br>
</div>
<div></div>
<div>Has anyone encountered a similar issue like this in the past?</div>
<div><br>
</div>
<div>We are looking into removing these copies with a post RA pass to address the most obvious case: if we see a copy with the same physregs in dest and source to an earlier one and the reaching definition of the dest and source registers is one and the same,
 then that copy should be redundant.</div>
<div><br>
</div>
<div>This might be too specific though, so perhaps there are better approaches?<br>
</div>
<div><br>
</div>
<div>Thanks!<br>
</div>
<br>
-- <br>
<div dir="ltr">Roger Ferrer Ibáñez<br>
</div>
</div>
</div>
</div>

</blockquote></div></div><br clear="all"><br>-- <br><div dir="ltr">Roger Ferrer Ibáñez<br></div>