diff options
| author | Yong He <yonghe@outlook.com> | 2023-02-24 10:01:47 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-24 10:01:47 -0800 |
| commit | bd6306cdaa4a49344658bd026721b6532e103d09 (patch) | |
| tree | bb7f666d426e6cfc7777a3ccac0a1d628588eb39 /tests/experimental | |
| parent | e8c08e7ecb1124f115a1d1042277776193122b57 (diff) | |
More control flow simplifications. (#2673)
* More control flow and Phi param simplifications.
* Fix.
* Fix gcc error.
* Fix.
* More IR cleanup.
* Fix bug in phi param dce + ifelse simplify.
* Propagate and DCE side-effect-free functions.
* Enhance CFG simplifcation to remove loops with no side effects.
* Fix.
* Fixes.
* Fix tests. Add [__AlwaysFoldIntoUseSite] for rayPayloadLocation.
* More cleanup.
* Fixes.
* Fix.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests/experimental')
6 files changed, 125 insertions, 111 deletions
diff --git a/tests/experimental/liveness/liveness-2.slang.expected b/tests/experimental/liveness/liveness-2.slang.expected index c742fa1fc..16883c1fd 100644 --- a/tests/experimental/liveness/liveness-2.slang.expected +++ b/tests/experimental/liveness/liveness-2.slang.expected @@ -51,9 +51,8 @@ layout(local_size_x = 4, local_size_y = 1, local_size_z = 1) in; void main() { int index_0 = int(gl_GlobalInvocationID.x); - uint _S4 = uint(index_0); - int _S5 = calcThing_0(index_0); - ((outputBuffer_0)._data[(_S4)]) = _S5; + int _S4 = calcThing_0(index_0); + ((outputBuffer_0)._data[(uint(index_0))]) = _S4; return; } diff --git a/tests/experimental/liveness/liveness-3.slang.expected b/tests/experimental/liveness/liveness-3.slang.expected index 4dff6b37a..cb093a640 100644 --- a/tests/experimental/liveness/liveness-3.slang.expected +++ b/tests/experimental/liveness/liveness-3.slang.expected @@ -53,12 +53,15 @@ int calcThing_0(int offset_0) idx_0[0] = 0; idx_0[1] = 0; idx_0[2] = 0; + int _S2 = (k_0 + 7) % 5; + bool _S3 = _S2 == 4; + int k_1 = k_0 + 1; int i_0; livenessStart_1(i_0, 0); i_0 = 0; - int _S2; - livenessStart_1(_S2, 0); - _S2 = _S1; + int _S4; + livenessStart_1(_S4, 0); + _S4 = _S1; for(;;) { if(i_0 < 17) @@ -70,74 +73,74 @@ int calcThing_0(int offset_0) } int modRange_0 = i_0 % 3; another_0[i_0 & 1] = another_0[i_0 & 1] + modRange_0; - int _S3 = i_0 % 3; - int _S4; - if(_S3 != 0) + int _S5 = i_0 % 3; + int _S6; + if(modRange_0 != 0) { - int _S5 = _S2; - livenessEnd_0(_S2, 0); - int _S6 = _S5 + 1; - livenessStart_1(_S4, 0); - _S4 = _S6; + int _S7 = _S4; + livenessEnd_0(_S4, 0); + int _S8 = _S7 + 1; + livenessStart_1(_S6, 0); + _S6 = _S8; } else { - int _S7 = _S2; - livenessEnd_0(_S2, 0); - livenessStart_1(_S4, 0); - _S4 = _S7; + int _S9 = _S4; + livenessEnd_0(_S4, 0); + livenessStart_1(_S6, 0); + _S6 = _S9; } - idx_0[modRange_0] = idx_0[modRange_0] + (_S4 + i_0); + idx_0[modRange_0] = idx_0[modRange_0] + (_S6 + i_0); i_0 = i_0 + 1; - livenessStart_1(_S2, 0); - int _S8 = _S4; - livenessEnd_0(_S4, 0); - _S2 = _S8; + livenessStart_1(_S4, 0); + int _S10 = _S6; + livenessEnd_0(_S6, 0); + _S4 = _S10; } livenessEnd_0(i_0, 0); livenessEnd_0(_S1, 0); - int _S9 = (k_0 + 7) % 5; - if(_S9 == 4) + livenessEnd_0(k_0, 0); + if(_S3) { - livenessEnd_0(_S2, 0); + livenessEnd_0(_S4, 0); livenessEnd_1(idx_0, 0); - livenessEnd_0(k_0, 0); livenessEnd_2(another_0, 0); return total_0; } - int _S10 = idx_0[0] + idx_0[1]; - int _S11 = idx_0[2]; + int _S11 = idx_0[0] + idx_0[1]; + int _S12 = idx_0[2]; livenessEnd_1(idx_0, 0); - int _S12 = _S10 + _S11; - int _S13 = total_0; + int _S13 = _S11 + _S12; + int _S14 = total_0; livenessEnd_0(total_0, 0); - int total_1 = _S13 + _S12; - k_0 = k_0 + 1; + int total_1 = _S14 + _S13; + livenessStart_1(k_0, 0); + k_0 = k_1; livenessStart_1(_S1, 0); - int _S14 = _S2; - livenessEnd_0(_S2, 0); - _S1 = _S14; + int _S15 = _S4; + livenessEnd_0(_S4, 0); + _S1 = _S15; livenessStart_1(total_0, 0); total_0 = total_1; } livenessEnd_0(_S1, 0); livenessEnd_0(k_0, 0); livenessEnd_2(another_0, 0); - int _S15 = total_0; + int _S16 = total_0; livenessEnd_0(total_0, 0); - return - _S15; + return - _S16; } -layout(std430, binding = 0) buffer _S16 { +layout(std430, binding = 0) buffer _S17 { 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 _S17 = uint(index_0); - int _S18 = calcThing_0(index_0); - ((outputBuffer_0)._data[(_S17)]) = _S18; + uint _S18 = uint(index_0); + int _S19 = calcThing_0(index_0); + ((outputBuffer_0)._data[(_S18)]) = _S19; return; } diff --git a/tests/experimental/liveness/liveness-4.slang.expected b/tests/experimental/liveness/liveness-4.slang.expected index cd97f8057..efc2e3846 100644 --- a/tests/experimental/liveness/liveness-4.slang.expected +++ b/tests/experimental/liveness/liveness-4.slang.expected @@ -36,6 +36,9 @@ int calcThing_0(int offset_0) { break; } + int _S1 = (k_0 + 7) % 5; + bool _S2 = _S1 == 4; + int k_1 = k_0 + 1; int i_0; livenessStart_1(i_0, 0); i_0 = 0; @@ -52,30 +55,30 @@ int calcThing_0(int offset_0) i_0 = i_0 + 1; } livenessEnd_0(i_0, 0); - int _S1 = (k_0 + 7) % 5; - if(_S1 == 4) + livenessEnd_0(k_0, 0); + if(_S2) { - livenessEnd_0(k_0, 0); livenessEnd_1(another_0, 0); return 1; } - k_0 = k_0 + 1; + livenessStart_1(k_0, 0); + k_0 = k_1; } livenessEnd_0(k_0, 0); livenessEnd_1(another_0, 0); return -2; } -layout(std430, binding = 0) buffer _S2 { +layout(std430, binding = 0) buffer _S3 { 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 _S3 = uint(index_0); - int _S4 = calcThing_0(index_0); - ((outputBuffer_0)._data[(_S3)]) = _S4; + uint _S4 = uint(index_0); + int _S5 = calcThing_0(index_0); + ((outputBuffer_0)._data[(_S4)]) = _S5; return; } diff --git a/tests/experimental/liveness/liveness-5.slang.expected b/tests/experimental/liveness/liveness-5.slang.expected index 3693d3fde..e9fe9d652 100644 --- a/tests/experimental/liveness/liveness-5.slang.expected +++ b/tests/experimental/liveness/liveness-5.slang.expected @@ -39,6 +39,9 @@ int calcThing_0(int offset_0) { break; } + int _S1 = (k_0 + 7) % 5; + bool _S2 = _S1 == 4; + int k_1 = k_0 + 1; int i_0; livenessStart_1(i_0, 0); i_0 = 0; @@ -55,17 +58,17 @@ int calcThing_0(int offset_0) i_0 = i_0 + 1; } livenessEnd_0(i_0, 0); - int _S1 = total_0; + livenessEnd_0(k_0, 0); + int _S3 = total_0; livenessEnd_0(total_0, 0); - int total_1 = _S1 + another_0[k_0 & 1]; - int _S2 = (k_0 + 7) % 5; - if(_S2 == 4) + int total_1 = _S3 + another_0[k_0 & 1]; + if(_S2) { - livenessEnd_0(k_0, 0); livenessEnd_1(another_0, 0); return 1; } - k_0 = k_0 + 1; + livenessStart_1(k_0, 0); + k_0 = k_1; livenessStart_1(total_0, 0); total_0 = total_1; } @@ -81,16 +84,16 @@ int calcThing_0(int offset_0) return total_0; } -layout(std430, binding = 0) buffer _S3 { +layout(std430, binding = 0) buffer _S4 { 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 _S4 = uint(index_0); - int _S5 = calcThing_0(index_0); - ((outputBuffer_0)._data[(_S4)]) = _S5; + uint _S5 = uint(index_0); + int _S6 = calcThing_0(index_0); + ((outputBuffer_0)._data[(_S5)]) = _S6; return; } diff --git a/tests/experimental/liveness/liveness-6.slang.expected b/tests/experimental/liveness/liveness-6.slang.expected index 9c3bae815..b661c09bf 100644 --- a/tests/experimental/liveness/liveness-6.slang.expected +++ b/tests/experimental/liveness/liveness-6.slang.expected @@ -43,6 +43,10 @@ int calcThing_0(int offset_0) livenessStart_0(arr_0, 0); arr_0[0] = 2; arr_0[1] = 3; + int _S1 = k_0 & 1; + int _S2 = (k_0 + 7) % 5; + bool _S3 = _S2 == 4; + int k_1 = k_0 + 1; int i_0; livenessStart_1(i_0, 0); i_0 = 0; @@ -56,25 +60,24 @@ int calcThing_0(int offset_0) break; } another_0[i_0 & 1] = another_0[i_0 & 1] + (k_0 + i_0); - arr_0[k_0 & 1] = arr_0[k_0 & 1] + i_0; + arr_0[_S1] = arr_0[_S1] + i_0; i_0 = i_0 + 1; } livenessEnd_0(i_0, 0); - int _S1 = k_0 & 1; - int _S2 = total_0; + livenessEnd_0(k_0, 0); + int _S4 = total_0; livenessEnd_0(total_0, 0); - int total_1 = _S2 + another_0[_S1]; - int _S3 = arr_0[_S1]; + int total_1 = _S4 + another_0[_S1]; + int _S5 = arr_0[_S1]; livenessEnd_1(arr_0, 0); - int total_2 = total_1 + _S3; - int _S4 = (k_0 + 7) % 5; - if(_S4 == 4) + int total_2 = total_1 + _S5; + if(_S3) { - livenessEnd_0(k_0, 0); livenessEnd_1(another_0, 0); return 1; } - k_0 = k_0 + 1; + livenessStart_1(k_0, 0); + k_0 = k_1; livenessStart_1(total_0, 0); total_0 = total_2; } @@ -90,16 +93,16 @@ int calcThing_0(int offset_0) return total_0; } -layout(std430, binding = 0) buffer _S5 { +layout(std430, binding = 0) buffer _S6 { 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 _S6 = uint(index_0); - int _S7 = calcThing_0(index_0); - ((outputBuffer_0)._data[(_S6)]) = _S7; + uint _S7 = uint(index_0); + int _S8 = calcThing_0(index_0); + ((outputBuffer_0)._data[(_S7)]) = _S8; return; } diff --git a/tests/experimental/liveness/liveness.slang.expected b/tests/experimental/liveness/liveness.slang.expected index 4a81b8855..06809ffc3 100644 --- a/tests/experimental/liveness/liveness.slang.expected +++ b/tests/experimental/liveness/liveness.slang.expected @@ -21,6 +21,7 @@ void livenessEnd_1(spirv_by_reference int _0, spirv_literal int _1); int someSlowFunc_0(int a_0) { uint _S1 = uint(a_0); + int _S2 = a_0 * 20; uint v_0; livenessStart_0(v_0, 0); v_0 = _S1; @@ -29,20 +30,20 @@ int someSlowFunc_0(int a_0) i_0 = 0; for(;;) { - if(i_0 < a_0 * 20) + if(i_0 < _S2) { } else { break; } - uint _S2 = v_0 >> 1; - uint _S3 = v_0; + uint _S3 = v_0 >> 1; + uint _S4 = v_0; livenessEnd_0(v_0, 0); - uint _S4 = (_S2 | _S3 << 31) * uint(i_0); + uint _S5 = (_S3 | _S4 << 31) * uint(i_0); int i_1 = i_0 + 1; livenessStart_0(v_0, 0); - v_0 = _S4; + v_0 = _S5; i_0 = i_1; } livenessEnd_1(i_0, 0); @@ -58,12 +59,12 @@ struct SomeStruct_0 SomeStruct_0 makeSomeStruct_0() { - const int _S5[100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - SomeStruct_0 s_0 = { 0, 0, _S5 }; + const int _S6[100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + SomeStruct_0 s_0 = { 0, 0, _S6 }; return s_0; } -layout(std430, binding = 1) buffer _S6 { +layout(std430, binding = 1) buffer _S7 { int _data[]; } anotherBuffer_0; int doThing_0(SomeStruct_0 s_1) @@ -73,11 +74,12 @@ int doThing_0(SomeStruct_0 s_1) int somethingElse_0(inout SomeStruct_0 s_2) { - s_2.x_0 = s_2.x_0 + 1; - return s_2.x_0; + int _S8 = s_2.x_0 + 1; + s_2.x_0 = _S8; + return _S8; } -layout(std430, binding = 0) buffer _S7 { +layout(std430, binding = 0) buffer _S9 { int _data[]; } outputBuffer_0; spirv_instruction(id = 256) @@ -90,6 +92,12 @@ layout(local_size_x = 4, local_size_y = 1, local_size_z = 1) in; void main() { int index_0 = int(gl_GlobalInvocationID.x); + const int _S10[100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + int _S11 = index_0 & 7; + SomeStruct_0 _S12 = makeSomeStruct_0(); + int v_1 = someSlowFunc_0(index_0); + bool _S13 = (v_1 & 256) != 0; + int _S14 = v_1 & 3; int i_2; livenessStart_1(i_2, 0); i_2 = 0; @@ -105,23 +113,20 @@ void main() { break; } - int v_1 = someSlowFunc_0(index_0); SomeStruct_0 s_3; livenessStart_2(s_3, 0); SomeStruct_0 t_0; livenessStart_2(t_0, 0); - SomeStruct_0 _S8 = makeSomeStruct_0(); - t_0 = _S8; - const int _S9[100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + t_0 = _S12; SomeStruct_0 u_0; - if((v_1 & 256) != 0) + if(_S13) { - s_3.x_0 = ((anotherBuffer_0)._data[(uint(v_1 & 3))]); - t_0.x_0 = ((anotherBuffer_0)._data[(uint(v_1 & 3))]); + s_3.x_0 = ((anotherBuffer_0)._data[(uint(_S14))]); + t_0.x_0 = ((anotherBuffer_0)._data[(uint(_S14))]); livenessStart_2(u_0, 0); u_0.a_1 = 0; u_0.x_0 = 0; - u_0.c_0 = _S9; + u_0.c_0 = _S10; } else { @@ -129,37 +134,35 @@ void main() livenessStart_2(x_1, 0); x_1.a_1 = 0; x_1.x_0 = 0; - x_1.c_0 = _S9; - x_1.x_0 = ((anotherBuffer_0)._data[(uint(v_1 & 3))]) + 1; - SomeStruct_0 _S10 = x_1; + x_1.c_0 = _S10; + x_1.x_0 = ((anotherBuffer_0)._data[(uint(_S14))]) + 1; + SomeStruct_0 _S15 = x_1; livenessEnd_2(x_1, 0); livenessStart_2(u_0, 0); - u_0 = _S10; + u_0 = _S15; } - s_3.c_0[index_0 & 7] = s_3.c_0[index_0 & 7] + 1; - int _S11 = s_3.x_0 + t_0.x_0; - SomeStruct_0 _S12 = u_0; + s_3.c_0[_S11] = s_3.c_0[_S11] + 1; + int _S16 = s_3.x_0 + t_0.x_0; + SomeStruct_0 _S17 = u_0; livenessEnd_2(u_0, 0); - int _S13 = _S11 + _S12.x_0; - int _S14 = doThing_0(t_0); - int _S15 = _S13 + _S14; - int _S16 = somethingElse_0(t_0); + int _S18 = _S16 + _S17.x_0 + doThing_0(t_0); + int _S19 = somethingElse_0(t_0); livenessEnd_2(t_0, 0); - int _S17 = _S15 + _S16; - int _S18 = s_3.c_0[2]; + int _S20 = _S18 + _S19; + int _S21 = s_3.c_0[2]; livenessEnd_2(s_3, 0); - int _S19 = _S17 + _S18; - int _S20 = res_0; + int _S22 = _S20 + _S21; + int _S23 = res_0; livenessEnd_1(res_0, 0); - int res_1 = _S20 + _S19; + int res_1 = _S23 + _S22; i_2 = i_2 + 1; livenessStart_1(res_0, 0); res_0 = res_1; } livenessEnd_1(i_2, 0); - int _S21 = res_0; + int _S24 = res_0; livenessEnd_1(res_0, 0); - ((outputBuffer_0)._data[(uint(index_0))]) = _S21; + ((outputBuffer_0)._data[(uint(index_0))]) = _S24; return; } |
