1 /* { dg-do compile } */ 2 /* { dg-options "-O2 -fdump-tree-ivopts-details" } */ 3 #include <string.h> 4 #include <stdlib.h> 5 6 #define MAX_NUM (256) 7 8 void sort_pointers(size_t n,void ** pointers,void ** work)9sort_pointers (size_t n, void **pointers, void **work) 10 { 11 typedef unsigned char digit_t; 12 unsigned int count[MAX_NUM]; 13 int big_endian_p; 14 size_t i; 15 size_t j; 16 17 if ((sizeof (void *) / sizeof (digit_t)) % 2 != 0) 18 abort (); 19 20 for (i = 0, j = 0; i < sizeof (size_t); ++i) 21 { 22 j *= MAX_NUM; 23 j += i; 24 } 25 26 big_endian_p = (((char *)&j)[0] == 0); 27 for (i = 0; i < sizeof (void *) / sizeof (digit_t); ++i) 28 { 29 digit_t *digit; 30 digit_t *bias; 31 digit_t *top; 32 unsigned int *countp; 33 void **pointerp; 34 35 if (big_endian_p) 36 j = sizeof (void *) / sizeof (digit_t) - i; 37 else 38 j = i; 39 40 memset (count, 0, MAX_NUM * sizeof (unsigned int)); 41 bias = ((digit_t *) pointers) + j; 42 top = ((digit_t *) (pointers + n)) + j; 43 for (digit = bias; 44 digit < top; 45 digit += sizeof (void *) / sizeof (digit_t)) 46 ++count[*digit]; 47 48 for (countp = count + 1; countp < count + MAX_NUM; ++countp) 49 *countp += countp[-1]; 50 51 for (pointerp = pointers + n - 1; pointerp >= pointers; --pointerp) 52 work[--count[((digit_t *) pointerp)[j]]] = *pointerp; 53 54 pointerp = pointers; 55 pointers = work; 56 work = pointerp; 57 } 58 } 59 60 /* { dg-final { scan-tree-dump-not "base \[^\\n\]*&MEM\\\[" "ivopts" } } */ 61