From bd6306cdaa4a49344658bd026721b6532e103d09 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 24 Feb 2023 10:01:47 -0800 Subject: 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 --- tests/ir/loop-dce.slang | 40 ++++++++++++++++++++++++++++++++++++ tests/ir/loop-dce.slang.expected.txt | 4 ++++ 2 files changed, 44 insertions(+) create mode 100644 tests/ir/loop-dce.slang create mode 100644 tests/ir/loop-dce.slang.expected.txt (limited to 'tests/ir') diff --git a/tests/ir/loop-dce.slang b/tests/ir/loop-dce.slang new file mode 100644 index 000000000..f89c1aa38 --- /dev/null +++ b/tests/ir/loop-dce.slang @@ -0,0 +1,40 @@ +//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 outputBuffer; + +__target_intrinsic(hlsl, "@") +__target_intrinsic(glsl, "@") +__target_intrinsic(cpp, "@") +__target_intrinsic(cuda, "@") +[__readNone] +int produceSyntaxError() { return 0; } + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) +{ + int sum = 0; + int array[100]; + // Next, this loop will be removed because there is no use of `array`. + for (int i = 0; i < 100; i++) + { + // This loop must be removed, or we will fail downstream compilation. + array[i] = i + produceSyntaxError(); + } + + // First, this loop will be removed because there is no use of `sum`. + for (int i = 0; i < 100; i++) + { + // This loop must be removed, or we will fail downstream compilation. + if (i < 50) + { + sum += array[i] + produceSyntaxError(); + } + else + { + sum += i * 2 + produceSyntaxError(); + } + } + outputBuffer[0] = 1; +} diff --git a/tests/ir/loop-dce.slang.expected.txt b/tests/ir/loop-dce.slang.expected.txt new file mode 100644 index 000000000..968ac3ef0 --- /dev/null +++ b/tests/ir/loop-dce.slang.expected.txt @@ -0,0 +1,4 @@ +1 +0 +0 +0 -- cgit v1.2.3