<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 Oct 3, 2016, at 11:01 AM, Joerg Sonnenberger 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 class="">On Mon, Oct 03, 2016 at 02:43:03PM +0200, Michael Kruse via llvm-dev wrote:<br class=""><blockquote type="cite" class="">2016-10-03 13:55 GMT+02:00 Martin J. O'Riordan via llvm-dev<br class=""><<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>>:<br class=""><blockquote type="cite" class="">I am trying to implement some new alignment based optimisations in our<br class="">target backend, and I am wondering if there a way a target can specify that<br class="">‘malloc’, ‘realloc’ and ‘calloc’ always return a pointer to memory that is<br class="">aligned to a particular boundary?<br class=""></blockquote><br class="">malloc is guaranteed to be properly aligned for any C type. This would<br class="">be 8 bytes on most systems for double. However, I think in practice<br class="">most modern implementations return 16-byte aligned pointers. I don't<br class="">think there is a way to annotate calls malloc to have some specific<br class="">alignment from the backend, that has effect on passes before the<br class="">backend.<br class=""></blockquote><br class="">Note that this only applies to base types. Vector types certainly can<br class="">require larger alignment in practice and that's why posix_memalign<br class="">exists.<br class=""></div></div></blockquote>Is memalign stil needed for vector types?  From the man page (<a href="http://www.manpagez.com/man/3/calloc/" class="">http://www.manpagez.com/man/3/calloc/</a>), it says:</div><div><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div>The malloc(), calloc(), valloc(), realloc(), and reallocf() functions allocate memory.  </div></blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div>The allocated memory is aligned such that it can be used for any data type, including AltiVec- and SSE-related types.</div></blockquote><div class=""><br class=""></div>Given this, a while ago I had a hacked up an LLVM pass to add align(16) to the return attributes of malloc.  It saved a few KB from the clang executable size due to more efficient memcpy and related functions being generated in the backend.<div class=""><br class=""></div><div class="">So yes please to some kind of solution to this.  I’d be fine with adding something to TTI if we can’t get it in the headers.</div><div class=""><br class=""></div><div class="">Cheers,</div><div class="">Pete<br class=""><div><blockquote type="cite" class=""><div class=""><div class=""><br class="">Joerg<br class="">_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></div></blockquote></div><br class=""></div></body></html>