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