(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
tree-ssa/
ldist-rawmemchr-2.c
       1  /* { dg-do run { target s390x-*-* } } */
       2  /* { dg-options "-O2 -ftree-loop-distribution -fdump-tree-ldist-details" } */
       3  /* { dg-additional-options "-march=z13 -mzarch" { target s390x-*-* } } */
       4  /* { dg-final { scan-tree-dump-times "generated rawmemchrQI" 2 "ldist" { target s390x-*-* } } } */
       5  /* { dg-final { scan-tree-dump-times "generated rawmemchrHI" 2 "ldist" { target s390x-*-* } } } */
       6  /* { dg-final { scan-tree-dump-times "generated rawmemchrSI" 2 "ldist" { target s390x-*-* } } } */
       7  
       8  /* Rawmemchr pattern: reduction stmt and store */
       9  
      10  #include <stdint.h>
      11  #include <assert.h>
      12  
      13  typedef __SIZE_TYPE__ size_t;
      14  extern void* malloc (size_t);
      15  extern void* memset (void*, int, size_t);
      16  
      17  uint8_t *p_uint8_t;
      18  uint16_t *p_uint16_t;
      19  uint32_t *p_uint32_t;
      20  
      21  int8_t *p_int8_t;
      22  int16_t *p_int16_t;
      23  int32_t *p_int32_t;
      24  
      25  #define test(T, pattern)    \
      26  __attribute__((noinline))   \
      27  T *test_##T (void)          \
      28  {                           \
      29    while (*p_##T != pattern) \
      30      ++p_##T;                \
      31    return p_##T;             \
      32  }
      33  
      34  test (uint8_t,  0xab)
      35  test (uint16_t, 0xabcd)
      36  test (uint32_t, 0xabcdef15)
      37  
      38  test (int8_t,  (int8_t)0xab)
      39  test (int16_t, (int16_t)0xabcd)
      40  test (int32_t, (int32_t)0xabcdef15)
      41  
      42  #define run(T, pattern, i) \
      43  {                          \
      44  T *q = p;                  \
      45  q[i] = pattern;            \
      46  p_##T = p;                 \
      47  T *r = test_##T ();        \
      48  assert (r == p_##T);       \
      49  assert (r == &q[i]);       \
      50  q[i] = 0;                  \
      51  }
      52  
      53  int main(void)
      54  {
      55    void *p = malloc (1024);
      56    assert (p);
      57    memset (p, '\0', 1024);
      58  
      59    run (uint8_t, 0xab, 0);
      60    run (uint8_t, 0xab, 1);
      61    run (uint8_t, 0xab, 13);
      62  
      63    run (uint16_t, 0xabcd, 0);
      64    run (uint16_t, 0xabcd, 1);
      65    run (uint16_t, 0xabcd, 13);
      66  
      67    run (uint32_t, 0xabcdef15, 0);
      68    run (uint32_t, 0xabcdef15, 1);
      69    run (uint32_t, 0xabcdef15, 13);
      70  
      71    run (int8_t, (int8_t)0xab, 0);
      72    run (int8_t, (int8_t)0xab, 1);
      73    run (int8_t, (int8_t)0xab, 13);
      74  
      75    run (int16_t, (int16_t)0xabcd, 0);
      76    run (int16_t, (int16_t)0xabcd, 1);
      77    run (int16_t, (int16_t)0xabcd, 13);
      78  
      79    run (int32_t, (int32_t)0xabcdef15, 0);
      80    run (int32_t, (int32_t)0xabcdef15, 1);
      81    run (int32_t, (int32_t)0xabcdef15, 13);
      82  
      83    return 0;
      84  }