<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 26, 2015, at 10:30 AM, Chandler Carruth <<a href="mailto:chandlerc@google.com" class="">chandlerc@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class="Apple-interchange-newline">On Mon, Jan 26, 2015 at 10:29 AM, Pete Cooper<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:peter_cooper@apple.com" target="_blank" class="">peter_cooper@apple.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><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 class=""><div class="adM"><div class=""><blockquote type="cite" class=""><div class="">On Jan 26, 2015, at 10:24 AM, Chandler Carruth <<a href="mailto:chandlerc@google.com" target="_blank" class="">chandlerc@google.com</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Sun, Jan 25, 2015 at 9:37 PM, Pete Cooper<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:peter_cooper@apple.com" target="_blank" class="">peter_cooper@apple.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><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;" class="">Hi hfinkel,<br class=""><br class="">This teaches the constant folder that an llvm.expect intrinsic with a constant as the first operand will return that constant.<br class=""><br class="">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 class=""></div><div class="gmail_extra">I really don't understand this.</div><div class="gmail_extra"><br class=""></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 class=""><br class=""></div><div class="">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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">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>I see what you mean.  Personally I find that a bit gross that we have an intrinsic for this at all then.</div><div><br class=""></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><br class=""></div><div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">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;" class="">Data Layout</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">No target information</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">Target independent code generator's TTI</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">X86 Target Transform Info</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">No Alias Analysis (always returns 'may' alias)</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">Type-Based Alias Analysis</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">Scoped NoAlias Alias Analysis</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">Assumption Cache Tracker</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">Target Library Information</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">Basic Alias Analysis (stateless AA impl)</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">  FunctionPass Manager</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">    Module Verifier</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">    Simplify the CFG</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">    Dominator Tree Construction</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">    SROA</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">    Early CSE</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">    Lower 'expect' Intrinsics</div></div><br class=""></body></html>