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 no 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  #define test(T, pattern)   \
      18  __attribute__((noinline))  \
      19  T *test_##T (T *p)         \
      20  {                          \
      21    while (*p != (T)pattern) \
      22      ++p;                   \
      23    return p;                \
      24  }
      25  
      26  test (uint8_t,  0xab)
      27  test (uint16_t, 0xabcd)
      28  test (uint32_t, 0xabcdef15)
      29  
      30  test (int8_t,  0xab)
      31  test (int16_t, 0xabcd)
      32  test (int32_t, 0xabcdef15)
      33  
      34  #define run(T, pattern, i)      \
      35  {                               \
      36  T *q = p;                       \
      37  q[i] = (T)pattern;              \
      38  assert (test_##T (p) == &q[i]); \
      39  q[i] = 0;                       \
      40  }
      41  
      42  int main(void)
      43  {
      44    void *p = malloc (1024);
      45    assert (p);
      46    memset (p, 0, 1024);
      47  
      48    run (uint8_t, 0xab, 0);
      49    run (uint8_t, 0xab, 1);
      50    run (uint8_t, 0xab, 13);
      51  
      52    run (uint16_t, 0xabcd, 0);
      53    run (uint16_t, 0xabcd, 1);
      54    run (uint16_t, 0xabcd, 13);
      55  
      56    run (uint32_t, 0xabcdef15, 0);
      57    run (uint32_t, 0xabcdef15, 1);
      58    run (uint32_t, 0xabcdef15, 13);
      59  
      60    run (int8_t, 0xab, 0);
      61    run (int8_t, 0xab, 1);
      62    run (int8_t, 0xab, 13);
      63  
      64    run (int16_t, 0xabcd, 0);
      65    run (int16_t, 0xabcd, 1);
      66    run (int16_t, 0xabcd, 13);
      67  
      68    run (int32_t, 0xabcdef15, 0);
      69    run (int32_t, 0xabcdef15, 1);
      70    run (int32_t, 0xabcdef15, 13);
      71  
      72    return 0;
      73  }