https://gcc.gnu.org/g:c71ad4260fe73a20c002721491a4d4291f1fb3d8
commit r17-5996-gc71ad4260fe73a20c002721491a4d4291f1fb3d8 Author: Richard Biener <[email protected]> Date: Fri Nov 6 08:35:52 2026 +0100 tree-optimization/128461 - store motion and SSO The following preserves the SSO when performing loop store motion. PR tree-optimization/128461 * tree-ssa-loop-im.cc (gather_mem_refs_stmt): Preserve SSO when building a canonicalized ref. * gcc.dg/torture/pr128461.c: New testcase. Diff: --- gcc/testsuite/gcc.dg/torture/pr128461.c | 24 ++++++++++++++++++++++++ gcc/tree-ssa-loop-im.cc | 2 ++ 2 files changed, 26 insertions(+) diff --git a/gcc/testsuite/gcc.dg/torture/pr128461.c b/gcc/testsuite/gcc.dg/torture/pr128461.c new file mode 100644 index 000000000000..cac07eef2494 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr128461.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ + +#pragma scalar_storage_order big-endian +struct S { + short a; +}; +#pragma scalar_storage_order default + +struct S g[2]; +int n = 1; + +int main () +{ + int x = 0; + g[1].a = 2; + for (int i = 0; i < n; i++) + { + x = g[1].a; + (&g[0])[1].a = 0; + } + if (x != 2) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-ssa-loop-im.cc b/gcc/tree-ssa-loop-im.cc index 04f6e9282ee8..5bbeb5048b23 100644 --- a/gcc/tree-ssa-loop-im.cc +++ b/gcc/tree-ssa-loop-im.cc @@ -1757,6 +1757,8 @@ gather_mem_refs_stmt (class loop *loop, gimple *stmt) build_int_cst (ref_alias_type, mem_off)); if ((*slot)->mem.volatile_p) TREE_THIS_VOLATILE (new_ref) = 1; + if (reverse_storage_order_for_component_p (*mem)) + REF_REVERSE_STORAGE_ORDER (new_ref) = 1; (*slot)->mem.ref = new_ref; /* Make sure the recorded base and offset are consistent with the newly built ref. */
