<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Hi,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">For a test case that I ran I am seeing something in the RDF graph that I do not quite understand. I think there is an data flow edge that is missing but most
 likely I am wrong.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">The relevant portion of IR looks like this:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">BB#0:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">%R10<def> = MOVSX64rr32 %EDX<kill>; dbg:FastBoard.cpp:186:26 @[ FastBoard.cpp:1938:21 ]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">                                                  .<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">                                                  .<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">                                                  .<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">TEST32rr %ESI<kill>, %R8D<kill>, %EFLAGS<imp-def>; dbg:FastBoard.cpp:1940:10<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">JNE_1 <BB#1>, %EFLAGS<imp-use,kill>; dbg:FastBoard.cpp:1940:9<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">BB#1:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">%CL<def> = COPY %R9B<kill>, %ECX<imp-use,kill>, %ECX<imp-def>; dbg:FastBoard.cpp:1938:38<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">                                                   .<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">                                                   .<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">                                                   .<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">CMP32mr %RDI, 4, %RSI, 1776, %noreg, %ECX, %EFLAGS<imp-def>; mem:LD4[%arrayidx.i49](tbaa=!2767) dbg:FastBoard.cpp:1947:26<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">The relevant portion of the RDF graph that is constructed is shown below:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">BB#0:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">s3: MOV32r0 [d4<ECX>(,d50,u245):, d5<EFLAGS>!(,d7,):]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">                                                  .<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">                                                  .<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">                                                  .<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">BB#1:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">s48: COPY [d49<CL>(d4,,):, d50<ECX>(d4,d184,u246):d49, u51<R9B>(d11):u23, u52<ECX>(d4):]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">                                                  .<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">                                                  .<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">                                                  .<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">s61: CMP32mr [d62<EFLAGS>!(d58,d80,u205):, u63<RDI>(+d194):u55, u64<RSI>(d57):, u65<ECX>(d50):]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">This is a test case I was interested in because it shows the partial register redefinition scenario in X86 for which more register units needed to be added. I
 have a hacky fix for this in TableGen code which adds more units for X86 registers. I am not completely sure that my fix is correct and I was trying to test it.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">You can see that register ECX is defined by s3 above and is used in the compare instruction which is s61. In between there is a partial re-definition of the lower
 8 bits of ECX through the definition of register CL in s48. This definition of CL should leave the high order bits defined by s3 untouched.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Now consider the reaching definition for the use ref node u65 in s61. It has the d50 def ref node as a reaching definition. My question is: shouldn’t we also
 be able to infer that the d49 ref node is a reaching def node for u65? Starting from u65 there does not seem to be a way to reach d49.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">I debugged the code in X86RDFGraph.cpp. It appears that when we start from u65, we hit the def ref node d50 which covers u65 since both involve ECX. Hence there
 is no need to look for other reaching defs. <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">The node d50 itself is created as a def node because ECX appears as an implicit def in the COPY instruction in the machine IR and the code in the function buildStmt()
 processes such implicit defs and creates def nodes for them in the RDF graph.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">I understand that the virtual SSA nature of the RDF graph does not allow multiple reaching defs to be specified at a use ref node, but then how does one handle
 situations such as this where we need to identify all reaching defs for a use node? Or, is this situation being created because my hacky fix for the X86 partial redefinition case is not doing the right thing?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Thanks.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Regards,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Venu.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<div>
<div>
<p class="MsoNormal">From: <b>Krzysztof Parzyszek via llvm-dev</b> <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>><br>
Date: Thu, Nov 2, 2017 at 1:34 AM<br>
Subject: Re: [llvm-dev] Reaching definitions on Machine IR post register allocation<br>
To: <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<br>
<br>
RDF has its own tests to detect the ability to rename any given register. RefNodes that have "Fixed" flag are those where the register cannot be changed. Having the isRenamable flag in MachineOperand would help remove these tests.<br>
<br>
-Krzysztof<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal"><br>
<br>
<br>
On 10/31/2017 11:24 PM, Raghavan, Venugopal via llvm-dev wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<p class="MsoNormal">Hi Geoff/Krzyssztof,<br>
<br>
Wouldn't the isRenamable() change be required even for the RDF based copy propagation? Maybe Hexagon does not impose ABI/ISA restrictions which require specific registers to be used in specific contexts.<br>
<br>
Also, if Geoff's copy propagation pass is invoked post-RA wouldn't it need to handle the x86 ISA feature which allows 8 bit/16 bit values to be moved into a register without over-writing the other bits in the register being defined? I am assuming this needs
 to be handled for this pass to work for x86. Is this part of Geoff's patch?<br>
<br>
I have seen cases where we need copy propagation across basic blocks. Given that RDF works on the whole function, would it not be a good idea to just use that with the X86 partial-definition issue being handled?<br>
<br>
Considering everything, would the following not be a good approach?<br>
<br>
1) Use the isRenamable() change for MachineOperand which allows us to adhere to ABI/ISA constraints<br>
2) Fix the partial register definition issues as seen in x86<br>
3) Try to get the RDF based analysis and copy propagation and other passes built on RDF to work for all targets including x86 (we get the advantage of passes which can work on the whole machine function assuming that there are no scalability issues by doing
 so).<br>
<br>
I myself implemented a rudimentary copy propagation pass which tries to copy propagate on the whole machine function but was put off from doing further work on this because of the X86 partial definition issue mentioned above to which Krzysztof drew my attention.<br>
<br>
Regards,<br>
Venu.<br>
<br>
-----Original Message-----<br>
From: Geoff Berry [mailto:<a href="mailto:gberry@codeaurora.org" target="_blank">gberry@codeaurora.org</a>]<br>
Sent: Tuesday, October 31, 2017 8:33 PM<br>
To: <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>; Raghavan, Venugopal <<a href="mailto:Venugopal.Raghavan@amd.com" target="_blank">Venugopal.Raghavan@amd.com</a>><br>
Subject: Re: [llvm-dev] Reaching definitions on Machine IR post register allocation<br>
<br>
Hi Venu,<br>
<br>
FWIW, I have a pass that does copy propagation after RA [1] (currently only within a basic block) that should be enabled some time in the not-too-distant future.  It has been reviewed and accepted, but I'm currently working on getting a slight change to the
 MachineOperand representation [2] that should make the copy propagation change much simpler.  I believe this change to MachineOperand (or something like it) would also be needed for any pass that wants to rename registers after RA (unless the renaming is done
 right after RA when virtual registers are still present, which is what my current patch does, and is the source of complexity that I'm trying to eliminate).<br>
<br>
[1] <a href="https://reviews.llvm.org/D30751" target="_blank">https://reviews.llvm.org/D30751</a><br>
[2] <a href="https://reviews.llvm.org/D39400" target="_blank">https://reviews.llvm.org/D39400</a> D39400 WIP: [MachineOperand][MIR] Add isRenamable to MachineOperand.<br>
        <br>
On 10/31/2017 5:49 AM, Raghavan, Venugopal via llvm-dev wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<p class="MsoNormal" style="margin-bottom:12.0pt">Hi Krzysztof,<br>
<br>
Thanks a lot for taking the time to write a detailed explanation. I<br>
think I understand things better now.<br>
<br>
I am trying to see if I can use RDF for X86 assuming I can add more<br>
register units for X86 so that the partial re-definition issue you<br>
pointed earlier is fixed. I am not yet sure whether it is easy or not,<br>
but I have identified a portion of code in TableGen which I can modify<br>
to do this.<br>
<br>
Once I have done this I plan to use the RDG graph construction and RDF<br>
copy propagation code to try to propagate copies in the code after RA.<br>
<br>
I am hoping that this plan would work.<br>
<br>
Regards,<br>
<br>
Venu.<br>
<br>
From: *Krzysztof Parzyszek via llvm-dev* <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>><br>
Date: Mon, Oct 30, 2017 at 7:25 PM<br>
Subject: Re: [llvm-dev] Reaching definitions on Machine IR post<br>
register allocation<br>
To: <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
<br>
<br>
Hi Raghavan,<br>
Thanks for asking the questions, it's not a problem at all.<br>
<br>
The RDF graph simulates SSA. It does so by having "artificial" PHI<br>
nodes that account for multiple reaching defs.<br>
<br>
Consider this example (for Hexagon). The CFG is a simple triangle<br>
which has a split block (BB#0), which either goes to the side block<br>
(BB#1), or to the join block (BB#2). The register R0 is defined in<br>
BB#0 and then redefined in BB#1. Both definitions can reach the use of R0 in BB#2:<br>
<br>
<br>
***<br>
Before Hexagon RDF optimizations<br>
# Machine code for function fred: IsSSA, NoPHIs, TracksLiveness,<br>
NoVRegs<br>
<br>
BB#0:<br>
      Live Ins: %P0<br>
          %R0<def> = IMPLICIT_DEF<br>
          J2_jumpt %P0, <BB#2>, %PC<imp-def>  ; Conditional branch to<br>
BB#2<br>
      Successors according to CFG: BB#1 BB#2<br>
<br>
BB#1:<br>
      Predecessors according to CFG: BB#0<br>
          %R0<def> = IMPLICIT_DEF<br>
      Successors according to CFG: BB#2<br>
<br>
BB#2:<br>
      Live Ins: %R0<br>
      Predecessors according to CFG: BB#0 BB#1<br>
          %R1<def> = COPY %R0<br>
***<br>
<br>
The constructed graph is below. Note the phi node (p17) in BB#2:<br>
<br>
Starting copy propagation on: fred<br>
DFG dump:[<br>
f1: Function: fred<br>
b2: --- BB#0 --- preds(0):   succs(2): BB#1, BB#2<br>
p15: phi [+d16<P0>(,,u7):]<br>
s3: IMPLICIT_DEF [d4<R0>(,d10,u19):]<br>
s5: J2_jumpt BB#2 [/+d6<PC>!(,,):, u7<P0>(+d16):]<br>
<br>
b8: --- BB#1 --- preds(1): BB#0  succs(1): BB#2<br>
s9: IMPLICIT_DEF [d10<R0>(d4,,u20):]<br>
<br>
b11: --- BB#2 --- preds(2): BB#0, BB#1  succs(0):<br>
p17: phi [+d18<R0>(,,u14):, u19<R0>(d4,b2):, u20<R0>(d10,b8):]  ;<br>
*PHI*<br>
s12: COPY [d13<R1>(,,):, u14<R0>(+d18):]<br>
<br>
]<br>
<br>
<br>
The phi node has uses which are linked to the reaching defs, and<br>
paired with the predecessor block to which the def corresponds. At<br>
this point, the graph looks a lot like the standard SSA graph.<br>
<br>
<br>
There are cases where there are multiple reaching defs emerging in a<br>
straight-line code. Imagine a register BIG_REG that has two<br>
non-overlapping subregisters, SMALL_REG_1 and SMALL_REG_2. Now,<br>
consider<br>
this:<br>
<br>
SMALL_REG_1 = ...<br>
SMALL_REG_2 = ...<br>
... = BIG_REG<br>
<br>
Both of the preceding definitions of of the subregisters of BIG_REG<br>
reach the use of BIG_REG, and both of them have to be connected to the<br>
use somehow. Phi nodes are not the solution, since they are specific<br>
to join blocks in the control flow graph. What RDF does is that it<br>
adds additional uses of BIG_REG, and each of them has a different<br>
reaching def. These uses are called "shadows" in the RDF terminology.<br>
<br>
A concrete example (from Hexagon again, D0 is a pair of registers R0<br>
and R1). Note the two uses u9 and u10 in the COPY instruction, and<br>
that each of them has one of the preceding defs as its reaching def:<br>
<br>
Before Hexagon RDF optimizations<br>
# Machine code for function fred: IsSSA, NoPHIs, TracksLiveness,<br>
NoVRegs<br>
<br>
BB#0:<br>
          %R0<def> = IMPLICIT_DEF<br>
          %R1<def> = IMPLICIT_DEF<br>
          %D1<def> = COPY %D0<br>
<br>
# End machine code for function fred.<br>
<br>
Starting copy propagation on: fred<br>
DFG dump:[<br>
f1: Function: fred<br>
b2: --- BB#0 --- preds(0):   succs(0):<br>
s3: IMPLICIT_DEF [d4<R0>(,,u10"):]<br>
s5: IMPLICIT_DEF [d6<R1>(,,u9"):]<br>
s7: COPY [d8<D1>(,,):, u9"<D0>(d6):, u10"<D0>(d4):] ;; Two uses: u9,<br>
u10<br>
<br>
]<br>
<br>
<br>
<br>
In the example above, the fact that the two subregisters were<br>
non-overlapping was important. If they are non-overlapping, there<br>
won't be any data-flow links between them, since they are essentially<br>
independent registers. If they were overlapping, such links would be<br>
present. Here's a modified version of the example above, where we<br>
first modify D0, then one of its subregisters, and then read the whole D0:<br>
<br>
Before Hexagon RDF optimizations<br>
# Machine code for function fred: IsSSA, NoPHIs, TracksLiveness,<br>
NoVRegs<br>
<br>
BB#0:<br>
          %D0<def> = IMPLICIT_DEF<br>
          %R1<def> = IMPLICIT_DEF<br>
          %D1<def> = COPY %D0<br>
<br>
# End machine code for function fred.<br>
<br>
Starting copy propagation on: fred<br>
DFG dump:[<br>
f1: Function: fred<br>
b2: --- BB#0 --- preds(0):   succs(0):<br>
s3: IMPLICIT_DEF [d4<D0>(,d6,):]<br>
s5: IMPLICIT_DEF [d6<R1>(d4,,u9):]<br>
s7: COPY [d8<D1>(,,):, u9<D0>(d6):]<br>
<br>
]<br>
<br>
<br>
This time, the use of D0 only has the immediately preceding def of R1,<br>
and that def is then linked to the preceding def of D0.<br>
<br>
<br>
Before I describe how to get the reaching defs from the graph, let me<br>
point out that there is a function "getAllReachingDefs" in<br>
RDFLiveness.cpp that for a given RefNode returns the vector of all<br>
reaching defs from the same block in the order in which they would be<br>
encountered going backwards from the RefNode to the beginning of the<br>
basic block. That function will only return defs from the same basic<br>
block as the RefNode is in. This function was meant to hide the<br>
complexity of finding reaching defs "by hand", and is the preferred<br>
way of getting reaching defs.<br>
<br>
Now, to get all reaching defs for a given use or def, you need to<br>
follow the "reaching-def" link up in the graph, possibly multiple<br>
times, until the set of registers associated with these reaching defs<br>
covers the register from the use/def that you started from. In the<br>
last example, there is a use of D0, and the reaching def is d6, which<br>
is associated with R1. The set {R1} does not cover D0, so you'd need<br>
to go further up, to the reaching def of d6. That def (d4) defines D0,<br>
so now the set of registers is {R1,D0}, which completely covers D0, so<br>
the algorithm<br>
stops: the list of reaching defs is d6, d4.<br>
All of that work is done by getAllReachingDefs, together with handling<br>
shadows and all other necessary cases.<br>
<br>
<br>
The "isPreserving" flag has more to do with making sure that all<br>
necessary links are present in the graph. The idea is that the entire<br>
data flow is completely represented via the links, and so the exact<br>
semantics of the machine instructions does not need to be known.<br>
If you have two definitions of the same register following one<br>
another, and the first one does not reach any uses, it may be considered "dead"<br>
by looking at the data-flow links alone. If the second one is<br>
predicated, it may or may not happen, and so the preceding def is not<br>
guaranteed to be dead (and cannot be removed). In other words, it can<br>
"preserve" the original value (or, in general, one or more bits of the<br>
original value), hence the name. I don't think that it's necessary to<br>
have that flag anymore (i.e. RDF can be modified to work without it),<br>
but there are some historical reasons why it was introduced.<br>
<br>
-Krzysztof<br>
<br>
<br>
<br>
<br>
On 10/30/2017 4:13 AM, Raghavan, Venugopal via llvm-dev wrote:<br>
<br>
     Hi Krzysztof,<br>
<br>
     I am returning to this thread after a gap in time. I took some time<br>
     to study the code in RDFGraph.cpp in the Hexagon directory.<br>
<br>
     I have a few questions. I hope you will not find it too much of a<br>
     bother to answer them.<br>
<br>
     1) Does use node only support a single reaching def? If the RDF<br>
     graph is constructed post-RA, the code is no longer in SSA form and<br>
     is it not possible that multiple reaching defs reach a use node? For<br>
     example, the same physical register RAX may be defined in the if<br>
     branch and the else branch and can reach a common use node resulting<br>
     in multiple reaching defs for a use node. How is this handled?<br>
     2) I am unable to locate the code that handles re-definition of the<br>
     same register. I though "clobber" refers to such situations but the<br>
     isClobbering() function which controls the setting of the<br>
     "Clobbering" attribute seems to mainly handle function calls and not<br>
     the re-definitions of registers through other types of instructions.<br>
     How are such re-definitions handled?<br>
     3) My mental picture of reaching definitions analysis is the<br>
     classical iterative data flow analysis approach which involves using<br>
     the union operator as the join operator for the data flow<br>
     information, but I do not see anything in the code that corresponds<br>
     to such a notion. I am obviously way off the mark here, so, can you<br>
     briefly explain the idea behind the reaching definitions analysis in<br>
     the RDF code?<br>
     4) Assuming I have somehow fixed the register units issue for x86<br>
     (which you mentioned in a previous reply)  in the TableGen code by<br>
     adding extra register units for x86, I am not sure how the<br>
     preservation of the previous defined value through a partial<br>
     over-write by a sub-register definition is handled in the RDF code.<br>
     I looked at the isPreserving() function but that function seems to<br>
     check whether the instruction is predicated or not which is a little<br>
     confusing to me since the x86 case can create preservation of bits<br>
     through non-predicated partial over-writes. So, how is the x86<br>
     situation handled?<br>
<br>
     I realize that I have asked too many questions, but, I hope you can<br>
     briefly provide me some clarifications.<br>
<br>
     Thanks.<br>
<br>
     Regards,<br>
     Venugopal Raghavan.<br>
<br>
     -----Original Message-----<br>
     From: <a href="mailto:qcolombet@apple.com" target="_blank">qcolombet@apple.com</a> <mailto:<a href="mailto:qcolombet@apple.com" target="_blank">qcolombet@apple.com</a>><br>
     [mailto:<a href="mailto:qcolombet@apple.com" target="_blank">qcolombet@apple.com</a> <mailto:<a href="mailto:qcolombet@apple.com" target="_blank">qcolombet@apple.com</a>>]<br>
     Sent: Tuesday, September 12, 2017 11:31 PM<br>
     To: Raghavan, Venugopal <<a href="mailto:Venugopal.Raghavan@amd.com" target="_blank">Venugopal.Raghavan@amd.com</a><br>
     <mailto:<a href="mailto:Venugopal.Raghavan@amd.com" target="_blank">Venugopal.Raghavan@amd.com</a>>><br>
     Cc: <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
     Subject: Re: [llvm-dev] Reaching definitions on Machine IR post<br>
     register allocation<br>
<br>
     Hi Venu,<br>
<br>
         On Sep 11, 2017, at 11:00 PM, Raghavan, Venugopal via llvm-dev<br>
         <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>> wrote:<br>
<br>
         Hi Krzysztof,<br>
<br>
         Thanks for your reply.<br>
<br>
         I agree that adding extra register units for x86 would be the<br>
         right way to fix this. Do you know if there is a plan to fix this?<br>
<br>
<br>
     No concrete plan, no. We've been thinking about for quite some time<br>
     now, but never got at it.<br>
<br>
     Cheers,<br>
     -Quentin<br>
<br>
<br>
         The case that you have pointed out involving partial writes to a<br>
         register together completely killing a wider register is<br>
         interesting and did not occur to me. But, for reaching<br>
         definitions, even if you do not detect this case, shouldn't this<br>
         be safe (although conservative) since you would only end up<br>
         over-estimating the set of reaching definitions at a point?<br>
<br>
         But for other scenarios such as copy propagation, you may need<br>
         to detect this scenario because otherwise you could assume that<br>
         a copy reaches a use point (when it actually does not) and you<br>
         may end up propagating the copy when it is incorrect to do so.<br>
<br>
         Regards,<br>
         Venu.<br>
<br>
<br>
         -----Original Message-----<br>
         From: llvm-dev [mailto:<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a><br>
         <mailto:<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>>] On Behalf Of<br>
         Krzysztof Parzyszek via llvm-dev<br>
         Sent: Friday, September 8, 2017 7:10 PM<br>
         To: <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
         Subject: Re: [llvm-dev] Reaching definitions on Machine IR post<br>
         register allocation<br>
<br>
         It would be much easier to add extra reg units to EAX, EBX, etc.<br>
         to represent the upper half of the register. That would fix the<br>
         issue the right way (and would actually make sense without the<br>
         context of RDF).<br>
<br>
         Regarding the sub-register check---consider this case:<br>
<br>
             AX = ...<br>
             ...<br>
             AL = ...  // AX partially overwritten<br>
             AH = ...  // AX completely overwritten<br>
<br>
         Each of the assignments to AL/AH does not overwrite AX by<br>
         itself, but together they do. This would be very difficult to<br>
         detect if we added such special treatment of sub-registers that<br>
         you propose.<br>
<br>
         I could try to make a case for the extra register units to get<br>
         them added.<br>
<br>
         -Krzysztof<br>
<br>
<br>
         On 9/8/2017 1:55 AM, Raghavan, Venugopal via llvm-dev wrote:<br>
<br>
             Hi Krzysztof,<br>
<br>
             Thanks for your explanation - I think I understand the issue<br>
             now.<br>
<br>
             I do know if this is a hack, but, in reaching definitions,<br>
             when we check if a definition of AX kills a previous<br>
             definition of EAX, can we not check the actual physical<br>
             register? In this case since EAX and AX are different<br>
             (although I understand AX is a sub-register of EAX), can we<br>
             not conclude that the definition of AX does not kill EAX?<br>
             Since, in reaching definitions, it is conservative if we<br>
             over-estimate the set of reaching definitions (but not<br>
             unsafe), should not this strategy be adequate to avoid<br>
             incorrect optimizations?<br>
<br>
             Or, is there an optimization that can behave incorrectly<br>
             with an overestimated set of reaching definitions?<br>
<br>
             Regards,<br>
             Venu.<br>
<br>
             -----Original Message-----<br>
             From: Nema, Ashutosh<br>
             Sent: Friday, September 08, 2017 12:00 PM<br>
             To: Raghavan, Venugopal <<a href="mailto:Venugopal.Raghavan@amd.com" target="_blank">Venugopal.Raghavan@amd.com</a><br>
             <mailto:<a href="mailto:Venugopal.Raghavan@amd.com" target="_blank">Venugopal.Raghavan@amd.com</a>>><br>
             Subject: FW: [llvm-dev] Reaching definitions on Machine IR post<br>
             register allocation<br>
<br>
<br>
<br>
             -----Original Message-----<br>
             From: llvm-dev [mailto:<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a><br>
             <mailto:<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>>] On Behalf Of<br>
             Krzysztof Parzyszek via llvm-dev<br>
             Sent: Wednesday, September 6, 2017 6:10 PM<br>
             To: <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
             Subject: Re: [llvm-dev] Reaching definitions on Machine IR post<br>
             register allocation<br>
<br>
             RDF needs to know when an assignment to a register is<br>
             overwritten by another assignment, or by a sequence of<br>
             assignments.  This is needed to determine whether the<br>
             original assignment is still live or not. RDF uses register<br>
             units to represent the building blocks of registers, and<br>
             assumes that if all units of a register are overwritten,<br>
             then the original value of that register is completely<br>
             overwritten. This assumption is true for all targets (that I<br>
             have tested it with) except X86. On X86, registers AX and<br>
             EAX both have only one register unit, but when you assign a<br>
             value to AX, the upper half of EAX is preserved (that is,<br>
             the original value of EAX is not completely overwritten).<br>
<br>
             -Krzysztof<br>
<br>
             On 9/6/2017 6:42 AM, Raghavan, Venugopal via llvm-dev wrote:<br>
<br>
                 Hi Krzysztof,<br>
<br>
                 I did look at the other link you have mentioned in your<br>
                 reply but did not quite understand the register units<br>
                 issue. If it is not too difficult, can you briefly<br>
                 summarize what the issue was?<br>
<br>
                 Thanks.<br>
<br>
                 Regards,<br>
                 Venu.<br>
<br>
<br>
                 -----Original Message-----<br>
                 From: llvm-dev [mailto:<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a><br>
                 <mailto:<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>>] On Behalf Of<br>
                 Krzysztof Parzyszek via llvm-dev<br>
                 Sent: Tuesday, September 5, 2017 7:44 PM<br>
                 To: <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
                 Subject: Re: [llvm-dev] Reaching definitions on Machine<br>
                 IR post<br>
                 register allocation<br>
<br>
                 Hexagon has RDF that does exactly that.  At the moment<br>
                 it's under lib/Target/Hexagon, but it meant to be<br>
                 target-independent.  It won't work with X86 due to a<br>
                 known issue related to register units, but it should<br>
                 work fine for other targets.  See<br>
                 <a href="https://reviews.llvm.org/D29295" target="_blank">https://reviews.llvm.org/D29295</a> about moving it to<br>
                 lib/CodeGen.<br>
<br>
                 -Krzysztof<br>
<br>
                 On 9/4/2017 9:00 AM, Raghavan, Venugopal via llvm-dev wrote:<br>
<br>
                     Hi,<br>
<br>
                     Just to clarify I am looking for a whole machine<br>
                     function analysis<br>
                     not just something restricted to within a machine<br>
                     basic block.<br>
<br>
                     Thanks.<br>
<br>
                     Regards,<br>
<br>
                     Venu.<br>
<br>
                     *From:* Raghavan, Venugopal<br>
                     *Sent:* Saturday, September 02, 2017 12:56 PM<br>
                     *To:* <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">
llvm-dev@lists.llvm.org</a><br>
                     <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
                     *Subject:* Reaching definitions on Machine IR post<br>
                     register<br>
                     allocation<br>
<br>
                     Hi,<br>
<br>
                     Given a definition of a register by a machine<br>
                     instruction in the<br>
                     Machine IR post register allocation, I would like to<br>
                     compute the<br>
                     set of uses of this register reached by this definition.<br>
<br>
                     Does LLVM already have this kind of analysis I can<br>
                     use? Otherwise,<br>
                     I will have to implement a reaching definitions<br>
                     analysis which<br>
                     would be a little involved since it would need to<br>
                     work on a non-SSA IR form.<br>
<br>
                     If something already exists that would be very<br>
                     helpful for me.<br>
<br>
                     Thanks.<br>
<br>
                     Regards,<br>
<br>
                     Venugopal Raghavan.<br>
<br>
<br>
<br>
                     _______________________________________________<br>
                     LLVM Developers mailing list<br>
                     <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
                     <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br>
<br>
                 --<br>
                 Qualcomm Innovation Center, Inc. is a member of Code<br>
                 Aurora Forum,<br>
                 hosted by The Linux Foundation<br>
                 _______________________________________________<br>
                 LLVM Developers mailing list<br>
                 <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
                 <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
                 _______________________________________________<br>
                 LLVM Developers mailing list<br>
                 <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
                 <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br>
<br>
             --<br>
             Qualcomm Innovation Center, Inc. is a member of Code Aurora<br>
             Forum,<br>
             hosted by The Linux Foundation<br>
             _______________________________________________<br>
             LLVM Developers mailing list<br>
             <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
             <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
             _______________________________________________<br>
             LLVM Developers mailing list<br>
             <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
             <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br>
<br>
         --<br>
         Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,<br>
         hosted by The Linux Foundation<br>
         _______________________________________________<br>
         LLVM Developers mailing list<br>
         <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
         <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
         _______________________________________________<br>
         LLVM Developers mailing list<br>
         <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
         <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br>
<br>
     _______________________________________________<br>
     LLVM Developers mailing list<br>
     <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
     <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br>
<br>
--<br>
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,<br>
hosted by The Linux Foundation<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br>
<br>
_______________________________________________<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="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></p>
</blockquote>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
--<br>
Geoff Berry<br>
Employee of Qualcomm Datacenter Technologies, Inc.<br>
   Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.  Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.<br>
_______________________________________________<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="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></p>
</blockquote>
<p class="MsoNormal"><br>
-- <br>
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</body>
</html>