https://gcc.gnu.org/g:cfddb495c2f4cfc556588ea21ec322c885661b02
commit r17-6058-gcfddb495c2f4cfc556588ea21ec322c885661b02 Author: Richard Biener <[email protected]> Date: Mon Nov 9 12:55:03 2026 +0100 tree-optimization/128514 - wrong bitfield vectorization with SSO The following rejects reverse-storage-order components when lowering bitfields to avoid miscompilation. PR tree-optimization/128514 * tree-if-conv.cc (bitfields_to_lower_p): Reject components with reverse storage order. * gcc.dg/vect/vect-pr128514.c: New testcase. Diff: --- gcc/testsuite/gcc.dg/vect/vect-pr128514.c | 26 ++++++++++++++++++++++++++ gcc/tree-if-conv.cc | 6 ++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/gcc.dg/vect/vect-pr128514.c b/gcc/testsuite/gcc.dg/vect/vect-pr128514.c new file mode 100644 index 000000000000..6d28bbd36082 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-pr128514.c @@ -0,0 +1,26 @@ +#include "tree-vect.h" + +#pragma scalar_storage_order big-endian +struct S { + unsigned b : 5; +}; +#pragma scalar_storage_order default + +struct S a[16]; +unsigned char c[16][3]; + +int main() +{ + check_vect (); + + for (int i = 0; i < 16; i++) + c[i][0] = i + 1; + for (int i = 0; i < 16; i++) + { + c[i][1] = c[i][2] = 0; + a[i ^ 1].b = c[i ^ 1][0]; + } + if (a[15].b != 16) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc index b44b96ff7968..05780b4a3748 100644 --- a/gcc/tree-if-conv.cc +++ b/gcc/tree-if-conv.cc @@ -4039,11 +4039,13 @@ bitfields_to_lower_p (class loop *loop, if (dump_file && (dump_flags & TDF_DETAILS)) print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM); - if (TREE_THIS_VOLATILE (op)) + if (TREE_THIS_VOLATILE (op) + || reverse_storage_order_for_component_p (op)) { if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, "\t Bitfield NO OK to lower," - " the access is volatile.\n"); + " the access is volatile or" + " has reverse storage-order.\n"); return false; }
