<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: arial,helvetica,sans-serif; font-size: 10pt; color: #000000'><br><hr id="zwchr"><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><b>From: </b>"James Molloy via llvm-dev" <llvm-dev@lists.llvm.org><br><b>To: </b>"LLVM Dev" <llvm-dev@lists.llvm.org>, "Chandler Carruth" <chandlerc@google.com><br><b>Sent: </b>Friday, April 1, 2016 2:56:25 AM<br><b>Subject: </b>[llvm-dev] RFC: std::vector and identified objects<br><br><div dir="ltr">Hi,<div><br></div><div>Consider this code:</div><div>std::vector v;</div><div>v.resize(256);</div><div>for (i = 0; i < ... ; ++i) {</div><div>  a += v[b[i]];</div><div>}</div><div><br></div><div>This is a gather loop, and should be able to be vectorized. <b>however</b>...</div><div><br></div><div>I as a programmer can see that the size of v.data() is at least 256. I know because of the contract of std::vector that v.data() is a unique heap object that doesn't alias anything.</div><div><br></div><div>However, LLVM knows none of this. Only if I force-inline std::vector::__append and friends does LLVM actually see the operator new(256) call - without that LLVM has no idea of the underlying storage of v, or of its size.</div><div><br></div><div>Now, the vectorizer can emit runtime pointer checks, but one thing it absolutely requires is knowledge of the maximum size of a pointed-to object so it can do range intersection analysis. Without this information, it can't even emit a runtime pointer check.</div><div><br></div><div id="DWT8543">So this RFC is about what exactly is going wrong here. I don't understand quite how we intend LLVM to gain this information - are we missing some intrinsics or abstractions?</div></div></blockquote>FWIW, this is one of the primary motivators for http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3988.pdf (which I need to get back to working on soon). The size is also important information (but likely not as important as the aliasing in this case - it is more important if you have conditional accesses and lack hardware predicated loads/stores).<br><br>In this case, where the object is local, I can imagine some smarter IPA (function attributes or otherwise) helping. I think that, in general, we'll probably need to provide some attributes that can be used to adorn the std::vector implementation, translated into some associated intrinsics and/or metadata, that will allow the backend to compute these various properties.<br><br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><div dir="ltr"><div id="DWT8544"> Or is the inliner just doing a poor job?</div></div></blockquote>Perhaps this too ;)<br><br> -Hal<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><div dir="ltr"><div></div><div><br></div><div>I can't imagine that in the common case inlining all the way to operator new() would be beneficial - it's only beneficial in this case because the object is newly constructed so all of the branches in __append can be folded away when inlining.</div><div><br></div><div>Any information welcome :)</div><div><br></div><div>Cheers,</div><div><br></div><div>James</div></div>
<br>_______________________________________________<br>LLVM Developers mailing list<br>llvm-dev@lists.llvm.org<br>http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br></blockquote><br><br><br>-- <br><div><span name="x"></span>Hal Finkel<br>Assistant Computational Scientist<br>Leadership Computing Facility<br>Argonne National Laboratory<span name="x"></span><br></div></div></body></html>