<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></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 Jan 17, 2022, at 08:07, Russell Wallace via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">All the optimization passes I can find in the documentation, deal with register, stack or global values; I cannot find any mention of anything trying to optimize values on the heap. But this:<div class=""><br class=""></div><div class="">#include <stdlib.h><br class=""><br class="">int main(int argc, char **argv) {<br class="">  int *a = malloc(10 * sizeof(int));<br class="">  for (int i = 0; i < 10; i++)<br class="">    a[i] = i;<br class="">  return a[5];<br class="">}<br class=""></div><div class=""><br class=""></div><div class="">compiles to 'ret 5' (as it should). Which pass does that?</div></div>
_____________________________________________<br class=""></div></blockquote></div><br class=""><div class=""><br class=""></div><div class="">You can use `-mllvm -print-changed` with clang when built with assertions to find this out, e.g. see <a href="https://clang.godbolt.org/z/aM18Tr7Mr" class="">https://clang.godbolt.org/z/aM18Tr7Mr</a></div><div class=""><br class=""></div><div class="">It will be multiple optimizations working together. There are several passes that optimize memory operation, like DSE, GVN, EarlyCSE +MemorySSA.</div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>