<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=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 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;}
@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">(Re-adding llvm-commits)<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" style="margin-left:.5in">My idea was to remove the column and use the *scope* from the "if" iff "then" and "else" block are on the same line.<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">My misunderstanding, sorry… although the line table doesn't know about scopes so I'd think it would come down to the same thing.<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></a></p>
<p class="MsoNormal" style="margin-left:.5in">A better example that is more likely to appear on one line is the ternary ?: operator. In C++11 with lambdas you can also end up with a surprising amount of control flow condensed to a single line, though I can't
 think of a good example where tail-merging would apply.<o:p></o:p></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">Oh, something like 'return x ? foo(1) : foo(2);' would do it.  Setting up the parameters is disjoint but the actual call and passing back the return value would
 be a common tail.<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" style="margin-left:.5in">That said I understand this is a micro-optimization and perhaps not worth doing.<o:p></o:p></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">Yeah, I think we're all agreed on that point.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">--paulr<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 style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> aprantl@apple.com [mailto:aprantl@apple.com]
<br>
<b>Sent:</b> Wednesday, October 19, 2016 10:49 AM<br>
<b>To:</b> Robinson, Paul<br>
<b>Cc:</b> reviews+D25742+public+84a9fdd1c5228b3b@reviews.llvm.org; danielcdh@gmail.com; Pieb, Wolfgang<br>
<b>Subject:</b> Re: [PATCH] D25742: Remove debug location from common tail when tail-merging<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">On Oct 19, 2016, at 10:30 AM, Robinson, Paul <<a href="mailto:paul.robinson@sony.com">paul.robinson@sony.com</a>> wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div style="margin-left:.5in">
<p class="MsoNormal">Let me rephrase what I think you said in my own words and correct me at the point where I drift off.<o:p></o:p></p>
</div>
<div style="margin-left:.5in">
<p class="MsoNormal">The point of profiling is to assign weights to each basic block. When an instruction that exists in both a then and an else branch is sunk into their common successor block, and it would somehow keep both locations, then each time the instruction
 is executed, the counter for the then and the else block would be incremented simultaneously thus incorrectly increasing the weight of one of them each time.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">If we could manage to associate both locations with the same instruction, yes each hit would be attributed to both blocks (incorrectly).  Currently of course
 we associate only one location (arbitrarily picking one), so all hits are attributed to one block even if the execution was actually a result of the other block.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> </span><o:p></o:p></p>
</div>
<div style="margin-left:.5in">
<p class="MsoNormal">My proposal was to assign a new location to the common tail that keeps the source line, but uses the lexical scope of the parent block of the single-line if-then-else statement.<o:p></o:p></p>
</div>
<div style="margin-left:.5in">
<p class="MsoNormal">In a conversation I had with Dehao last week I learned that samplepgo, for example only identifies source locations by file/line/discriminator, so in order to make my proposal work with samplepgo, we would have to assign a new discriminator
 to the location of the common tail, because it doesn't look at scopes.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">This would clearly distinguish hits on the common tail versus hits on the original then/else blocks.  At best you could assign the hit to the 'if' as a whole
 but not to either of the then/else blocks.  Assuming the 'if' was itself in a nested block of some kind, this would ensure the hit was assigned somewhere useful.  I don't know whether the current sample analysis can assign the hit somewhere useful if we give
 the tail to line 0, as this patch (ultimately) wants to do.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">But I think we really *don't* want to assign the tail to the location of the 'if' unless the entire if/then/else is on a single line,</span><o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Sure, and I don't think anyone proposed this. My idea was to remove the column and use the *scope* from the "if" iff "then" and "else" block are on the same line.<o:p></o:p></p>
</div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">because that will mess up debugging.  And as David pointed out, single-line if/then/else is something of a special and unusual case, probably not worth addressing
 separately.</span><o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">A better example that is more likely to appear on one line is the ternary ?: operator. In C++11 with lambdas you can also end up with a surprising amount of control flow condensed to a single line, though I can't think of a good example
 where tail-merging would apply.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">That said I understand this is a micro-optimization and perhaps not worth doing.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">-- adrian<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</body>
</html>