(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
store_merging_32.c
       1  /* PR tree-optimization/97053 */
       2  /* { dg-do run } */
       3  /* { dg-options "-O2 -fno-tree-dse" } */
       4  
       5  struct __attribute__((packed, may_alias)) S { long long s; };
       6  struct __attribute__((packed, may_alias)) T { short t; };
       7  
       8  __attribute__((noipa)) void
       9  test (char *p, char *q, int s)
      10  {
      11    if ((s & 1) == 0)
      12      {
      13        if (*(short __attribute__((may_alias)) *) &p[sizeof (short)]
      14  	  != *(short __attribute__((may_alias)) *) &q[sizeof (short)]
      15  	  || (((struct S __attribute__((may_alias)) *) &p[1])->s
      16  	      != ((struct S __attribute__((may_alias)) *) &q[1])->s)
      17  	  || (*(short __attribute__((may_alias)) *) &p[2 * sizeof (short)]
      18  	      != *(short __attribute__((may_alias)) *) &q[2 * sizeof (short)]))
      19  	__builtin_abort ();
      20      }
      21    else
      22      {
      23        if (*(short __attribute__((may_alias)) *) &p[sizeof (short)]
      24  	  != *(short __attribute__((may_alias)) *) &q[sizeof (short)]
      25  	  || (((struct S __attribute__((may_alias)) *) &p[1])->s
      26  	      != ((struct S __attribute__((may_alias)) *) &q[1])->s)
      27  	  || (((struct T __attribute__((may_alias)) *) &p[2 * sizeof (short) - 1])->t
      28  	      != ((struct T __attribute__((may_alias)) *) &q[2 * sizeof (short) - 1])->t)
      29  	  || p[3 * sizeof (short) - 2] != q[3 * sizeof (short) - 2])
      30  	__builtin_abort ();
      31      }
      32  }
      33  
      34  __attribute__((noipa)) void
      35  foo (long long *p, char *q, char *r, char *s)
      36  {
      37    char a[64] __attribute__((aligned (__alignof (short))));
      38    *(short __attribute__((may_alias)) *) &a[sizeof (short)] = 1;
      39    ((struct S __attribute__((may_alias)) *) &a[1])->s = p[0];
      40    *(short __attribute__((may_alias)) *) &a[2 * sizeof (short)] = 2;
      41    *(short __attribute__((may_alias)) *) &q[sizeof (short)] = 1;
      42    ((struct S __attribute__((may_alias)) *) &r[1])->s = p[0];
      43    *(short __attribute__((may_alias)) *) &s[2 * sizeof (short)] = 2;
      44    test (a, q, 0);
      45  }
      46  
      47  __attribute__((noipa)) void
      48  bar (long long *p, char *q, char *r, char *s, char *t)
      49  {
      50    char a[64] __attribute__((aligned (__alignof (short))));
      51    *(short __attribute__((may_alias)) *) &a[sizeof (short)] = 1;
      52    ((struct S __attribute__((may_alias)) *) &a[1])->s = p[0];
      53    ((struct T __attribute__((may_alias)) *) &a[2 * sizeof (short) - 1])->t = 2;
      54    a[3 * sizeof (short) - 2] = 3;
      55    *(short __attribute__((may_alias)) *) &q[sizeof (short)] = 1;
      56    ((struct S __attribute__((may_alias)) *) &r[1])->s = p[0];
      57    ((struct T __attribute__((may_alias)) *) &s[2 * sizeof (short) - 1])->t = 2;
      58    t[3 * sizeof (short) - 2] = 3;
      59    test (a, q, 1);
      60  }
      61  
      62  __attribute__((noipa)) void
      63  baz (long long *p, char *q, char *r, char *s)
      64  {
      65    char a[64] __attribute__((aligned (__alignof (short))));
      66    *(short __attribute__((may_alias)) *) &a[2 * sizeof (short)] = 2;
      67    ((struct S __attribute__((may_alias)) *) &a[1])->s = p[0];
      68    *(short __attribute__((may_alias)) *) &a[sizeof (short)] = 1;
      69    *(short __attribute__((may_alias)) *) &q[2 * sizeof (short)] = 2;
      70    ((struct S __attribute__((may_alias)) *) &r[1])->s = p[0];
      71    *(short __attribute__((may_alias)) *) &s[sizeof (short)] = 1;
      72    test (a, q, 2);
      73  }
      74  
      75  __attribute__((noipa)) void
      76  qux (long long *p, char *q, char *r, char *s, char *t)
      77  {
      78    char a[64] __attribute__((aligned (__alignof (short))));
      79    *(short __attribute__((may_alias)) *) &a[2 * sizeof (short) - 1] = 2;
      80    ((struct S __attribute__((may_alias)) *) &a[1])->s = p[0];
      81    a[3 * sizeof (short) - 2] = 3;
      82    *(short __attribute__((may_alias)) *) &a[sizeof (short)] = 1;
      83    ((struct T __attribute__((may_alias)) *) &q[2 * sizeof (short) - 1])->t = 2;
      84    ((struct S __attribute__((may_alias)) *) &r[1])->s = p[0];
      85    s[3 * sizeof (short) - 2] = 3;
      86    ((struct T __attribute__((may_alias)) *) &t[sizeof (short)])->t = 1;
      87    test (a, q, 3);
      88  }
      89  
      90  __attribute__((noipa)) void
      91  corge (long long *p, char *q, char *r, char *s, short u[3])
      92  {
      93    char a[64] __attribute__((aligned (__alignof (short))));
      94    *(short __attribute__((may_alias)) *) &a[2 * sizeof (short)] = u[2];
      95    ((struct S __attribute__((may_alias)) *) &a[1])->s = p[0];
      96    *(short __attribute__((may_alias)) *) &a[sizeof (short)] = u[1];
      97    *(short __attribute__((may_alias)) *) &q[2 * sizeof (short)] = u[2];
      98    ((struct S __attribute__((may_alias)) *) &r[1])->s = p[0];
      99    *(short __attribute__((may_alias)) *) &s[sizeof (short)] = u[1];
     100    test (a, q, 4);
     101  }
     102  
     103  __attribute__((noipa)) void
     104  garply (long long *p, char *q, char *r, char *s, short u[3])
     105  {
     106    char a[64] __attribute__((aligned (__alignof (short))));
     107    *(short __attribute__((may_alias)) *) &a[sizeof (short)] = u[1];
     108    ((struct S __attribute__((may_alias)) *) &a[1])->s = p[0];
     109    *(short __attribute__((may_alias)) *) &a[2 * sizeof (short)] = u[2];
     110    *(short __attribute__((may_alias)) *) &s[sizeof (short)] = u[1];
     111    ((struct S __attribute__((may_alias)) *) &r[1])->s = p[0];
     112    *(short __attribute__((may_alias)) *) &q[2 * sizeof (short)] = u[2];
     113    test (a, q, 6);
     114  }
     115  
     116  int
     117  main ()
     118  {
     119    char a[64] __attribute__((aligned (__alignof (short))));
     120    long long p = -1LL;
     121    short u[] = { 1, 2, 3 };
     122    foo (&p, &a[0], &a[0], &a[0]);
     123    bar (&p, &a[0], &a[0], &a[0], &a[0]);
     124    baz (&p, &a[0], &a[0], &a[0]);
     125    qux (&p, &a[0], &a[0], &a[0], &a[0]);
     126    corge (&p, &a[0], &a[0], &a[0], u);
     127    garply (&p, &a[0], &a[0], &a[0], u);
     128    return 0;
     129  }