[cfe-dev] Code generated for pointer pair -> pointer + size -> pointer pair conversion

Stephan Tolksdorf st at quanttec.com
Sun Jun 16 04:59:09 PDT 2013


Hi,

clang emits the following x64 code for `vector.data() + vector.size()`
(where vector is a std::vector<int32> instance that contains two 
internal pointers that point to the beginning and the end of an array):

   movq	(%rdi), %rcx  // rdi is a pointer to the vector
   movq	8(%rdi), %rax
   subq	%rcx, %rax
   andq	$-4, %rax
   addq	%rcx, %rax

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
`movq 8(%rdi), %rax`?

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.

- Stephan





More information about the cfe-dev mailing list