summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/function-calls/forceinline-multiple-cases.slang
blob: 3f1cfc0f7ea4092065b485d0910dcbe7924de621 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//TEST:SIMPLE(filecheck=CHECK): -stage compute -entry computeMain -target spirv -O0 -g3
RWStructuredBuffer<int> outputBuffer;

// Function with a single basic block
[ForceInline]
int basicBlockFunc(int value1, int value2)
{
    // Simple operation that should be inlined
    return value1 * 2 + value2;
}

// Function with multiple basic blocks
[ForceInline]
int multipleBlockFunc(int value1, int value2)
{
    int result = value1 * 2;
    
    // Add a condition to create multiple basic blocks
    if (value1 > value2)
    {
        result += value2 * 3;
    }
    else
    {
        result -= value2;
    }
    
    return result;
}

// Test case a: Multiple calls to basic block function
int testMultipleBasicBlockCalls()
{
    int result = basicBlockFunc(10, 5);
    result += basicBlockFunc(20, 15);
    result += basicBlockFunc(30, 25);
    return result;
}

// Test case b: Multiple calls to multiple block function
int testMultipleBlockCalls()
{
    int result = multipleBlockFunc(10, 5);
    result += multipleBlockFunc(20, 25);
    result += multipleBlockFunc(30, 25);
    return result;
}

// Test case c: One call to basic block, other instructions, another call to basic block
int testBasicBlockWithInstructions()
{
    int result = basicBlockFunc(10, 5);
    
    // Some other instructions
    result *= 2;
    result += 10;
    
    result += basicBlockFunc(20, 15);
    return result;
}

// Test case d: One call to multiple block func, other instructions, another call to multiple block func
int testMultipleBlockWithInstructions()
{
    int result = multipleBlockFunc(10, 5);
    
    // Some other instructions
    result *= 2;
    result += 10;
    
    result += multipleBlockFunc(20, 25);
    return result;
}

// Test case e: One call to basic block, other instructions, call to multiple block
int testBasicToMultipleBlock()
{
    int result = basicBlockFunc(10, 5);
    
    // Some other instructions
    result *= 2;
    result += 10;
    
    result += multipleBlockFunc(20, 25);
    return result;
}

// Additional test case: Mixed calls with condition
int testMixedCallsWithCondition()
{
    int result = basicBlockFunc(15, 7);
    if (result > 30)
    {
        result += multipleBlockFunc(8, 3);
    }
    else
    {
        result += multipleBlockFunc(12, 9);
    }
    return result;
}

[numthreads(8, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
    // Call all test functions directly and store results in different indices
    
    // Test case a: Multiple calls to basic block function
    outputBuffer[0] = testMultipleBasicBlockCalls();
    
    // Test case b: Multiple calls to multiple block function
    outputBuffer[1] = testMultipleBlockCalls();
    
    // Test case c: One call to basic block, other instructions, another call to basic block
    outputBuffer[2] = testBasicBlockWithInstructions();
    
    // Test case d: One call to multiple block func, other instructions, another call to multiple block func
    outputBuffer[3] = testMultipleBlockWithInstructions();
    
    // Test case e: One call to basic block, other instructions, call to multiple block
    outputBuffer[4] = testBasicToMultipleBlock();
    
    // Additional test case: Mixed calls with condition
    outputBuffer[5] = testMixedCallsWithCondition();
    
    // Set any remaining indices to 0
    if (dispatchThreadID.x >= 6)
    {
        outputBuffer[dispatchThreadID.x] = 0;
    }
}

// CHECK-COUNT-14: %{{[0-9]+}} = OpExtInst %void %{{[0-9]+}} DebugInlinedAt %uint_{{[0-9]+}} %{{[0-9]+}}
// CHECK-NOT: %{{[0-9]+}} = OpExtInst %void %{{[0-9]+}} DebugInlinedAt %uint_{{[0-9]+}} %{{[0-9]+}}
// CHECK-COUNT-28: %{{[0-9]+}} = OpExtInst %void %{{[0-9]+}} DebugScope %{{[0-9]+}} %{{[0-9]+}}
// CHECK-NOT: %{{[0-9]+}} = OpExtInst %void %{{[0-9]+}} DebugScope %{{[0-9]+}} %{{[0-9]+}}

// TODO: Verified manually that the count in the .actual file is 28. 
// But the pattern matcher complains to match.
// _CHECK-COUNT-28: %{{[0-9]+}} = OpExtInst %void %{{[0-9]+}} DebugNoScope
// _CHECK-NOT: %{{[0-9]+}} = OpExtInst %void %{{[0-9]+}} DebugNoScope