[Bug tree-optimization/69047] memcpy is not as optimized as union is

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Aug 25 05:34:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69047

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|arm, aarch64                |
          Component|rtl-optimization            |tree-optimization
            Summary|memcpy of 64-bit integer to |memcpy is not as optimized
                   |32-bit integer causes       |as union is
                   |pointless stack operations  |
                   |on ARM                      |
           Severity|normal                      |enhancement

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Take:
union li
{
  int a[2];
  long long b;
};
int f(long long b) {
    int a;
    __builtin_memcpy(&a, &b, sizeof a);
    return a;
}
int f1(long long b) {
    union li a;
    a.b = b;
    return a.a[0];
}

These two functions should produce the same code but f produces worse.

Also f1 is optimized at the tree level while f is optimized at the RTL level
leaving behind the stack location that is used to store b.


More information about the Gcc-bugs mailing list