summaryrefslogtreecommitdiffstats
path: root/tests/bugs
diff options
context:
space:
mode:
authorcheneym2 <acheney@nvidia.com>2025-01-14 11:22:04 -0500
committerGitHub <noreply@github.com>2025-01-14 08:22:04 -0800
commit4da52b65ac04251ab52d713fa28146f76a84446c (patch)
treefff3710a934dc704dc185bd78f45a998cba393d0 /tests/bugs
parent9a926058f45c7adfa569946b4f6b15a8772ac035 (diff)
Fix simplify if-else (#6077)
* Fix simplify if-else The if-else optimization observes that at if at least one true/false block is merely an unconditional jump to the after block, that the whole if-else can be replaced with a jump to the after block. But it's important to copy the phi arguments from the aforementioned unconditional jump, rather than what is present in the 'true' block, since the 'true' block might actually just be the after block itself. Below, the ifElse() would be replaced with an unconditional jump to block %39, but with the `phi` arguments copied from the branch to %29, which is an unrelated block. ifElse(%38, %39, %40, %39) block %40: unconditionalBranch(%39) block %39: unconditionalBranch(%29, 0 : Float) block %29( [nameHint("ret")] param %ret : Float): Fixes issue #5972 * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tests/bugs')
-rw-r--r--tests/bugs/simplify-if-else.slang26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/bugs/simplify-if-else.slang b/tests/bugs/simplify-if-else.slang
new file mode 100644
index 000000000..8719a1599
--- /dev/null
+++ b/tests/bugs/simplify-if-else.slang
@@ -0,0 +1,26 @@
+//TEST:SIMPLE(filecheck=CHECK): -stage compute -entry computeMain -target hlsl
+//CHECK: computeMain
+
+//TEST_INPUT:ubuffer(data=[9 9 9 9], stride=4):out,name=outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ vector<float32_t, 4> vvv = vector<float32_t, 4>(0);
+ float32_t ret = 0.0f;
+ if (vvv.y < 1.0f)
+ {
+ ret = 1.0f;
+ }
+ else
+ {
+ if (vvv.y > 1.0f && outputBuffer[3] == 3)
+ {
+ ret = 0.0f;
+ } else {
+ if (true) {}
+ }
+ }
+ outputBuffer[int(dispatchThreadID.x)] = int(ret);
+}