<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jan 26, 2015 at 10:59 AM, Pete Cooper <span dir="ltr"><<a href="mailto:peter_cooper@apple.com" target="_blank">peter_cooper@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><div><div class="h5"><blockquote type="cite"><div>On Jan 26, 2015, at 10:30 AM, Chandler Carruth <<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>> wrote:</div><br><div><div class="gmail_quote" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br>On Mon, Jan 26, 2015 at 10:29 AM, Pete Cooper<span> </span><span dir="ltr"><<a href="mailto:peter_cooper@apple.com" target="_blank">peter_cooper@apple.com</a>></span><span> </span>wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div><div><blockquote type="cite"><div>On Jan 26, 2015, at 10:24 AM, Chandler Carruth <<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>> wrote:</div><br><div><div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jan 25, 2015 at 9:37 PM, Pete Cooper<span> </span><span dir="ltr"><<a href="mailto:peter_cooper@apple.com" target="_blank">peter_cooper@apple.com</a>></span><span> </span>wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="overflow:hidden">Hi hfinkel,<br><br>This teaches the constant folder that an llvm.expect intrinsic with a constant as the first operand will return that constant.<br><br>This reduces the size of an LTO'd llc by over 1% due to branches which can be removed once the constant is propagated.</div></blockquote></div><br></div><div class="gmail_extra">I really don't understand this.</div><div class="gmail_extra"><br></div><div class="gmail_extra">The design llvm.expect was specifically for LowerExpect to remove *all* of these intrinsics from the IR? Why isn't that working?</div></div></div></blockquote></div></div>Looks like LowerExpect is only added in populateFunctionPassManager, which is only called by clang, opt, and bug point.  There’s no call to this in llvm-lto.</div><div><br></div><div>I still think its worthwhile to constant fold expect as soon as possible as this patch does, but it looks like we also need that pass in the LTO pipeline.</div></blockquote></div><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">I really don't think it is. We should be running LowerExpect really early in every single pass pipeline because, as you saw, there are tons of passes we would have to teach about it otherwise. Not constant folding is, if anything, a nice way to flush these issues out.</span></div></blockquote></div></div>I see what you mean.  Personally I find that a bit gross that we have an intrinsic for this at all then.</div></div></blockquote><div><br></div><div>I kind-of do too... But at the time it went in, it was "hard" to connect these dots.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div>If anyone is curious, these are the passes 'opt -O2' runs up to LowerExpect.  So the SimplifyCFG here for example is possibly missing the opportunity to do some useful work because of the expects.</div></div></blockquote><div><br></div><div>Fortunately, we run simplify-cfg again at the start of the module pass manager.</div><div><br></div><div>The reason we do things in this order:</div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div><div style="margin:0px;font-size:11px;font-family:Menlo">Pass Arguments:  -datalayout -notti -basictti -x86tti -no-aa -tbaa -scoped-noalias -assumption-cache-tracker -targetlibinfo -basicaa -verify -simplifycfg -domtree -sroa -early-cse -lower-expect</div><div style="margin:0px;font-size:11px;font-family:Menlo">Data Layout</div><div style="margin:0px;font-size:11px;font-family:Menlo">No target information</div><div style="margin:0px;font-size:11px;font-family:Menlo">Target independent code generator's TTI</div><div style="margin:0px;font-size:11px;font-family:Menlo">X86 Target Transform Info</div><div style="margin:0px;font-size:11px;font-family:Menlo">No Alias Analysis (always returns 'may' alias)</div><div style="margin:0px;font-size:11px;font-family:Menlo">Type-Based Alias Analysis</div><div style="margin:0px;font-size:11px;font-family:Menlo">Scoped NoAlias Alias Analysis</div><div style="margin:0px;font-size:11px;font-family:Menlo">Assumption Cache Tracker</div><div style="margin:0px;font-size:11px;font-family:Menlo">Target Library Information</div><div style="margin:0px;font-size:11px;font-family:Menlo">Basic Alias Analysis (stateless AA impl)</div><div style="margin:0px;font-size:11px;font-family:Menlo">  FunctionPass Manager</div><div style="margin:0px;font-size:11px;font-family:Menlo">    Module Verifier</div><div style="margin:0px;font-size:11px;font-family:Menlo">    Simplify the CFG</div><div style="margin:0px;font-size:11px;font-family:Menlo">    Dominator Tree Construction</div><div style="margin:0px;font-size:11px;font-family:Menlo">    SROA</div><div style="margin:0px;font-size:11px;font-family:Menlo">    Early CSE</div><div style="margin:0px;font-size:11px;font-family:Menlo">    Lower 'expect' Intrinsics</div></div></div></blockquote><div><br></div><div>Is because 1) SROA isn't heavily impacted by expect intrinsics, and 2) we want simplify-cfg to have "normalized" the CFG enough to more easily attach the expect intrinsic to the eventual branch or switch.</div><div><br></div><div>However, I suspect (without evidence sadly) that we could get all of the benifit from just running simplify-cfg + lower-expect, and then running the rest afterward.</div><div><br></div><div>I also suspect that with minimal effort (again, without evidence) we could just generate weights on branches rather than using the expect intrinsic.... :: shrug ::</div></div></div></div>