This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Why does GCC reload my array base pointer? (C++, ASM)
- From: Juan Cabrera <jjcp dot 91 at gmail dot com>
- To: David Pfander <David dot Pfander at ipvs dot uni-stuttgart dot de>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Tue, 11 Jul 2017 13:28:47 -0300
- Subject: Re: Why does GCC reload my array base pointer? (C++, ASM)
- Authentication-results: sourceware.org; auth=none
- References: <8ad7a463-f9cb-ca60-0b44-fea2a20e0bc1@ipvs.uni-stuttgart.de>
It might be hard to tell without a code example of this, but I usually
find that "const all the things" does the trick.
Regards,
Juan.
2017-07-11 13:16 GMT-03:00 David Pfander <David.Pfander@ipvs.uni-stuttgart.de>:
> Hello everyone,
>
> I have some trouble understanding GCC's code generation. I'm accessing
> different components of a big array. (Or in more detail: I'm writing a
> struct-of-array abstraction in C++.) Now, I want to read different
> components with minimal overhead, because this access takes place in an
> extremely hot loop:
>
> [...]
> m[0] = expansions_SoA.value<0>(flat_index);
> m[1] = expansions_SoA.value<1>(flat_index);
> [...]
>
> The expansions_SoA is an instance of a class that has the accessed array
> as a member:
>
> template <typename component_type, size_t num_components, size_t entries>
> class struct_of_array_data {
> private:
> component_type* const data;
> [...]
> }
>
> The array pointer is initialized, used and absolutely never changed (and
> finally deleted[]).
>
> If you now look at a screenshot of vtune (or gdb) ouput here:
> http://imgur.com/a/7YJBC
> You'll see that there is a suspicious mov instruction
>
> movq (%rax), %rdx
>
> over and over again. This reloads the "data" member, so basically it
> reloads the same value.
>
> My question is: Why isn't this value just kept in registers (it is
> reused immediately)? (How) can I get rid of the duplicate load?
>
> Best regards,
> David Pfander