10SN/A/* PR tree-optimization/51581 */ 2157SN/A/* { dg-require-effective-target int32plus } */ 30SN/A 40SN/Aextern void abort (void); 50SN/A 60SN/A#define N 4096 7157SN/Aint a[N], c[N]; 80SN/Aunsigned int b[N], d[N]; 9157SN/A 100SN/A__attribute__((noinline, noclone)) void 110SN/Af1 (void) 120SN/A{ 130SN/A int i; 140SN/A for (i = 0; i < N; i++) 150SN/A c[i] = a[i] % 3; 160SN/A} 170SN/A 180SN/A__attribute__((noinline, noclone)) void 190SN/Af2 (void) 200SN/A{ 21157SN/A int i; 22157SN/A for (i = 0; i < N; i++) 23157SN/A d[i] = b[i] % 3; 240SN/A} 250SN/A 260SN/A__attribute__((noinline, noclone)) void 270SN/Af3 (void) 280SN/A{ 290SN/A int i; 300SN/A for (i = 0; i < N; i++) 310SN/A c[i] = a[i] % 18; 320SN/A} 330SN/A 340SN/A__attribute__((noinline, noclone)) void 350SN/Af4 (void) 360SN/A{ 370SN/A int i; 380SN/A for (i = 0; i < N; i++) 390SN/A d[i] = b[i] % 18; 400SN/A} 410SN/A 420SN/A__attribute__((noinline, noclone)) void 430SN/Af5 (void) 440SN/A{ 450SN/A int i; 460SN/A for (i = 0; i < N; i++) 470SN/A c[i] = a[i] % 19; 480SN/A} 490SN/A 500SN/A__attribute__((noinline, noclone)) void 510SN/Af6 (void) 520SN/A{ 530SN/A int i; 540SN/A for (i = 0; i < N; i++) 550SN/A d[i] = b[i] % 19; 560SN/A} 570SN/A 580SN/A#if __SIZEOF_INT__ == 4 && __SIZEOF_LONG_LONG__ == 8 590SN/A__attribute__((noinline, noclone)) void 600SN/Af7 (void) 610SN/A{ 620SN/A int i; 630SN/A for (i = 0; i < N; i++) 640SN/A { 650SN/A int x = (int) ((unsigned long long) (a[i] * 0x55555556LL) >> 32) - (a[i] >> 31); 660SN/A c[i] = a[i] - x * 3; 670SN/A } 680SN/A} 690SN/A 700SN/A__attribute__((noinline, noclone)) void 71f8 (void) 72{ 73 int i; 74 for (i = 0; i < N; i++) 75 { 76 unsigned int x = ((unsigned int) ((b[i] * 0xaaaaaaabULL) >> 32) >> 1); 77 d[i] = b[i] - x * 3; 78 } 79} 80 81__attribute__((noinline, noclone)) void 82f9 (void) 83{ 84 int i; 85 for (i = 0; i < N; i++) 86 { 87 int x = (((int) ((unsigned long long) (a[i] * 0x38e38e39LL) >> 32)) >> 2) - (a[i] >> 31); 88 c[i] = a[i] - x * 18; 89 } 90} 91 92__attribute__((noinline, noclone)) void 93f10 (void) 94{ 95 int i; 96 for (i = 0; i < N; i++) 97 { 98 unsigned int x = (unsigned int) ((b[i] * 0x38e38e39ULL) >> 32) >> 2; 99 d[i] = b[i] - x * 18; 100 } 101} 102 103__attribute__((noinline, noclone)) void 104f11 (void) 105{ 106 int i; 107 for (i = 0; i < N; i++) 108 { 109 int x = (((int) ((unsigned long long) (a[i] * 0x6bca1af3LL) >> 32)) >> 3) - (a[i] >> 31); 110 c[i] = a[i] - x * 19; 111 } 112} 113 114__attribute__((noinline, noclone)) void 115f12 (void) 116{ 117 int i; 118 for (i = 0; i < N; i++) 119 { 120 unsigned int tmp = (b[i] * 0xaf286bcbULL) >> 32; 121 unsigned int x = (((b[i] - tmp) >> 1) + tmp) >> 4; 122 d[i] = b[i] - x * 19; 123 } 124} 125#endif 126 127int 128main () 129{ 130 int i; 131 for (i = 0; i < N; i++) 132 { 133 asm (""); 134 a[i] = i - N / 2; 135 b[i] = i; 136 } 137 a[0] = -__INT_MAX__ - 1; 138 a[1] = -__INT_MAX__; 139 a[N - 1] = __INT_MAX__; 140 b[N - 1] = ~0; 141 f1 (); 142 f2 (); 143 for (i = 0; i < N; i++) 144 if (c[i] != a[i] % 3 || d[i] != b[i] % 3) 145 abort (); 146 f3 (); 147 f4 (); 148 for (i = 0; i < N; i++) 149 if (c[i] != a[i] % 18 || d[i] != b[i] % 18) 150 abort (); 151 f5 (); 152 f6 (); 153 for (i = 0; i < N; i++) 154 if (c[i] != a[i] % 19 || d[i] != b[i] % 19) 155 abort (); 156#if __SIZEOF_INT__ == 4 && __SIZEOF_LONG_LONG__ == 8 157 f7 (); 158 f8 (); 159 for (i = 0; i < N; i++) 160 if (c[i] != a[i] % 3 || d[i] != b[i] % 3) 161 abort (); 162 f9 (); 163 f10 (); 164 for (i = 0; i < N; i++) 165 if (c[i] != a[i] % 18 || d[i] != b[i] % 18) 166 abort (); 167 f11 (); 168 f12 (); 169 for (i = 0; i < N; i++) 170 if (c[i] != a[i] % 19 || d[i] != b[i] % 19) 171 abort (); 172#endif 173 return 0; 174} 175