<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=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jul 17, 2020, at 1:51 PM, Nikita Popov <<a href="mailto:nikita.ppv@gmail.com" class="">nikita.ppv@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; 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;" class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jul 17, 2020 at 9:30 PM Jonathan Roelofs via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:<br class=""></div><blockquote class="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 style="overflow-wrap: break-word;" class="">I’m digging through a build failure [1], and it looks like the loop idiom recognizer adds some instructions [2], and then removes them again [3]. I don’t understand why yet, but the LegacyPassManager detects that the structural hash of the function has changed, and complains that the pass didn’t correctly report that it changed the function [4] (even though materially, it didn’t).<div class=""><br class=""></div><div class="">This raises a broader question of what we really mean when we say that a pass is allowed to report it made no changes through its runOn* function(s):</div><div class=""><br class=""></div><div class="">A) The obvious, and most restrictive condition would be that the pass can only return false if it treated the Function/Module/etc that it visited purely as read-only. From what I can tell, a lot of passes conservatively assume this is the required condition.</div><div class=""><br class=""></div><div class="">B) Less obvious would be that we allow passes to add instructions speculatively, so long as they remove whatever they added before returning false. If one were to dump the IR before & after such a pass, you should see no change in the text/bitcode. If you compared the in-memory representations, you should see no semantic differences in the two, modulo “allowed” differences like unordered lists of pointers (I vaguely remember a few cases of this existing, but can’t remember the details).</div><div class=""><br class=""></div><div class="">C) Even less obvious would be that we allow a pass that removes instructions / globals, and then re-adds them. These changes would be semantics-preserving, but would of course not preserve the removed bits of IR’s addresses in memory.<br class=""><div class=""><br class=""></div><div class="">I believe (A) to be the spirit of the contract between passes and the pass manager. (B) seems like a stretch, but depending on the analysis invalidation needs of the PM, might still be ok. (C) seems totally off base, and does not seem like a productive interpretation.</div><div class=""><br class=""></div><div class="">Does this match everyone else’s intuition, and is (B) even a valid interpretation?</div></div></div></blockquote><div class=""><br class=""></div><div class="">This concern was brought up in the relevant review (<a href="https://reviews.llvm.org/D81230" class="">https://reviews.llvm.org/D81230</a>) as well. I think we can safely go with (A) here. It's unambiguous, and I don't think there's any practical benefit to be had from (B) or (C).<br class=""></div></div></div></div></blockquote><div><br class=""></div><div>Thanks for the perfect reference!</div><div><br class=""></div><div><a href="https://reviews.llvm.org/D84071" class="">https://reviews.llvm.org/D84071</a></div><div><br class=""></div><div><br class=""></div><div>Jon</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; 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;" class=""><div class="gmail_quote"><div class=""><br class=""></div><div class="">Regards,<br class=""></div><div class="">Nikita</div></div></div></div></blockquote></div><br class=""></body></html>