(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
powerpc/
pr65456.c
       1  /* { dg-do compile { target { powerpc64le-*-* } } } */
       2  /* { dg-options "-mdejagnu-cpu=power8 -O3" } */
       3  
       4  /* Verify that swap optimization properly removes swaps for unaligned
       5     vector stores.  See PR65456.  */
       6  
       7  typedef unsigned char UChar;
       8  typedef unsigned short UShort;
       9  typedef unsigned int UWord;
      10  
      11  typedef unsigned long SizeT;
      12  typedef unsigned long Addr;
      13  
      14  void *memmove(void *dst, const void *src, SizeT len)
      15  {
      16    const Addr WS = sizeof(UWord);/* 8 or 4 */
      17    const Addr WM = WS - 1;/* 7 or 3 */
      18  
      19    /* Copying backwards. */
      20    SizeT n = len;
      21    Addr d = (Addr) dst;
      22    Addr s = (Addr) src;
      23  
      24    if (((s ^ d) & WM) == 0) {
      25      /* s and d have same UWord alignment. */
      26      /* Pull up to a UWord boundary. */
      27      while ((s & WM) != 0 && n >= 1) {
      28        *(UChar *) d = *(UChar *) s;
      29        s += 1;
      30        d += 1;
      31        n -= 1;
      32      }
      33      /* Copy UWords. */
      34      while (n >= WS) {
      35        *(UWord *) d = *(UWord *) s;
      36        s += WS;
      37        d += WS;
      38        n -= WS;
      39      }
      40      if (n == 0)
      41        return dst;
      42    }
      43    if (((s | d) & 1) == 0) {
      44      /* Both are 16-aligned; copy what we can thusly. */
      45      while (n >= 2) {
      46        *(UShort *) d = *(UShort *) s;
      47        s += 2;
      48        d += 2;
      49        n -= 2;
      50      }
      51    }
      52    /* Copy leftovers, or everything if misaligned. */
      53    while (n >= 1) {
      54      *(UChar *) d = *(UChar *) s;
      55      s += 1;
      56      d += 1;
      57      n -= 1;
      58    }
      59  
      60    return dst;
      61  }
      62  
      63  /* { dg-final { scan-assembler-not "xxpermdi" } } */
      64  /* { dg-final { scan-assembler-not "xxswapd" } } */