<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: arial,helvetica,sans-serif; font-size: 10pt; color: #000000'><br><hr id="zwchr"><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><b>From: </b>"Dehao Chen" <dehao@google.com><br><b>To: </b>"Hal Finkel" <hfinkel@anl.gov><br><b>Cc: </b>"llvm-dev" <llvm-dev@lists.llvm.org>, "Xinliang David Li" <davidxl@google.com><br><b>Sent: </b>Tuesday, November 1, 2016 8:24:30 PM<br><b>Subject: </b>Re: [llvm-dev] (RFC) Encoding code duplication factor in discriminator<br><br><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 1, 2016 at 5:56 PM, Hal Finkel <span dir="ltr"><<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt; color: rgb(0, 0, 0);"><br><hr id="gmail-m_-810890770938607349zwchr"><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: helvetica,arial,sans-serif; font-size: 12pt;"><span class="gmail-"><b>From: </b>"Dehao Chen" <<a href="mailto:dehao@google.com" target="_blank">dehao@google.com</a>><br><b>To: </b>"Hal Finkel" <<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>><br></span><span class="gmail-"><b>Cc: </b>"llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>, "Xinliang David Li" <<a href="mailto:davidxl@google.com" target="_blank">davidxl@google.com</a>><br></span><b>Sent: </b>Tuesday, November 1, 2016 6:41:29 PM<div><div class="gmail-h5"><br><b>Subject: </b>Re: [llvm-dev] (RFC) Encoding code duplication factor in discriminator<br><br><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 1, 2016 at 2:36 PM, Hal Finkel <span dir="ltr"><<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt; color: rgb(0, 0, 0);"><br><hr id="gmail-m_-810890770938607349gmail-m_-1572076769796879342m_-1389974181502797381zwchr"><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: helvetica,arial,sans-serif; font-size: 12pt;"><b>From: </b>"Hal Finkel via llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br><b>To: </b>"Dehao Chen" <<a href="mailto:dehao@google.com" target="_blank">dehao@google.com</a>><br><b>Cc: </b>"llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>, "Xinliang David Li" <<a href="mailto:davidxl@google.com" target="_blank">davidxl@google.com</a>><br><b>Sent: </b>Tuesday, November 1, 2016 4:26:17 PM<span><br><b>Subject: </b>Re: [llvm-dev] (RFC) Encoding code duplication factor in discriminator<br><br>
<div id="gmail-m_-810890770938607349gmail-m_-1572076769796879342m_-1389974181502797381DWT18126" style="font-family: arial,helvetica,sans-serif; font-size: 10pt; color: rgb(0, 0, 0);"><br><hr id="gmail-m_-810890770938607349gmail-m_-1572076769796879342m_-1389974181502797381zwchr"><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: helvetica,arial,sans-serif; font-size: 12pt;"><b>From: </b>"Dehao Chen" <<a href="mailto:dehao@google.com" target="_blank">dehao@google.com</a>><br><b>To: </b>"Hal Finkel" <<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>><br><b>Cc: </b>"Paul Robinson" <<a href="mailto:paul.robinson@sony.com" target="_blank">paul.robinson@sony.com</a>>, "Xinliang David Li" <<a href="mailto:davidxl@google.com" target="_blank">davidxl@google.com</a>>, "llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br><b>Sent: </b>Tuesday, November 1, 2016 4:14:43 PM<br><b>Subject: </b>Re: [llvm-dev] (RFC) Encoding code duplication factor in discriminator<br><br><div dir="ltr">damn... my english is not readable at all when I try to write fast... trying to make some clarification below, hopefully can make it more readable...<div class="gmail_extra"><br><div id="gmail-m_-810890770938607349gmail-m_-1572076769796879342m_-1389974181502797381DWT18125" class="gmail_quote">On Tue, Nov 1, 2016 at 2:07 PM, Dehao Chen <span dir="ltr"><<a href="mailto:dehao@google.com" target="_blank">dehao@google.com</a>></span> wrote:<br><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">Oops... pressed the wrong button and sent out early...<div class="gmail_extra"><br><div class="gmail_quote"><span class="gmail-m_-810890770938607349gmail-m_-1572076769796879342m_-1389974181502797381gmail-">On Tue, Nov 1, 2016 at 2:01 PM, Dehao Chen <span dir="ltr"><<a href="mailto:dehao@google.com" target="_blank">dehao@google.com</a>></span> wrote:<br><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">If Hal's proposal is for SamplePGO purpose, let me clarify some design principles of SamplePGO.<div><br></div><div>The profile for sample pgo uses source location as the key to map the execution count back to IR. This design is based on the principle that we do not want the profile to be tightly couple with compiler IR. Instead, profile is simple an attribute of the source code. We have been benefited  a lot from this design that the profile can easily be reused across different source versions and compiler versions, or even compilers.</div><div><br></div><div>That being said, the design to encode more info into discriminator does not mean that we will change the profile. The encoded info in discriminator will be handled by the create_llvm_prof tool, which combines counts from different clones of the same source code and generate the combined profile data. The output profile will not have any cloning/dupliaction bits at all. So for the initial example profile I provided, the output profile will be:</div></div></blockquote><div><br></div></span><div style="font-size: 12.8px;">#1: 10</div><div><span style="font-size: 12.8px;">#3: 80</span></div><div><br></div><div>Not:</div><div><br></div><div>#1: 10</div><div>#3.0x400: 70<br></div><div>#3.0x10400: 5</div><div>#3.0x20400: 3</div><div id="gmail-m_-810890770938607349gmail-m_-1572076769796879342m_-1389974181502797381DWT18124">#3.0x30400: 2<br></div></div></div></div></blockquote><br></div></div></div></blockquote></div></span></blockquote>Also, how does this work for vectorization? For vectorization, you're going to multiply by the duplication factor first? The issue obviously is that each vector instruction counts for VF times as many scalar instructions, and so to get equivalent scalar counts, you need to multiply by VF. I had assumed this is what you were saying when I read the initial e-mail, but if you're also using the same duplication scheme for unrolling, then I think we need some way to differentiate.</div></div></blockquote><div><br></div><div id="gmail-m_-810890770938607349DWT24637">In my original proposal, I only record VF*UF if the clone is both unrolled and vectorized. I did not distinguish between unroll and vectorization because I the unroll/vectorize decision only depends on the trip count, which can be derived from the duplication factor. If more profile info can be used for better unroll/vectorize decision making, we can definitely add it.</div></div></div></div></div></div></blockquote>I'm still missing something here. In your proposed system, does the tool collecting the profiling information *interpret* the duplication factor encoded in the descriminators at all?</div></div></blockquote><div><br></div><div id="DWT1034">Yes it does.</div></div></div></div></blockquote>Okay. I'm still missing something. Can you please write out an example using your notation below for a vectorized loop?<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt; color: rgb(0, 0, 0);"> If it does, it seems like this should be specific to vectorization. For unrolling, you still have the same number of instructions, and so you just need to make the different instructions from the different loop iterations carry different discriminator values (so they they'll sum together, instead of using the maximum, as you explained in your original proposal).</div></div></blockquote><div><br></div><div>Let's take a look at the original loop unroll example. My proposed discriminator assignment is: </div><div><div style="font-size: 12.8px;">for (i = 0; i < N & 3; i+= 4) {</div><div style="font-size: 12.8px;">  foo();  // discriminator: 0x400</div><div style="font-size: 12.8px;">  foo();  // discriminator: 0x400</div><div style="font-size: 12.8px;">  foo();  // discriminator: 0x400</div><div style="font-size: 12.8px;">  foo();  // discriminator: 0x400</div><div style="font-size: 12.8px;">}</div><div style="font-size: 12.8px;">if (i++ < N) {</div><div style="font-size: 12.8px;">  foo();   // discriminator: 0x10000</div><div style="font-size: 12.8px;">  if (i++ < N) {</div><div style="font-size: 12.8px;">    foo(); // discriminator: 0x20000</div><div style="font-size: 12.8px;">    if (i++ < N) {</div><div style="font-size: 12.8px;">      foo();  // discriminator: 0x30000</div><div style="font-size: 12.8px;">    }</div><div style="font-size: 12.8px;">  }</div><div style="font-size: 12.8px;">}</div></div><div style="font-size: 12.8px;"><br></div><div id="DWT1026" style="font-size: 12.8px;">IIRC, your proposed discriminator assignment is:</div></div></div></div></blockquote>To be clear, I don't think that I've proposed any assignment scheme at all. Regardless, I was asking this question purely in the context of your proposal.<br><br>Thanks again,<br>Hal<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div style="font-size: 12.8px;"></div><div style="font-size: 12.8px;"><br></div><div style="font-size: 12.8px;"><div style="font-size: 12.8px;">for (i = 0; i < N & 3; i+= 4) {</div><div style="font-size: 12.8px;">  foo();  // discriminator: 0x10000</div><div style="font-size: 12.8px;">  foo();  // discriminator: 0x20000</div><div style="font-size: 12.8px;">  foo();  // discriminator: 0x30000</div><div style="font-size: 12.8px;">  foo();  // discriminator: 0x40000</div><div style="font-size: 12.8px;">}</div><div style="font-size: 12.8px;">if (i++ < N) {</div><div style="font-size: 12.8px;">  foo();   // discriminator: 0x50000</div><div style="font-size: 12.8px;">  if (i++ < N) {</div><div style="font-size: 12.8px;">    foo(); // discriminator: 0x60000</div><div style="font-size: 12.8px;">    if (i++ < N) {</div><div style="font-size: 12.8px;">      foo();  // discriminator: 0x70000</div><div style="font-size: 12.8px;">    }</div><div style="font-size: 12.8px;">  }</div><div style="font-size: 12.8px;">}</div><div style="font-size: 12.8px;"><br></div><div style="font-size: 12.8px;">I think my method can save discriminator space because all clones share the same discriminator. Consider that if a loop is unrolled 100 times, then with your algorithm, we may end up having 100 different discriminators, which seem not good for debug info size.</div></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt; color: rgb(0, 0, 0);"><span class="gmail-"><br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: helvetica,arial,sans-serif; font-size: 12pt;"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt; color: rgb(0, 0, 0);"><span class="gmail-m_-810890770938607349gmail-m_-1572076769796879342HOEnZb"><font color="#888888"><br><br> -Hal<br></font></span><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: helvetica,arial,sans-serif; font-size: 12pt;"><div><div class="gmail-m_-810890770938607349gmail-m_-1572076769796879342h5"><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt; color: rgb(0, 0, 0);"><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: helvetica,arial,sans-serif; font-size: 12pt;"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><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 class="gmail_extra"><div class="gmail_quote"><div></div><div><br></div><div>The goal of the proposed change, is to make profile more accurately represent the attribute of the source.</div><div>The non-goal of the proposed change, is to provide more context in the profile to present the behavior of program in the context of different context.</div></div></div></div></blockquote><div><br></div><div id="gmail-m_-810890770938607349gmail-m_-1572076769796879342m_-1389974181502797381DWT14535">The non-goal of the proposed change, is to provide more context in the profile to present the behavior of program in different contexts.'</div></div></div></div></blockquote>Okay, but why? The information will be present in the profiles, why not encode it in the metadata and let the optimizer decide when to sum it up? We should even provide some utility functions that make this transparent for passes that don't care about the distinction.<br></div></div></div></blockquote></div></div></blockquote><div>I see, you are proposing encoding these profile in the metadata. I agree that this can work, but from implementation's perspective, it could could lead to great complexity.</div><div><br></div><div id="gmail-m_-810890770938607349DWT24638">Sample PGO pass first read in the source->count map, use it to get basic_block->count map, and then use heuristics to propagate and get branch->probability count. So we don't have Metadata to store the raw count, but only the branch probability is stored after sample pgo pass. <br></div></div></div></div></blockquote></span>I think that, as you indicate below, we'd need to change this to {source, disc}->count map --> {BB, disc}->count map --> {branch, disc}->prob map. The idea being that the total probability for the branch is the sum of the probabilities associated with it for each discriminator value. Most users will just sum them up, but some passes will want the breakdowns.</div></div></blockquote><div><br></div><div>Agree. Note that this would add some complexity to BFI/BPI <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><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt; color: rgb(0, 0, 0);"><div><div class="gmail-h5"><br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: helvetica,arial,sans-serif; font-size: 12pt;"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt; color: rgb(0, 0, 0);"><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: helvetica,arial,sans-serif; font-size: 12pt;"><div><div class="gmail-m_-810890770938607349gmail-m_-1572076769796879342h5"><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt; color: rgb(0, 0, 0);"><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: helvetica,arial,sans-serif; font-size: 12pt;"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div> </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 class="gmail_extra"><div class="gmail_quote"><div><br></div><div>If we are pursuing more context-sensitive profile, that would be a very different design. In this design, we will need to read profile multiple times, and have the profile tightly coupled with the compiler IR/pass manager. That is doable, but I don't think that probably better suits instrumentation based PGO's domain. Comments?</div></div></div></div></blockquote><div><br></div><div id="gmail-m_-810890770938607349gmail-m_-1572076769796879342m_-1389974181502797381DWT14536">If we are pursuing more context-sensitive profile, that would be a very different design in which we need to read in profiles multiple times, and have the profile tightly coupled with the compiler IR/pass manager. That is doable, but that probably better suits instrumentation based PGO's domain. Comments? </div></div></div></div></blockquote>I don't understand why you say we'd need to read the profile multiple times. Can you please explain? I also don't think it needs to be that tightly coupled; we just need each pass that generates multiple copies of things to have some way to generate a unique id for what it's doing. It's all per source location, so I don't even think we need any kind of complicated hashing scheme.<br></div></div></div></blockquote></div></div></blockquote><div>As explained above, we only have branch probability. Yes, we can record more instruction/basicblock count context info in additional metadata. But when you use it in optimizer, I suppose you will need to convert it to branch probability too?</div><div><br></div><div>Let me take an example to demonstrate my understanding of your use of context-sensitive profile.</div><div><br></div><div>original code:</div><div>for ()</div><div>  stmt1;</div><div><br></div><div>optimized code:</div><div>if (cond1)</div><div>  for()</div><div>    stmt1;  //100 samples</div><div>else if (cond2)</div><div>  for()</div><div>    stmt1;  // 0 samples</div><div>else</div><div>  for()</div><div>    stmt1; // 50 samples</div><div><br></div><div>The loop was multi-versioned by cond1 and cond2. With my proposal, the profile for stmt1 will be combined as 150 samples. If we use this profile to optimize the orginal source, after annotation, the code becomes:</div><div><br></div><div>for()</div><div>  stmt1 // 150 samples</div><div><br></div><div>Later when it comes to the mulit-version optimization, it will transform the code to:<br></div><div><br></div><div><div>if (cond1)</div><div>  for()</div><div>    stmt1;  //50 samples</div><div>else if (cond2)</div><div>  for()</div><div>    stmt1;  // 50 samples</div><div>else</div><div>  for()</div><div>    stmt1; // 50 samples</div></div><div><br></div><div>The 150 samples are evenly distributed to 3 clones as we do not have context info.</div><div><br></div><div>With your proposal, after annotation, the original code becomes:</div><div><br></div><div><div>for()</div><div>  stmt1 // 150 samples (M1:100, M2:0, M3:50)</div></div><div><br></div><div>Then during mutli-version optimization, the optimizer reads the metadata and find M2 is never taken, so it will transform the code to:</div><div><br></div><div><div>if (cond1)</div><div>  for()</div><div>    stmt1;  // 100 samples</div><div>else<br></div><div>  for()</div><div>    stmt1; // 50 samples</div></div><div><br></div><div>There are two major parts that can benefit from the extra metadata recorded for each copy.</div><div><br></div><div>1. It can demonstrate that cond2 is always false and there is no need to create that version.</div><div>2. It can correctly attribute samples to cloned copy (i.e. 100, 50 respectively in this case)</div><div><br></div><div id="gmail-m_-810890770938607349DWT24640">I think the most important benefit is #1. For #2, my guess is scaled count is already good enough.</div></div></div></div></blockquote></div></div>By what are you scaling the count?</div></div></blockquote><div><br></div><div>It's random. Or most likely, each branch will be 50% taken.</div><div> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt; color: rgb(0, 0, 0);"><span class="gmail-"><br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: helvetica,arial,sans-serif; font-size: 12pt;"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div><br></div><div id="gmail-m_-810890770938607349DWT24639">Here comes the problem: cond1 and cond2 are both generated by compiler. Then how do we map the metadata back to them? Using uid or special encoding seems fragile because when upstream optimization changes, compiler may choose to put cond2 in front of cond1 so the uid will change accordingly. How would we handle cases like this?</div></div></div></div></blockquote></span>Exactly for this reason, I don't think we can rely on the ordering to generate the identifiers; they need to have semantic meaning. I agree that this is tricky in general. However, for the cases I have in mind (unrolling, vectorization, etc.) these passes don't generate arbitrary conditionals, but rather, specific conditionals related to runtime overlap checks, trip-count thresholds, and I think that it should be easy to encode a discriminator value which can be unambiguously inverted.<br></div></div></blockquote><div><br></div><div>I'm still not quite clear how to do this. Needs to think more thoroughly. But one thing I want to note is that, we want to encode the context info only when it will be useful for the optimization. For vectorization/unroll, I think accurate trip count is already good enough. So do we want to record its context?</div><div><br></div><div>Thanks,</div><div>Dehao</div><div> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt; color: rgb(0, 0, 0);"><br>Thanks again,<br>Hal<div><div class="gmail-h5"><br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: helvetica,arial,sans-serif; font-size: 12pt;"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div><br></div><div>Dehao</div><div><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><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt; color: rgb(0, 0, 0);"><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: helvetica,arial,sans-serif; font-size: 12pt;"><div><div class="gmail-m_-810890770938607349gmail-m_-1572076769796879342h5"><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt; color: rgb(0, 0, 0);"><br>Thanks again,<br>Hal<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: helvetica,arial,sans-serif; font-size: 12pt;"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></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 class="gmail_extra"><div class="gmail_quote"><div><br></div><div>Thanks,</div><div>Dehao</div><span class="gmail-m_-810890770938607349gmail-m_-1572076769796879342m_-1389974181502797381gmail-"><div><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><br></div></div><div class="gmail-m_-810890770938607349gmail-m_-1572076769796879342m_-1389974181502797381gmail-m_-1621770862889340260gmail-HOEnZb"><div class="gmail-m_-810890770938607349gmail-m_-1572076769796879342m_-1389974181502797381gmail-m_-1621770862889340260gmail-h5"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 1, 2016 at 1:04 PM, Hal Finkel <span dir="ltr"><<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt; color: rgb(0, 0, 0);"><br><hr id="gmail-m_-810890770938607349gmail-m_-1572076769796879342m_-1389974181502797381gmail-m_-1621770862889340260gmail-m_22964723159565198m_8666766791862472595zwchr"><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: helvetica,arial,sans-serif; font-size: 12pt;"><b>From: </b>"Paul Robinson" <<a href="mailto:paul.robinson@sony.com" target="_blank">paul.robinson@sony.com</a>><br><b>To: </b>"Dehao Chen" <<a href="mailto:dehao@google.com" target="_blank">dehao@google.com</a>>, "Hal Finkel" <<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>><br><b>Cc: </b>"Xinliang David Li" <<a href="mailto:davidxl@google.com" target="_blank">davidxl@google.com</a>>, <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br><b>Sent: </b>Tuesday, November 1, 2016 2:15:38 PM<br><b>Subject: </b>RE: [llvm-dev] (RFC) Encoding code duplication factor in        discriminator<span><br><br>




<div class="gmail-m_-810890770938607349gmail-m_-1572076769796879342m_-1389974181502797381gmail-m_-1621770862889340260gmail-m_22964723159565198m_8666766791862472595WordSection1">
<p class="MsoNormal" style="margin-left: 1in;"><span style="font-family: helvetica,sans-serif; color: black;">As illustrated in the above example, it is not like "vectorization has a distinct bit". All different optimizations make clones of code which will
 be labeled by UIDs represented by N (e.g. 8) bits. In this way, the space will be capped by the number of clones all optimizations have made, instead of # of optimizations that has applied. And it will be capped at 2^N-1. The cons of using uid is that you
 will not know if a clone is coming from vectorization or unroll or loop distribution.</span></p>
<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-size: 10pt; font-family: arial,sans-serif; color: black;">Okay, but that kind of semantic mapping is important. How should we encode/recover that information? To be clear, I'm not saying that we
 need to implement that up front, but there needs to be a clear path to an implementation, because I don't want to have two disjoint schemes.</span></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal" style="margin-left: 5.35pt;">You mean that you want to know which optimization created the clone? How would you use that info? Looks to me this will expose compiler implementation detail in debug info.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal" style="margin-left: 5.35pt;">This is still doable, assume we have 15 interesting optimizations to track, we can use 4 bits to encode the optimization type that created the clone. But this becomes nasty if the a clone is created by more than
 one optimizations. In that way, discriminator may not be fit for this purpose.</p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: calibri,sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><a name="m_-810890770938607349_m_-1572076769796879342_m_-1389974181502797381_m_-1621770862889340260_m_22964723159565198_m_8666766791862472595__MailEndCompose"><span style="font-size: 11pt; font-family: calibri,sans-serif; color: rgb(31, 73, 125);">My understanding was that the encoding scheme would allow the profiling analysis to correctly map execution data back to the original
 source construct, while preserving the property that each distinct basic block would have its own discriminator value.  That is, the execution data would be attributed back to the original source construct, not whatever each individual optimization had done
 to it, and the data for the original source construct would correctly reflect the execution (e.g. profiling says you got 82 hits on the original loop, rather than reporting 20 hits on the unrolled-by-4 loop plus 1 each on 2 of the trailing copies).</span></a></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: calibri,sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: calibri,sans-serif; color: rgb(31, 73, 125);">It sounds like Hal is thinking that the per-discriminator execution info would be preserved down to the point where an individual optimization could look at
 the profile for each piece, and make decisions on that basis.</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: calibri,sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: calibri,sans-serif; color: rgb(31, 73, 125);">I'm not clear how that would be possible, as the optimization would have to first do the transform (or predict how it would do the transform) in order to see
 which individual-discriminator counts mapped to which actual blocks, and then make some kind of decision about whether to do the transform differently based on that information.  Then, if the optimization did choose to do the transform differently, then that
 leaves the IR in a state where the individual discriminators *cannot* map back to it.  (Say you unroll by 2 instead of 4; then you have only 1 trailing copy, not 3, and a discriminator that maps to the second trailing copy now maps to nothing.  The individual-discriminator
 data becomes useless.)</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: calibri,sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span id="gmail-m_-810890770938607349gmail-m_-1572076769796879342m_-1389974181502797381gmail-m_-1621770862889340260gmail-m_22964723159565198m_8666766791862472595DWT9585" style="font-size: 11pt; font-family: calibri,sans-serif; color: rgb(31, 73, 125);">Am I expressing this well enough to show that what Hal is looking for is not feasible?</span></p></div></span></blockquote>Yes, it will need to predict how the transformation would affect the blocks produced. That does not seem problematic (at least at a coarse level). Yes, if transformations made earlier in the pipeline make different decisions, then that will invalidate later fine-grained data (at least potentially). I don't see how any of this makes this infeasible. We just need a way for the profiling counts, per descriminator, to remain available, and for the transformations themselves to know which discriminators (loop ids, or whatever) to consider.<br><br> -Hal<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: helvetica,arial,sans-serif; font-size: 12pt;"><div class="gmail-m_-810890770938607349gmail-m_-1572076769796879342m_-1389974181502797381gmail-m_-1621770862889340260gmail-m_22964723159565198m_8666766791862472595WordSection1"><p class="MsoNormal"><span style="font-size: 11pt; font-family: calibri,sans-serif; color: rgb(31, 73, 125);"></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: calibri,sans-serif; color: rgb(31, 73, 125);">--paulr</span></p>
<div style="border-width: medium medium medium 1.5pt; border-style: none none none solid; padding: 0in 0in 0in 4pt;">
<div>
<div>
<p class="MsoNormal"> </p>
</div>
</div>
</div>
</div>
</blockquote><span><br><br><br>-- <br><div><span></span>Hal Finkel<br>Lead, Compiler Technology and Programming Languages<br>Leadership Computing Facility<br>Argonne National Laboratory<span></span><br></div></span></div></div></blockquote></div><br></div>
</div></div></blockquote></span></div><br></div></div>
</blockquote></div><br></div></div>
</blockquote><br><br><br>-- <br><div><span></span>Hal Finkel<br>Lead, Compiler Technology and Programming Languages<br>Leadership Computing Facility<br>Argonne National Laboratory<span></span><br></div></div><br></div></div><span>_______________________________________________<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><br></span></blockquote><br><br><span><br>-- <br><div><span></span>Hal Finkel<br>Lead, Compiler Technology and Programming Languages<br>Leadership Computing Facility<br>Argonne National Laboratory<span></span><br></div></span></div></div></blockquote></div><br></div></div>
</blockquote><br><br><br>-- <br><div><span></span>Hal Finkel<br>Lead, Compiler Technology and Programming Languages<br>Leadership Computing Facility<br>Argonne National Laboratory<span></span><br></div></div></div></div></div></blockquote></div><br></div></div>
</blockquote><br><br><br>-- <br><div><span name="x"></span>Hal Finkel<br>Lead, Compiler Technology and Programming Languages<br>Leadership Computing Facility<br>Argonne National Laboratory<span name="x"></span><br></div></div></body></html>