diff options
| author | Yong He <yonghe@outlook.com> | 2023-05-31 14:28:45 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-31 14:28:45 -0700 |
| commit | 02bb741a8d1b4ed31a65c46b7e43d153b42a7b73 (patch) | |
| tree | 1a548e812568de27b8fffcc2e251596e9d729177 /tests/language-feature/constants | |
| parent | 5dd401e416e18fdfe904a66284b0cf56cf256ec7 (diff) | |
Preserve type cast during AST constant folding. (#2912)
* Preserve type cast during AST constant folding.
Fixes #2891.
* Fix.
* Fix truncating.
* fix test.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests/language-feature/constants')
4 files changed, 41 insertions, 0 deletions
diff --git a/tests/language-feature/constants/type-cast-const.slang b/tests/language-feature/constants/type-cast-const.slang new file mode 100644 index 000000000..d0291aa7d --- /dev/null +++ b/tests/language-feature/constants/type-cast-const.slang @@ -0,0 +1,23 @@ +//TEST(compute):COMPARE_COMPUTE: +//TEST:SIMPLE(filecheck=CHECK): -target hlsl -entry computeMain -profile cs_5_0 + +int check<let b : bool>(int x) +{ + // CHECK: int v{{.*}}[int(2)] + int v[((int)b) + 1]; + for (int i = 0; i < ((int)b) + 1; i++) + v[i] = i; + return (int)v[x]; +} + +//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +[numthreads(1, 1, 1)] +void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) +{ + int tid = dispatchThreadID.x; + int inVal = tid; + int outVal = check<true>(inVal + 1); + outputBuffer[tid] = outVal; +} diff --git a/tests/language-feature/constants/type-cast-const.slang.expected.txt b/tests/language-feature/constants/type-cast-const.slang.expected.txt new file mode 100644 index 000000000..56a6051ca --- /dev/null +++ b/tests/language-feature/constants/type-cast-const.slang.expected.txt @@ -0,0 +1 @@ +1
\ No newline at end of file diff --git a/tests/language-feature/constants/type-cast-truncate.slang b/tests/language-feature/constants/type-cast-truncate.slang new file mode 100644 index 000000000..451d982f2 --- /dev/null +++ b/tests/language-feature/constants/type-cast-truncate.slang @@ -0,0 +1,15 @@ +//TEST(compute):COMPARE_COMPUTE: -output-using-type + +//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +static const int c = (int8_t)255; + +[numthreads(1, 1, 1)] +void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) +{ + int tid = dispatchThreadID.x; + int inVal = tid; + int outVal = c; + outputBuffer[tid] = outVal; +} diff --git a/tests/language-feature/constants/type-cast-truncate.slang.expected.txt b/tests/language-feature/constants/type-cast-truncate.slang.expected.txt new file mode 100644 index 000000000..a97ae25ba --- /dev/null +++ b/tests/language-feature/constants/type-cast-truncate.slang.expected.txt @@ -0,0 +1,2 @@ +type: int32_t +-1
\ No newline at end of file |
