From 02bb741a8d1b4ed31a65c46b7e43d153b42a7b73 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 31 May 2023 14:28:45 -0700 Subject: 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 --- .../constants/type-cast-const.slang | 23 ++++++++++++++++++++++ .../constants/type-cast-const.slang.expected.txt | 1 + .../constants/type-cast-truncate.slang | 15 ++++++++++++++ .../type-cast-truncate.slang.expected.txt | 2 ++ .../ray-tracing/ray-query-subroutine.slang | 2 +- 5 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/language-feature/constants/type-cast-const.slang create mode 100644 tests/language-feature/constants/type-cast-const.slang.expected.txt create mode 100644 tests/language-feature/constants/type-cast-truncate.slang create mode 100644 tests/language-feature/constants/type-cast-truncate.slang.expected.txt (limited to 'tests') 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(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 outputBuffer; + +[numthreads(1, 1, 1)] +void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) +{ + int tid = dispatchThreadID.x; + int inVal = tid; + int outVal = check(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 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 diff --git a/tests/pipeline/ray-tracing/ray-query-subroutine.slang b/tests/pipeline/ray-tracing/ray-query-subroutine.slang index 3279acc12..74489b6f8 100644 --- a/tests/pipeline/ray-tracing/ray-query-subroutine.slang +++ b/tests/pipeline/ray-tracing/ray-query-subroutine.slang @@ -7,7 +7,7 @@ RWStructuredBuffer gOutput; RaytracingAccelerationStructure gScene; -float3 helper(RayQuery q) +float3 helper(RayQuery q) { RayDesc ray; ray.Origin = 0; -- cgit v1.2.3