Zaara Syeda via llvm-dev
2017-Nov-21 16:23 UTC
[llvm-dev] RFC MachineLICM to hoist invariant stores
<div class="socmaildefaultfont" dir="ltr" style="font-family:Arial, Helvetica, sans-serif;font-size:10.5pt" ><div dir="ltr" >I've also posted a patch on phabricator for the isInvariantStore and isCopyFeedingInvariantStore hooks: <a href="https://reviews.llvm.org/D40196" >https://reviews.llvm.org/D40196</a></div> <div dir="ltr" > </div> <blockquote data-history-content-modified="1" data-history-expanded="1" dir="ltr" style="border-left:solid #aaaaaa 2px; margin-left:5px; padding-left:5px; direction:ltr; margin-right:0px" >----- Original message -----<br>From: Zaara Syeda/Toronto/IBM<br>To: llvm-dev@lists.llvm.org<br>Cc:<br>Subject: RFC MachineLICM to hoist invariant stores<br>Date: Wed, Nov 15, 2017 5:17 PM<br> <br><font size="3" >Hello,</font><br><br><font size="3" >I’m looking at MachineLICM and running into a limitation of not hoisting instructions that store a constant value to a constant spot on the stack. I see this example in the case of indirect calls for PowerPC. Indirect calls on PPC must be surrounded by instructions that save and restore the TOC (similar to the GOT) pointer. This pointer is in register X2 and will not change throughout the function.</font><br><br><font size="3" >%vreg12<def> = COPY %X2; G8RC:%vreg12</font><br><font size="3" >STD %vreg12, 24, %X1; mem:ST8[Stack+24] G8RC:%vreg12</font><br><font size="3" > </font><br><font size="3" >This currently can't be hoisted because:</font><br><font size="3" >1. It is a store instruction</font><br><font size="3" >2. It uses a physical register (the stack pointer register - X1)</font><br><font size="3" >3. The copy that defines the physical register being stored isn't profitable to hoist</font><br><br><font size="3" >As a proof of concept, I’ve relaxed these conditions to catch these loop invariant stores by using the fact that registers X1/X2 satisfy isCallerPreservedPhysReg(). With these relaxations I get the following results in SPEC:</font><br><br><font size="3" >Benchmark | Improvement | # of Hoists<br>dealII |0.10 % |1203</font><br><font size="3" >h264ref |11 % |347</font><br><font size="3" >Gcc |1.42 % |135<br>xalancbmk |0.86 % |3886</font><br><font size="3" >Astar | -2.39% | 1</font><br><br><font size="3" >Astar here is an outlier where we see a degradation. In this case, the store was hoisted out of an if statement that is executed infrequently compared to the outer code. This results in the store to r2 being executed more times dynamically.</font><br><font size="3" > </font><br><font size="3" >I would like to add TargetInstrInfo hooks like isInvariantStore(MachineInstr &) and isCopyFeedingInvariantStore(MachineInstr &) that would tell MachineLICM that the two instructions are safe and profitable to hoist. </font><br><br><font size="3" >Please advise if adding the target hooks is a good solution and if other targets would be interested in such hooks, or whether I should be take a different approach.</font><br><font size="3" > </font><br><font size="3" >Thanks,</font><br><font size="3" >Zaara Syeda</font></blockquote> <div dir="ltr" > </div></div><BR>