<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 Nov 25, 2016, at 4:17 PM, Daniel Berlin 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=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, Nov 25, 2016 at 6:10 AM, Hubert Tong <span dir="ltr" class=""><<a href="mailto:hubert.reinterpretcast@gmail.com" target="_blank" class="">hubert.reinterpretcast@gmail.<wbr class="">com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><span class="">On Fri, Nov 25, 2016 at 1:42 AM, Daniel Berlin <span dir="ltr" class=""><<a href="mailto:dberlin@dberlin.org" target="_blank" class="">dberlin@dberlin.org</a>></span> wrote:<br class=""><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><div dir="ltr" class="">What is the purpose of the union there?<br class=""></div></blockquote></span><div class="">The
 purpose of the union is to increase portability by ensuring that the 
placement new is not being performed on insufficiently sized or aligned 
memory.<br class=""></div></div></div></div></blockquote><div class="">Gotcha</div><div class=""> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""> </div><span class=""><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><div dir="ltr" class="">I ask because pretty much no compiler will respecting the unioning without visible accesses  in all cases, because it would ruin most optimization[1]<div class=""><br class=""></div><div class="">But i'm also not sure it's required in this testcase to make your testcase fail.</div></div></blockquote></span><div class="">It isn't. The program should be valid, without the union, on platforms where <span style="font-family:monospace,monospace" class="">int</span> and <span style="font-family:monospace,monospace" class="">float</span> have the same size an alignment.<br class=""></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">Right, so you need to debug that first, and see what's going wrong.</div><div class="">Without TBAA info in the .ll file, this should just work.</div><div class=""> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""></div><span class=""><div class=""> </div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><div dir="ltr" class=""><div class=""><br class=""></div><div class="">In practice, handling placement new properly in gcc required the equivalent of a new intrinsic (in gcc, it required adding CHANGE_DYNAMIC_TYPE_EXPR).</div></div></blockquote></span><div class="">Sure; my question is whether or not there is already a solution in the works for LLVM. If not, then I'll try to work with some folks to propose an intrinsic.</div></div></div></div></blockquote><div class=""><br class=""></div><div class="">I would first focus on understanding why the testcase fails without any TBAA info at all.</div><div class="">In that case, i would expect it to work.</div></div></div></div></div></blockquote><div><br class=""></div></div><br class=""><div class="">The PR says "passes with -fno-strict-aliasing”, my understanding is that it is failing only with the TBAA indeed.</div><div class=""><br class=""></div><div class="">You don’t need the main and the union to reproduce, extracting foo() alone in its single own file is enough:</div><div class=""><br class=""></div><div class=""><div class="">void *operator new(decltype(sizeof 0), void *) noexcept;</div><div class="">float *qq;</div><div class="">void foo(int *p, int *q, long unk) {</div><div class="">   for (long i = 0; i < unk; ++i) {</div><div class="">      ++*p;</div><div class="">      qq = new (static_cast<void *>(&q[i])) float(42);</div><div class="">   }</div><div class="">}</div></div><div class=""><br class=""></div><div class="">LICM will get the store to p out of the loop, conceptually turning it into:</div><div class=""><div class=""><br class=""></div><div class="">void foo(int *p, int *q, long unk) {</div><div class="">   for (long i = 0; i < unk; ++i) {</div><div class="">      qq = new (static_cast<void *>(&q[i])) float(42);</div><div class="">   }</div><div class="">   ++*p;</div><div class="">}</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Now I don’t know if the use of placement new in this example is legal in the first place. I thought calling delete before using placement new was mandatory.</div><div class=""><br class=""></div><div class="">CC Sanjoy, since he looked into TBAA recently and it reminds me a similar test case he mentioned, not with placement new but with a call to a function taking int * and float *, and passing the same address (call site was union).</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">— </div><div class="">Mehdi</div><div class=""><br class=""></div></body></html>