From 4c9e4de4b68f2612a39e8783e9da89605ecf54e0 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 26 Jun 2023 15:18:06 -0700 Subject: Fix DCE on mutable calls in a loop. (#2943) * Fix DCE on mutable calls in a loop. * More accurate in-loop test. * code review fixes. * Fix. --------- Co-authored-by: Yong He --- .../bugs/mutating/mutating-call-in-loop-dce.slang | 39 ++++++++++++++++++++++ .../mutating-call-in-loop-dce.slang.expected.txt | 2 ++ 2 files changed, 41 insertions(+) create mode 100644 tests/bugs/mutating/mutating-call-in-loop-dce.slang create mode 100644 tests/bugs/mutating/mutating-call-in-loop-dce.slang.expected.txt (limited to 'tests/bugs/mutating') diff --git a/tests/bugs/mutating/mutating-call-in-loop-dce.slang b/tests/bugs/mutating/mutating-call-in-loop-dce.slang new file mode 100644 index 000000000..372cb61b0 --- /dev/null +++ b/tests/bugs/mutating/mutating-call-in-loop-dce.slang @@ -0,0 +1,39 @@ +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type + +// Confirm that a SideEffectFree mutable method does not get DCE'd when +// it is called from within a loop. + +struct C +{ + int a; + [mutating] + int add() + { + a++; + return a; + } + [mutating] + void init() + { + a = 0; + } +} +int doSomething(C d) +{ + int rs = 0; + for (int i = 0; i < 10; i++) + rs = d.add(); + return rs; +} + +//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; + C c; + c.init(); + outputBuffer[tid] = doSomething(c); +} \ No newline at end of file diff --git a/tests/bugs/mutating/mutating-call-in-loop-dce.slang.expected.txt b/tests/bugs/mutating/mutating-call-in-loop-dce.slang.expected.txt new file mode 100644 index 000000000..2c29f3f9e --- /dev/null +++ b/tests/bugs/mutating/mutating-call-in-loop-dce.slang.expected.txt @@ -0,0 +1,2 @@ +type: int32_t +10 -- cgit v1.2.3