summaryrefslogtreecommitdiffstats
path: root/tests/ir/loop-dce.slang
blob: c67227fb10fd65ef69bf640d4862d7fc6a7d8eb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -g0
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -g0

//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<uint> outputBuffer;

__target_intrinsic(hlsl, "@")
__target_intrinsic(glsl, "@")
__target_intrinsic(cpp, "@")
__target_intrinsic(cuda, "@")
[__readNone]
int produceSyntaxError() { return 0; }

[numthreads(1, 1, 1)]
void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
{
    int sum = 0;
    int array[100];
    // Next, this loop will be removed because there is no use of `array`.
    for (int i = 0; i < 100; i++)
    {
        // This loop must be removed, or we will fail downstream compilation.
        array[i] = i + produceSyntaxError();
    }

    // First, this loop will be removed because there is no use of `sum`.
    for (int i = 0; i < 100; i++)
    {
        // This loop must be removed, or we will fail downstream compilation.
        if (i < 50)
        {
            sum += array[i] + produceSyntaxError();
        }
        else
        {
            sum += i * 2 + produceSyntaxError();
        }
    }
    outputBuffer[0] = 1;
}