<div dir="ltr">Didn't we just have this discussion on cfe-dev? (or is there something different I've missed?)</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 4, 2015 at 2:31 AM, François Fayard <span dir="ltr"><<a href="mailto:fayard@insideloop.io" target="_blank">fayard@insideloop.io</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi,<div><br></div><div>I’ve made my own version of std::vector which is called il::Vector. Due to <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3664.html" target="_blank">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3664.html</a>, LLVM can optimise away memory allocation. Therefore, the following code optimise away all memory allocation for w resulting in a single allocation during the whole program (for v).</div><div><br></div><div>When using my own vector implementation, I realised that the allocation were not optimized away because I was using ::operator new. When I’ve switched back to new, the optimisation came back.</div><div><br></div><div>Is it expected or a bug from LLVM?</div><div><br><div>
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div><div><span style="background-color:rgba(255,255,255,0)">François Fayard<br>Founder & Consultant - Inside Loop</span></div><div><span style="background-color:rgba(255,255,255,0)">Tel: <a href="tel:+33%206%2001%2044%2006%2093" target="_blank">+33 (0)6 01 44 06 93</a></span></div><div><span style="background-color:rgba(255,255,255,0)">Web: <a href="http://www.insideloop.io" target="_blank">www.insideloop.io</a></span></div></div><div>Twitter: @insideloop_io</div></div></div></div></div></div>
</div>
<br></div><div>=====</div><div><br></div><div><div>#include <iostream></div><div>#include <vector></div><div><br></div><div><br></div><div>std::vector<double> f_val(std::size_t i, std::size_t n) {</div><div> auto v = std::vector<double>(n);</div><div> for (std::size_t k = 0; k < v.size(); ++k) {</div><div> v[k] = static_cast<double>(i);</div><div> }</div><div> return v;</div><div>}</div><div><br></div><div>int main (int argc, char const *argv[])</div><div>{</div><div> const auto n = std::size_t{10};</div><div> const auto nb_loops = std::size_t{300000000};</div><div><br></div><div> auto v = std::vector<double>( n, 0.0 );</div><div> for (std::size_t i = 0; i < nb_loops; ++i) {</div><div> auto w = f_val(i, n);</div><div> for (std::size_t k = 0; k < v.size(); ++k) {</div><div> v[k] += w[k];</div><div> }</div><div> }</div><div> std::cout << v[0] << " " << v[n - 1] << std::endl;</div><div><br></div><div> return 0;</div><div>}</div></div></div><br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>