1  /* { dg-options "-O2 -fdump-ipa-profile-optimized -mtune=core2" } */
       2  /* { dg-skip-if "" { ! { i?86-*-* x86_64-*-* } } } */
       3  
       4  char *buffer1;
       5  char *buffer2;
       6  
       7  /* Bzero is not tested because it gets transformed into memset.  */
       8  
       9  #define DEFINE_TEST(N) \
      10  __attribute__((noinline)) \
      11  void memcpy_test_ ## N (int len) \
      12  { \
      13    __builtin_memcpy (buffer1, buffer2, len); \
      14  } \
      15   \
      16  __attribute__((noinline)) \
      17  void mempcpy_test_ ## N (int len) \
      18  { \
      19    __builtin_mempcpy (buffer1, buffer2, len); \
      20  } \
      21   \
      22  __attribute__((noinline)) \
      23  void memset_test_ ## N (int len) \
      24  { \
      25    __builtin_memset (buffer1, 'c', len); \
      26  } \
      27  __attribute__((noinline)) \
      28  void memmove_test_ ## N (int len) \
      29  { \
      30    __builtin_memmove (buffer1, buffer2, len); \
      31  } \
      32   \
      33  void test_stringops_ ## N(int len) \
      34  { \
      35    memcpy_test_## N (len); \
      36    mempcpy_test_ ## N (len); \
      37    memset_test_ ## N (len); \
      38    memmove_test_ ## N (len); \
      39  } \
      40   \
      41  void test_stringops_with_values_ ## N (int common, int not_common) \
      42  { \
      43    int i; \
      44    for (i = 0; i < 1000; i++) \
      45      { \
      46        if (i > 990) \
      47  	test_stringops_ ## N (not_common); \
      48        else \
      49  	test_stringops_ ## N (common); \
      50      } \
      51  }
      52  
      53  DEFINE_TEST(0);
      54  DEFINE_TEST(1);
      55  DEFINE_TEST(2);
      56  
      57  int main() {
      58    buffer1 = __builtin_malloc (1000);
      59    buffer2 = __builtin_malloc (1000);
      60  
      61    test_stringops_with_values_0 (8, 55);
      62    test_stringops_with_values_1 (55, 55);
      63    test_stringops_with_values_2 (257, 55);
      64  
      65    return 0;
      66  }
      67  
      68  /* { dg-final-use-not-autofdo { scan-ipa-dump "Transformation done: single value 8 stringop for BUILT_IN_MEMCPY" "profile" } } */
      69  /* { dg-final-use-not-autofdo { scan-ipa-dump "Transformation done: single value 55 stringop for BUILT_IN_MEMCPY" "profile" } } */
      70  /* { dg-final-use-not-autofdo { scan-ipa-dump-times "Transformation done: single value 32 stringop for BUILT_IN_MEMCPY" 0 "profile" } } */
      71  
      72  /* { dg-final-use-not-autofdo { scan-ipa-dump "Transformation done: single value 8 stringop for BUILT_IN_MEMPCPY" "profile" } } */
      73  /* { dg-final-use-not-autofdo { scan-ipa-dump "Transformation done: single value 55 stringop for BUILT_IN_MEMPCPY" "profile" } } */
      74  /* { dg-final-use-not-autofdo { scan-ipa-dump-times "Transformation done: single value 32 stringop for BUILT_IN_MEMPCPY" 0 "profile" } } */
      75  
      76  /* { dg-final-use-not-autofdo { scan-ipa-dump "Transformation done: single value 8 stringop for BUILT_IN_MEMSET" "profile" } } */
      77  /* { dg-final-use-not-autofdo { scan-ipa-dump "Transformation done: single value 55 stringop for BUILT_IN_MEMSET" "profile" } } */
      78  /* { dg-final-use-not-autofdo { scan-ipa-dump-times "Transformation done: single value 32 stringop for BUILT_IN_MEMSET" 0 "profile" } } */
      79  
      80  /* { dg-final-use-not-autofdo { scan-ipa-dump "Transformation done: single value 8 stringop for BUILT_IN_MEMMOVE" "profile" } } */
      81  /* { dg-final-use-not-autofdo { scan-ipa-dump "Transformation done: single value 55 stringop for BUILT_IN_MEMMOVE" "profile" } } */
      82  /* { dg-final-use-not-autofdo { scan-ipa-dump-times "Transformation done: single value 32 stringop for BUILT_IN_MEMMOVE" 0 "profile" } } */