diff options
| author | Yong He <yonghe@outlook.com> | 2023-01-27 16:41:31 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-27 16:41:31 -0800 |
| commit | 4a66e9729175a89833e5db784bb64e6a7f60cdf2 (patch) | |
| tree | 6a3cb0da3a6682ac0f8b06e66cb8e5fcd6dff279 /tests | |
| parent | 93a6b6119b6b65c4f6b00ca12d745e21b679c82f (diff) | |
Register allocation during phi elimination. (#2613)
* Register allocation during phi elimination.
* Enhance the test case.
* Cleanup line breaks in test case.
* remove unncessary line break changes.
* More cleanups.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests')
7 files changed, 105 insertions, 61 deletions
diff --git a/tests/experimental/liveness/liveness-3.slang.expected b/tests/experimental/liveness/liveness-3.slang.expected index 58f562d86..dac9ff1bd 100644 --- a/tests/experimental/liveness/liveness-3.slang.expected +++ b/tests/experimental/liveness/liveness-3.slang.expected @@ -52,13 +52,13 @@ int calcThing_0(int offset_0) livenessStart_2(idx_0, 0); const int _S3[3] = { 0, 0, 0 }; idx_0 = _S3; - int _S4 = _S2; int i_0; - int _S5; + int _S4; + int _S5 = _S2; livenessStart_1(i_0, 0); i_0 = 0; - livenessStart_1(_S5, 0); - _S5 = _S4; + livenessStart_1(_S4, 0); + _S4 = _S5; for(;;) { if(i_0 < 17) @@ -74,32 +74,32 @@ int calcThing_0(int offset_0) int _S7; if(_S6 != 0) { - int _S8 = _S5; - livenessEnd_0(_S5, 0); + int _S8 = _S4; + livenessEnd_0(_S4, 0); int _S9 = _S8 + 1; livenessStart_1(_S7, 0); _S7 = _S9; } else { - int _S10 = _S5; - livenessEnd_0(_S5, 0); + int _S10 = _S4; + livenessEnd_0(_S4, 0); livenessStart_1(_S7, 0); _S7 = _S10; } idx_0[modRange_0] = idx_0[modRange_0] + (_S7 + i_0); i_0 = i_0 + 1; - livenessStart_1(_S5, 0); + livenessStart_1(_S4, 0); int _S11 = _S7; livenessEnd_0(_S7, 0); - _S5 = _S11; + _S4 = _S11; } livenessEnd_0(i_0, 0); livenessEnd_0(_S2, 0); int _S12 = (k_0 + 7) % 5; if(_S12 == 4) { - livenessEnd_0(_S5, 0); + livenessEnd_0(_S4, 0); livenessEnd_1(idx_0, 0); livenessEnd_0(k_0, 0); livenessEnd_2(another_0, 0); @@ -114,8 +114,8 @@ int calcThing_0(int offset_0) int total_1 = _S16 + _S15; k_0 = k_0 + 1; livenessStart_1(_S2, 0); - int _S17 = _S5; - livenessEnd_0(_S5, 0); + int _S17 = _S4; + livenessEnd_0(_S4, 0); _S2 = _S17; livenessStart_1(total_0, 0); total_0 = total_1; diff --git a/tests/experimental/liveness/liveness-5.slang.expected b/tests/experimental/liveness/liveness-5.slang.expected index ea6e37036..a8a9707d7 100644 --- a/tests/experimental/liveness/liveness-5.slang.expected +++ b/tests/experimental/liveness/liveness-5.slang.expected @@ -72,35 +72,26 @@ int calcThing_0(int offset_0) } livenessEnd_0(k_0, 0); livenessEnd_1(another_0, 0); - int total_2; if(total_0 > 4) { - int _S5 = total_0; - livenessEnd_0(total_0, 0); - int _S6 = - _S5; - livenessStart_1(total_2, 0); - total_2 = _S6; + total_0 = - total_0; } else { - int _S7 = total_0; - livenessEnd_0(total_0, 0); - livenessStart_1(total_2, 0); - total_2 = _S7; } - return total_2; + return total_0; } -layout(std430, binding = 0) buffer _S8 { +layout(std430, binding = 0) buffer _S5 { int _data[]; } outputBuffer_0; layout(local_size_x = 4, local_size_y = 1, local_size_z = 1) in; void main() { int index_0 = int(gl_GlobalInvocationID.x); - uint _S9 = uint(index_0); - int _S10 = calcThing_0(index_0); - ((outputBuffer_0)._data[(_S9)]) = _S10; + uint _S6 = uint(index_0); + int _S7 = calcThing_0(index_0); + ((outputBuffer_0)._data[(_S6)]) = _S7; return; } diff --git a/tests/experimental/liveness/liveness-6.slang.expected b/tests/experimental/liveness/liveness-6.slang.expected index 26a537330..402e19886 100644 --- a/tests/experimental/liveness/liveness-6.slang.expected +++ b/tests/experimental/liveness/liveness-6.slang.expected @@ -81,35 +81,26 @@ int calcThing_0(int offset_0) } livenessEnd_0(k_0, 0); livenessEnd_1(another_0, 0); - int total_3; if(total_0 > 4) { - int _S8 = total_0; - livenessEnd_0(total_0, 0); - int _S9 = - _S8; - livenessStart_1(total_3, 0); - total_3 = _S9; + total_0 = - total_0; } else { - int _S10 = total_0; - livenessEnd_0(total_0, 0); - livenessStart_1(total_3, 0); - total_3 = _S10; } - return total_3; + return total_0; } -layout(std430, binding = 0) buffer _S11 { +layout(std430, binding = 0) buffer _S8 { int _data[]; } outputBuffer_0; layout(local_size_x = 4, local_size_y = 1, local_size_z = 1) in; void main() { int index_0 = int(gl_GlobalInvocationID.x); - uint _S12 = uint(index_0); - int _S13 = calcThing_0(index_0); - ((outputBuffer_0)._data[(_S12)]) = _S13; + uint _S9 = uint(index_0); + int _S10 = calcThing_0(index_0); + ((outputBuffer_0)._data[(_S9)]) = _S10; return; } diff --git a/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-make-hit.slang.1.expected b/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-make-hit.slang.1.expected index 15221b921..847eab926 100644 --- a/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-make-hit.slang.1.expected +++ b/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-make-hit.slang.1.expected @@ -65,16 +65,14 @@ uint calcValue_0(hitObjectNV hit_0) else { bool _S7 = (hitObjectIsMissNV((hit_0))); - uint r_3; if(_S7) { - r_3 = 1U; + r_0 = 1U; } else { - r_3 = 0U; + r_0 = 0U; } - r_0 = r_3; } return r_0; } @@ -96,13 +94,13 @@ void main() RayDesc_0 _S11 = ray_2; hitObjectNV hitObj_0; hitObjectRecordHitWithIndexNV(hitObj_0, scene_0, int(uint(idx_0)), int(uint(idx_0 * 2)), int(uint(idx_0 * 3)), 0U, 0U, _S11.Origin_0, _S11.TMin_0, _S11.Direction_0, _S11.TMax_0, (0)); - uint r_4 = calcValue_0(hitObj_0); + uint r_3 = calcValue_0(hitObj_0); RayDesc_0 _S12 = ray_2; hitObjectNV hitObj_1; hitObjectRecordHitNV(hitObj_1, scene_0, int(uint(idx_0)), int(uint(idx_0 * 3)), int(uint(idx_0 * 2)), 0U, 0U, 4U, _S12.Origin_0, _S12.TMin_0, _S12.Direction_0, _S12.TMax_0, (0)); uint _S13 = calcValue_0(hitObj_1); - uint r_5 = r_4 + _S13; - ((outputBuffer_0)._data[(uint(idx_0))]) = r_5; + uint r_4 = r_3 + _S13; + ((outputBuffer_0)._data[(uint(idx_0))]) = r_4; return; } diff --git a/tests/ir/ssa-reg-alloc.slang b/tests/ir/ssa-reg-alloc.slang new file mode 100644 index 000000000..3bfd795a8 --- /dev/null +++ b/tests/ir/ssa-reg-alloc.slang @@ -0,0 +1,68 @@ +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<uint> outputBuffer; + +int test1(uint p) +{ + int a, b; + if (p > 1) + { + a = 1; + b = 2; + } + else + { + a = 2; + b = 3; + } + // b is not used and should not interfere the result of a. + return a; +} + +int test2(uint p) +{ + int a, b; + if (p > 1) + { + a = 1; + b = 2; + } + else + { + a = 2; + b = 3; + } + // a is not used and should not interfere the result of b. + return b; +} + +int test3(uint p) +{ + int a = 1; + int b = 5; + + if (p > 0) a = 2; + if (p > 0) b = 3; + + // a and b are now register allocated. + // The first block of the loop will have IRParams in the form of (a, b) + for (int i = 0; i <= p + 2; i++) + { + let tmp = a; + a = b; + b = tmp; + // The branch back to the loop header will have phi args: (b, a) + // Phi-elmination must handle this case of concurrent assignment correctly. + } + return a - b; // should be 4 when p == 0. +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + let rs1 = test1(dispatchThreadID.x) + test2(dispatchThreadID.x); + outputBuffer[0] = rs1; + outputBuffer[1] = test3(0); +} diff --git a/tests/ir/ssa-reg-alloc.slang.expected.txt b/tests/ir/ssa-reg-alloc.slang.expected.txt new file mode 100644 index 000000000..e43a2b945 --- /dev/null +++ b/tests/ir/ssa-reg-alloc.slang.expected.txt @@ -0,0 +1,4 @@ +5 +4 +0 +0 diff --git a/tests/pipeline/ray-tracing/trace-ray-inline.slang.glsl b/tests/pipeline/ray-tracing/trace-ray-inline.slang.glsl index f9e94bb30..389dae05a 100644 --- a/tests/pipeline/ray-tracing/trace-ray-inline.slang.glsl +++ b/tests/pipeline/ray-tracing/trace-ray-inline.slang.glsl @@ -106,14 +106,10 @@ void main() tHit_1 = 0.00000000000000000000; bool _S6 = myProceduralIntersection_0(tHit_1, candidateProceduralAttrs_0); - MyProceduralHitAttrs_0 committedProceduralAttrs_2; - if(_S6) { bool _S7 = myProceduralAnyHit_0(payload_5); - MyProceduralHitAttrs_0 committedProceduralAttrs_3; - if(_S7) { rayQueryGenerateIntersectionEXT(query_0, tHit_1); @@ -126,28 +122,24 @@ void main() { } - committedProceduralAttrs_3 = _S8; + committedProceduralAttrs_1 = _S8; } else { - committedProceduralAttrs_3 = committedProceduralAttrs_0; + committedProceduralAttrs_1 = committedProceduralAttrs_0; } - committedProceduralAttrs_2 = committedProceduralAttrs_3; - } else { - committedProceduralAttrs_2 = committedProceduralAttrs_0; + committedProceduralAttrs_1 = committedProceduralAttrs_0; } - committedProceduralAttrs_1 = committedProceduralAttrs_2; - break; } case 0U: |
