[Bug tree-optimization/58039] New: -ftree-vectorizer make a loop crash on non-aligned memory
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58039 Bug ID: 58039 Summary: -ftree-vectorizer make a loop crash on non-aligned memory Product: gcc Version: unknown Status: UNCONFIRMED Severity: major Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: bar at mariadb dot org Created attachment 30578 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30578&action=edit The program that repeats the report crash If I compile the attached program using: gcc -Wall -O2 -fno-inline -ftree-vectorize -ftree-vectorizer-verbose=2 a.c it crashes with "segmentation fault". $ gcc --version gcc (GCC) 4.7.2 20120921 (Red Hat 4.7.2-2) Processor: Intel® Core™ i7-3520M CPU @ 2.90GHz × 4 The program is a minimal extract from the MariaDB-10.0 sources that reproduces the crash. The GCC flags that are actually used in the debug build of MariaDB are: gcc -Wall -O3 -fno-inline a.c but after tracking it down we noticed that the actually reason is -ftree-vectorize.
[Bug tree-optimization/58039] -ftree-vectorizer make a loop crash on non-aligned memory
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58039 --- Comment #1 from Alexander Barkov --- The bug is known to repeat on the following operating systems: - Fedora 17 - Ubuntu 13.04 - OpenSUSE 11.1
[Bug tree-optimization/58039] -ftree-vectorizer makes a loop crash on a non-aligned memory
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58039 --- Comment #2 from Alexander Barkov --- Any updates? Thanks.
[Bug tree-optimization/58039] -ftree-vectorizer makes a loop crash on a non-aligned memory
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58039 --- Comment #4 from Alexander Barkov --- Mikael, thanks for your comment on this. (In reply to Mikael Pettersson from comment #3) > Your code performs mis-aligned uint16_t stores, which x86 allows. Right, this is done for performance purposes. > The > vectorizer turns those into larger and still mis-aligned `movdqa' stores, > which x86 does not allow, hence the SEGV. Can you please clarify: is it a bug in the recent gcc versions? Note, we've used such performance improvement tricks for years. It worked perfectly fine until now. Has anything changed in how the gcc vectorizer works recently? > > Replace the non-portable mis-aligned stores with portable code like > > #define int2store_little_endian(s,A) memcpy((s), &(A), 2) > > or gcc-specific code like > > struct __attribute__((__packed__)) packed_uint16 { > uint16_t u16; > }; > #define int2store_little_endian(s,A) ((struct packed_uint16*)(s))->u16 = (A) > > and then the vectorizer generates large `movdqu' stores, which is pretty > much the best you can hope for unless you rewrite the code to avoid > mis-aligned stores. Unfortunately it's not possible to avoid mis-aligned stores due to the project architecture. I've read somewhere that gcc vectorizer generates two code branches, for aligned memory and for non-aligned memory (but can't find the reference now). Can you please confirm this? Thanks.