[Bug c/78853] New: aligned reads/writes (vmovdqa) emitted when no such guarantee can be made

2016-12-18 Thread gonnet at google dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78853

Bug ID: 78853
   Summary: aligned reads/writes (vmovdqa) emitted when no such
guarantee can be made
   Product: gcc
   Version: 7.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: gonnet at google dot com
  Target Milestone: ---

I have an example on https://godbolt.org/g/qZ4SuT, this produces incorrect code
since at least gcc-4.9.1 (didn't test earlier).

I have a function that swaps to pieces of memory using vectorized read/write
instructions. When I pass it a 28-byte struct that has been padded to 32 bytes,
it emits two vmovdqa reads and writes.

The problem is that it does this even when it can't guarantee that the pointers
provided to it are aligned correctly.

[Bug target/78853] aligned reads/writes (vmovdqa) emitted when no such guarantee can be made

2016-12-19 Thread gonnet at google dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78853

--- Comment #3 from Pedro Gonnet  ---
OK, thanks for clarifying!

The declaration of __m256i only specifies the attributes vector_size and
may_alias
(https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/i386/avxintrin.h;hb=HEAD#l56),
so I'm guessing vector_size implies alignment? This does not seem to be
documented anywhere obvious.

Also interesting is that icc-17 produces unaligned load/stores for the same
code, but there is no amount of __attribute__((aligned(32))) that will make
them aligned.

In any case I'll use the __m*_u types to make an unaligned version of my
memswap function.