<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div name="messageBodySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;">Arnold,
<div><br /></div>
<div>Thanks for the explanation of what’s going on here. Has the “optimizing a semantic function called from a semantic function” issue happened before, and is there a standard workaround?</div>
<div><br /></div>
<div>I feel like adding an earlier optimization pipeline, and adding a new InlineSelection to the performance inliner, is a clunky solution to the problem.</div>
</div>
<div name="messageSignatureSection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;"><br />
<div class="matchFont">Ben Ng</div>
</div>
<div name="messageReplySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;"><br />
On Mar 3, 2017, 5:24 PM -0500, Arnold Schwaighofer &lt;aschwaighofer@apple.com&gt;, wrote:<br />
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #1abc9c;">
<div class="">Some documentation about debugging the swift compiler:</div>
<div class=""><br class="" /></div>
<div class=""><a href="https://github.com/apple/swift/blob/master/docs/DebuggingTheCompiler.rst" class="">https://github.com/apple/swift/blob/master/docs/DebuggingTheCompiler.rst</a></div>
<div class=""><br class="" /></div>
<div class="">Possibly, not all flags are documented:</div>
<div class=""><br class="" /></div>
<div class=""><a href="https://github.com/apple/swift/blob/master/lib/SILOptimizer/PassManager/PassManager.cpp" class="">https://github.com/apple/swift/blob/master/lib/SILOptimizer/PassManager/PassManager.cpp</a></div>
<div class=""><br class="" /></div>
<div class=""><br class="" /></div>
<div class="">To your specific question: We run several stages of the PerformanceInliner (<a href="https://github.com/apple/swift/blob/master/lib/SILOptimizer/Transforms/PerformanceInliner.cpp#L866" class="">https://github.com/apple/swift/blob/master/lib/SILOptimizer/Transforms/PerformanceInliner.cpp#L866</a>) during our PassPipeline (<a href="https://github.com/apple/swift/blob/master/lib/SILOptimizer/PassManager/PassPipeline.cpp#L221" class="">https://github.com/apple/swift/blob/master/lib/SILOptimizer/PassManager/PassPipeline.cpp#L221</a>) . One stage — “the high-level stage” — inlines everything up to “@_semantics” functions. The next stage also inlines those.</div>
<div class=""><br class="" /></div>
<div class="">- Run PerformanceInliner without-semantic-inlining (<a href="https://github.com/apple/swift/blob/master/lib/SILOptimizer/PassManager/PassPipeline.cpp#L445" class="">https://github.com/apple/swift/blob/master/lib/SILOptimizer/PassManager/PassPipeline.cpp#L445</a>)</div>
<div class="">- Run Optimizations that rely on seeing @semantics calls</div>
<div class="">- &#160;…</div>
<div class="">- Run PerformanceInline with-semantic-inlining (<a href="https://github.com/apple/swift/blob/master/lib/SILOptimizer/PassManager/PassPipeline.cpp#L449" class="">https://github.com/apple/swift/blob/master/lib/SILOptimizer/PassManager/PassPipeline.cpp#L449</a>)</div>
<div class="">- …</div>
<div class=""><br class="" /></div>
<div class="">If you mark a function like append with @_semantics which internally has calls to @_semantics functions you prevent the optimizations that rely on having those calls exposed/inlined from working since those calls are now hidden behind an @_semantics function that did not get inlined.</div>
<div class=""><br class="" /></div>
<div class="">The file <a href="https://github.com/apple/swift/blob/master/lib/SILOptimizer/PassManager/PassPipeline.cpp" class="">https://github.com/apple/swift/blob/master/lib/SILOptimizer/PassManager/PassPipeline.cpp</a>&#160;contains the code that sets up the pass pipeline. You can see which optimizations are scheduled in which order.</div>
<div class=""><br class="" /></div>
<div class="">If you want to see a list of passes being run dynamically "-Xllvm -sil-print-pass-name" would be the flag to add, I think.</div>
<div class=""><br class="" /></div>
<div class=""><br class="" /></div>
<div>
<blockquote type="cite" class="" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #e67e22;">
<div class="">On Mar 3, 2017, at 9:58 AM, Ben Ng via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:</div>
<br class="Apple-interchange-newline" />
<div class="">
<div class="">
<div name="messageBodySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;" class="">I noticed that adding <i class="">any</i> semantic attribute to the two Array.append functions causes performance regressions in the Array benchmark. I think that it’s because the delayed inlining is blocking some array optimizations from happening.
<div class=""><br class="" /></div>
<div class="">What are some tips for debugging this sort of issue? There are a whole bunch of passes, and it’s difficult to figure out how they all interact. Reading the SIL generated after all optimizations have been run is pretty tedious, and I’m hoping that there’s a smarter way to go about this</div>
</div>
</div>
</div>
</blockquote>
<blockquote type="cite" class="" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #e67e22;">
<div class="">
<div class="">
<div name="messageBodySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;" class="">
<div class="">.</div>
<div class=""><br class="" /></div>
<div class="">Can I get debug output that tells me what optimizations happened, and then diff the two outputs to find out what changed?</div>
</div>
</div>
</div>
</blockquote>
<blockquote type="cite" class="" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #e67e22;">
<div class="">
<div class="">
<div name="messageBodySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;" class="">
<div class=""><br class="" /></div>
<div class="">I also see a “Pass Pipeline” utility that looks useful, but it’s not obvious to me how to use it.</div>
</div>
</div>
</div>
</blockquote>
</div>
<br class="" /></blockquote>
</div>
</body>
</html>