(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
vect/
pr94994.c
       1  #include <stdint.h>
       2  #include "tree-vect.h"
       3  
       4  #define BLOCK_SIZE (sizeof (uint32_t))
       5  
       6  struct unaligned {
       7    uint32_t x;
       8  } __attribute__((packed, may_alias));
       9  
      10  static inline uint32_t
      11  load_unaligned (const char *p)
      12  {
      13    return ((struct unaligned *) p)->x;
      14  }
      15  
      16  static inline void
      17  store_unaligned (uint32_t x, char *p)
      18  {
      19    ((struct unaligned *) p)->x = x;
      20  }
      21  
      22  void __attribute__((noipa))
      23  copy (char *dst, const char *src, size_t n)
      24  {
      25    for (size_t i = 0; i < n; i += BLOCK_SIZE)
      26      store_unaligned (load_unaligned (src + i), dst + i);
      27  }
      28  
      29  #define INPUT_SIZE 64
      30  #define MAX_STEP 32
      31  
      32  char x[INPUT_SIZE + MAX_STEP];
      33  
      34  int
      35  main (void)
      36  {
      37    check_vect ();
      38  
      39    for (unsigned int i = 1; i < MAX_STEP; ++i)
      40      {
      41        for (unsigned int j = 0; j < INPUT_SIZE + MAX_STEP; ++j)
      42  	x[j] = j + 10;
      43        copy (x + i, x, INPUT_SIZE);
      44        for (int j = 0; j < INPUT_SIZE + i; ++j)
      45  	{
      46  	  int expected;
      47  	  if (j < i)
      48  	    expected = j + 10;
      49  	  else if (i >= BLOCK_SIZE)
      50  	    expected = j % i + 10;
      51  	  else if ((j - i) % BLOCK_SIZE < i)
      52  	    expected = x[j - i];
      53  	  else
      54  	    expected = j - i + 10;
      55  	  if (x[j] != expected)
      56  	    __builtin_abort ();
      57  	}
      58      }
      59  
      60    return 0;
      61  }