<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><blockquote type="cite" class="">On Jan 31, 2019, at 4:40 PM, Aditya K <<a href="mailto:hiraditya@msn.com" class="">hiraditya@msn.com</a>> wrote:<br class=""></blockquote><div><blockquote type="cite" class=""><br class="Apple-interchange-newline"><div class=""><div style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class="">Hi Nikita,</div><div style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class=""><br class=""></div><div style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class="">Glad to hear that Rust code can benefit a lot from this.</div><div style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class=""> <span class="Apple-converted-space"> </span><br class=""></div><div style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class="">I have put patches to enable merge-similar functions with thinLTO.</div><div style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class=""><div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class=""><a href="https://reviews.llvm.org/D52896" class="">https://reviews.llvm.org/D52896 etc.</a></div></div></div></blockquote></div><div><blockquote type="cite" class=""><div class=""><div style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class=""><div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class=""><br class=""></div>This is more powerful than existing merge-functions pass and all we need to do is port these patches to trunk llvm. I'd be happy to help with this effort.</div></div></blockquote><div><br class=""></div><div>At the risk of straying too far off-topic: I think this patch is interesting, but would need help to understand it better. Would you mind starting a new thread about it? Specifically, I’d like to know what the marginal benefit is of factoring out dissimilar instructions, versus simply factoring out dissimilar constants. Presumably there’s a compile-time vs. performance vs. code size tradeoff. I think this is worth digging into because equivalence-module-constant-uses merging was sufficient for Swift.</div><div><br class=""></div><div>vedant</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class=""><br class=""></div><div style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class=""><br class=""></div><div style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class="">-Aditya<br class=""></div><div style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class=""><br class=""></div><div style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><div id="appendonsend" class=""></div><div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class=""><br class=""></div><div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;" class=""></div><hr tabindex="-1" style="display: inline-block; width: 1641.5px;" class=""><div id="divRplyFwdMsg" dir="ltr" class=""><font face="Calibri, sans-serif" style="font-size: 11pt;" class=""><b class="">From:</b><span class="Apple-converted-space"> </span>Nikita Popov <<a href="mailto:nikita.ppv@gmail.com" class="">nikita.ppv@gmail.com</a>><br class=""><b class="">Sent:</b><span class="Apple-converted-space"> </span>Thursday, January 31, 2019 3:46 PM<br class=""><b class="">To:</b><span class="Apple-converted-space"> </span>Vedant Kumar<br class=""><b class="">Cc:</b><span class="Apple-converted-space"> </span>llvm-dev; Reid Kleckner; Aditya K; <a href="mailto:whitequark@whitequark.org" class="">whitequark@whitequark.org</a>; Teresa Johnson; Duncan P. N. Exon Smith; Jessica Paquette<br class=""><b class="">Subject:</b><span class="Apple-converted-space"> </span>Re: Status of the function merging pass?</font><div class=""> </div></div><div class=""><div dir="ltr" class=""><div class="x_gmail_quote"><div dir="ltr" class="x_gmail_attr">On Thu, Jan 31, 2019 at 8:52 PM Vedant Kumar <<a href="mailto:vsk@apple.com" class="">vsk@apple.com</a>> wrote:<br class=""></div><blockquote class="x_gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div class="">Hi,<div class=""><br class=""></div><div class="">I'm interested in finding ways to reduce code size. LLVM's MergeFunctions pass seems like a promising option, and I'm curious about its status in tree.</div><div class=""><br class=""></div><div class="">Enabling MergeFunctions gives a 1% code size reduction across the entire iOS shared cache (a collection of a few hundred system-critical DSO's). The numbers are even more compelling for Swift code. In fact, the swift compiler enables MergeFunctions by default when optimizing, along with an even more aggressive merging pass which handles equivalence-modulo-constant-uses (<a href="https://github.com/apple/swift/blob/master/lib/LLVMPasses/LLVMMergeFunctions.cpp" target="_blank" class="">https://github.com/apple/swift/blob/master/lib/LLVMPasses/LLVMMergeFunctions.cpp</a>).</div><div class=""><br class=""></div><div class="">Is anyone actively working on enabling MergeFunctions in LLVM's default pipelines? Is there a roadmap for doing so?</div><div class=""><br class=""></div><div class="">ISTM that preventing miscompiles when merging functions is a serious, unsolved problem. I.e., it's hard for the MergeFunctions pass to be *really sure* that two functions are a) really identical and b) safe to merge.</div><div class=""><br class=""></div><div class="">Is there a systematic solution at the IR-level, given that the semantics of IR are subject to change? Is extensive testing the only solution? Or is this intractable, and the only safe approach is to perform merging post-regalloc (or, at some late point when equivalence is easier to determine)?</div></div></blockquote><div class=""><br class=""></div><div class="">In Rust we've been running with MergeFunctions enabled by default for a while now, and have recently also enabled the use of aliases instead of thunks. Apart from some initial bugs we didn't encounter any significant issues (one minor issue with NVPTX not supporting aliases and having CC restrictions).</div><div class=""><br class=""></div><div class="">As Rust tends to be quite heavy on monomorphization, MergeFuncs can give significant binary size reductions. I don't have any comprehensive numbers, but from checking this on a pet project just now, it reduces final artifact size by 13% and I've seen some similar numbers in the ~10% range quoted before.</div><div class=""><br class=""></div><div class="">So, at least for Rust's use case this pass seems to be both quite robust and useful :)<br class=""></div><div class=""><br class=""></div><div class="">Regards,<br class=""></div><div class="">Nikita</div></div></div></div></div></div></blockquote></div><br class=""></body></html>