<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Jun 16, 2013 at 4:59 AM, Stephan Tolksdorf <span dir="ltr"><<a href="mailto:st@quanttec.com" target="_blank">st@quanttec.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi,<br>
<br>
clang emits the following x64 code for `vector.data() + vector.size()`<br>
(where vector is a std::vector<int32> instance that contains two internal pointers that point to the beginning and the end of an array):<br>
<br>
movq (%rdi), %rcx // rdi is a pointer to the vector<br>
movq 8(%rdi), %rax<br>
subq %rcx, %rax<br>
andq $-4, %rax<br>
addq %rcx, %rax<br>
<br>
Is there any way to tell clang in the vector implementation that the array is aligned, so that it could reduce this code to a simple load<br>
`movq 8(%rdi), %rax`?<br>
<br>
This kind of optimization would be helpful for inlined code that converts back and forth between a pointer pair representation and pointer + size representation of an array reference.<br></blockquote><div><br></div><div style>
This is really interesting. It seems we run into a similar problem with:</div><div style><br></div><div style><div>ArrayRef<int> arrayRefOpt(ArrayRef<int> A) {</div><div> ArrayRef<int> B(A.data(), A.size());</div>
<div> ArrayRef<int> C(B.begin(), B.end());</div><div> ArrayRef<int> D(C.data(), C.size());</div><div> ArrayRef<int> E(D.begin(), D.end());</div><div> ArrayRef<int> F(E.data(), E.size());</div><div>
return D;</div><div>}</div><div><br></div>Which generates:<div style><div><font face="courier new, monospace">__Z11arrayRefOptN4llvm8ArrayRefIiEE:</font></div><div><font face="courier new, monospace"> 0: 55 pushq %rbp</font></div>
<div><font face="courier new, monospace"> 1: 48 89 e5 movq %rsp, %rbp</font></div><div><font face="courier new, monospace"> 4: 48 8d 14 b5 00 00 00 00 leaq (,%rsi,4), %rdx</font></div>
<div><font face="courier new, monospace"> c: 48 c1 fa 02 sarq $2, %rdx</font></div><div><font face="courier new, monospace"> 10: 48 89 f8 movq %rdi, %rax</font></div>
<div><font face="courier new, monospace"> 13: 5d popq %rbp</font></div><div><font face="courier new, monospace"> 14: c3 ret</font></div>
<div><br></div><div style>Maybe this is bug-report-worthy?</div></div></div><div style><br></div><div style>-- Sean Silva </div></div></div></div>