]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix oversight in handling of reverse SSO in SRA pass
authorEric Botcazou <ebotcazou@gcc.gnu.org>
Thu, 5 Aug 2021 08:21:30 +0000 (10:21 +0200)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Thu, 5 Aug 2021 08:24:50 +0000 (10:24 +0200)
The scalar storage order does not apply to pointer and vector components.

gcc/
PR tree-optimization/101626
* tree-sra.c (propagate_subaccesses_from_rhs): Do not set the
reverse scalar storage order on a pointer or vector component.

gcc/testsuite/
* gcc.dg/sso-15.c: New test.

gcc/testsuite/gcc.dg/sso-15.c [new file with mode: 0644]
gcc/tree-sra.c

diff --git a/gcc/testsuite/gcc.dg/sso-15.c b/gcc/testsuite/gcc.dg/sso-15.c
new file mode 100644 (file)
index 0000000..d8a711d
--- /dev/null
@@ -0,0 +1,36 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#define REV_ENDIANNESS __attribute__((scalar_storage_order("big-endian")))
+#else
+#define REV_ENDIANNESS __attribute__((scalar_storage_order("little-endian")))
+#endif
+
+struct X { int *p; } REV_ENDIANNESS;
+
+struct X x;
+
+struct X __attribute__((noinline)) foo (int *p)
+{
+  struct X x;
+  x.p = p;
+  return x;
+}
+
+void __attribute((noinline)) bar (void)
+{
+  *x.p = 1;
+}
+
+extern void abort (void);
+
+int main (void)
+{
+  int i = 0;
+  x = foo(&i);
+  bar();
+  if (i != 1)
+    abort ();
+  return 0;
+}
index c05d22f3e8f1ea4e5c3c6a4c61781f6a6baec054..3a9e14f50a08b6a36465dab604e5598ae5657065 100644 (file)
@@ -2790,7 +2790,10 @@ propagate_subaccesses_from_rhs (struct access *lacc, struct access *racc)
        {
          /* We are about to change the access type from aggregate to scalar,
             so we need to put the reverse flag onto the access, if any.  */
-         const bool reverse = TYPE_REVERSE_STORAGE_ORDER (lacc->type);
+         const bool reverse
+           = TYPE_REVERSE_STORAGE_ORDER (lacc->type)
+             && !POINTER_TYPE_P (racc->type)
+             && !VECTOR_TYPE_P (racc->type);
          tree t = lacc->base;
 
          lacc->type = racc->type;