https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119085
--- Comment #7 from Po Lu <luangruo at yahoo dot com> --- "pipcet at protonmail dot com" <gcc-bugzi...@gcc.gnu.org> writes: > I think the problem is that the representative access chosen in > sort_and_splice_var_accesses won't be the union copy (which would copy the > whole storage) but the copy of the member struct (which doesn't). > > Making that function choose the union copy (if there is one, and we can detect > it) fixes the problem, without giving up on scalarization for the entire > access > group, but I don't know how to do it properly, and what to do if there is no > union copy to be chosen. The same issue affects two struct accesses of different layouts but of the same size. E.g., with this code: #include "reduction.h" struct selection_input_event kbd_buffer[KBD_BUFFER_SIZE]; struct selection_input_event *kbd_store_ptr; void kbd_buffer_store_buffered_event (union buffered_input_event *event, struct input_event *hold_quit) { if (event->kind == ASCII_KEYSTROKE_EVENT) *hold_quit = event->ie; else *kbd_store_ptr = event->sie; } void init_keyboard (void) { kbd_store_ptr = kbd_buffer; } struct selection_input_event * get_kbd_fetch_ptr (void) { return kbd_buffer; } If struct input_event and struct selection_input_event are padded to the same size (on x86_64-pc-linux-gnu). struct input_event { ENUM_BF (event_kind) kind; unsigned code; unsigned modifiers; long device; }; struct selection_input_event { ENUM_BF (event_kind) kind; int *dpyinfo; long pad; };