1 /* Make sure that vector comaprison results are not unnecessarily ANDed 2 with vectors of 1. */ 3 /* { dg-do compile } */ 4 /* { dg-options "-O2 -ftree-vectorize" } */ 5 6 #pragma GCC target "+nosve" 7 8 #define COUNT1(X) if (X) count += 1 9 #define COUNT2(X) if (X) count -= 1 10 #define COUNT3(X) count += (X) 11 #define COUNT4(X) count -= (X) 12 13 #define COND1(X) (X) 14 #define COND2(X) ((X) ? 1 : 0) 15 #define COND3(X) ((X) ? -1 : 0) 16 #define COND4(X) ((X) ? 0 : 1) 17 #define COND5(X) ((X) ? 0 : -1) 18 19 #define TEST_LT(X, Y) ((X) < (Y)) 20 #define TEST_LE(X, Y) ((X) <= (Y)) 21 #define TEST_GT(X, Y) ((X) > (Y)) 22 #define TEST_GE(X, Y) ((X) >= (Y)) 23 #define TEST_EQ(X, Y) ((X) == (Y)) 24 #define TEST_NE(X, Y) ((X) != (Y)) 25 26 #define COUNT_LOOP(ID, TYPE, CMP_ARRAY, TEST, COUNT) \ 27 TYPE \ 28 reduc_##ID (__typeof__ (CMP_ARRAY[0]) x) \ 29 { \ 30 TYPE count = 0; \ 31 for (unsigned int i = 0; i < 1024; ++i) \ 32 COUNT (TEST (CMP_ARRAY[i], x)); \ 33 return count; \ 34 } 35 36 #define COND_LOOP(ID, ARRAY, CMP_ARRAY, TEST, COND) \ 37 void \ 38 plus_##ID (__typeof__ (CMP_ARRAY[0]) x) \ 39 { \ 40 for (unsigned int i = 0; i < 1024; ++i) \ 41 ARRAY[i] += COND (TEST (CMP_ARRAY[i], x)); \ 42 } \ 43 void \ 44 plusc_##ID (void) \ 45 { \ 46 for (unsigned int i = 0; i < 1024; ++i) \ 47 ARRAY[i] += COND (TEST (CMP_ARRAY[i], 10)); \ 48 } \ 49 void \ 50 minus_##ID (__typeof__ (CMP_ARRAY[0]) x) \ 51 { \ 52 for (unsigned int i = 0; i < 1024; ++i) \ 53 ARRAY[i] -= COND (TEST (CMP_ARRAY[i], x)); \ 54 } \ 55 void \ 56 minusc_##ID (void) \ 57 { \ 58 for (unsigned int i = 0; i < 1024; ++i) \ 59 ARRAY[i] += COND (TEST (CMP_ARRAY[i], 1)); \ 60 } 61 62 #define ALL_LOOPS(ID, ARRAY, CMP_ARRAY, TEST) \ 63 typedef __typeof__(ARRAY[0]) ID##_type; \ 64 COUNT_LOOP (ID##_1, ID##_type, CMP_ARRAY, TEST, COUNT1) \ 65 COUNT_LOOP (ID##_2, ID##_type, CMP_ARRAY, TEST, COUNT2) \ 66 COUNT_LOOP (ID##_3, ID##_type, CMP_ARRAY, TEST, COUNT3) \ 67 COUNT_LOOP (ID##_4, ID##_type, CMP_ARRAY, TEST, COUNT4) \ 68 COND_LOOP (ID##_1, ARRAY, CMP_ARRAY, TEST, COND1) \ 69 COND_LOOP (ID##_2, ARRAY, CMP_ARRAY, TEST, COND2) \ 70 COND_LOOP (ID##_3, ARRAY, CMP_ARRAY, TEST, COND3) \ 71 COND_LOOP (ID##_4, ARRAY, CMP_ARRAY, TEST, COND4) \ 72 COND_LOOP (ID##_5, ARRAY, CMP_ARRAY, TEST, COND5) 73 74 signed int asi[1024] __attribute__ ((aligned (16))); 75 unsigned int aui[1024] __attribute__ ((aligned (16))); 76 signed long long asl[1024] __attribute__ ((aligned (16))); 77 unsigned long long aul[1024] __attribute__ ((aligned (16))); 78 float af[1024] __attribute__ ((aligned (16))); 79 double ad[1024] __attribute__ ((aligned (16))); 80 81 ALL_LOOPS (si_si, aui, asi, TEST_LT) 82 ALL_LOOPS (ui_si, aui, asi, TEST_LE) 83 ALL_LOOPS (si_ui, aui, asi, TEST_GT) 84 ALL_LOOPS (ui_ui, aui, asi, TEST_GE) 85 ALL_LOOPS (sl_sl, asl, asl, TEST_NE) 86 ALL_LOOPS (ul_ul, aul, aul, TEST_EQ) 87 ALL_LOOPS (si_f, asi, af, TEST_LE) 88 ALL_LOOPS (ui_f, aui, af, TEST_GT) 89 ALL_LOOPS (sl_d, asl, ad, TEST_GE) 90 ALL_LOOPS (ul_d, aul, ad, TEST_GT) 91 92 /* { dg-final { scan-assembler-not "\tand\t" } } */ 93 /* { dg-final { scan-assembler-not "\tld\[^\t\]*\t\[wx\]" } } */ 94 /* { dg-final { scan-assembler-not "\tst\[^\t\]*\t\[wx\]" } } */ 95 /* { dg-final { scan-assembler "\tldr\tq" } } */ 96 /* { dg-final { scan-assembler "\tstr\tq" } } */ 97