1uniform half4 colorRed, colorGreen; 2 3int globalValue = 0; 4 5noinline int side_effecting(int value) { 6 globalValue++; 7 return value; 8} 9 10bool test() { 11 const int x [3] = int[3](1, 2, 3); 12 const int xx[3] = int[3](1, 2, 3); 13 const int y [3] = int[3](1, 2, 4); 14 15 const int z = x[0] - y[0]; 16 const int a [x[z]] = int[1](1); 17 const int b [x[x[z]]] = int[2](1, 2); 18 const int c [x[x[x[z]]]] = int[3](1, 2, 3); 19 20 // Arrays with elements lacking side-effects can be optimized. 21 int two = 2; 22 int flatten0 = (int[3](x[0], two, 3))[0]; 23 int flatten1 = (int[3](x[0], two, 3))[1]; 24 int flatten2 = (int[3](x[0], two, 3))[2]; 25 26 // Arrays with elements that have side-effects are not eligible for optimization. 27 int noFlatten0 = (int[3](--two, side_effecting(2), 3))[0]; 28 int noFlatten1 = (int[3](side_effecting(1), 2, 3))[1]; 29 int noFlatten2 = (int[3](1, ++two, 3))[2]; 30 31 return (x == xx) && !(x != xx) && (x != y) && !(x == y) && 32 (x[0] == y[0]) && (c == x) && 33 (flatten0 == noFlatten0) && (flatten1 == noFlatten1) && (flatten2 == noFlatten2); 34} 35 36half4 main(float2 coords) { 37 return test() ? colorGreen : colorRed; 38} 39 40