From 61a6c211b1587a7b9ed6a24ae1ba6fe0600c80d8 Mon Sep 17 00:00:00 2001 From: jarcherNV Date: Fri, 11 Apr 2025 14:51:48 -0700 Subject: Add flag to hoist instructions (#6740) This fixes issue #6654 Only hoist instructions that are optimized by prepareFuncForForwardDiff. Add flag hoistLoopInvariantInsts to IRSimplificationOptions and set this to true only if called from prepareFuncForForwardDiff, then only hoist if the flag is set. Additionally, do not hoist loops if they only have a single trivial iteration. --- tests/spirv/forceinline-nohoist.slang | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/spirv/forceinline-nohoist.slang (limited to 'tests/spirv') diff --git a/tests/spirv/forceinline-nohoist.slang b/tests/spirv/forceinline-nohoist.slang new file mode 100644 index 000000000..54db2838f --- /dev/null +++ b/tests/spirv/forceinline-nohoist.slang @@ -0,0 +1,32 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv -stage compute -entry main + +// Verify that the call to dot is after the conditional branch. + +// CHECK: OpBranchConditional +// CHECK: OpDot + +[ForceInline] +float test(bool x, float3 a, float3 b) { + float result = 0; + if(x) { + result = dot(a, b); + } + return result; +} + +float caller(uniform bool x, uniform float3 a, uniform float3 b) { + return test(x, a, b); +} + +RWStructuredBuffer output; + +uniform bool branchCheck; +uniform float3 uniformA; +uniform float3 uniformB; + +[numthreads(1,1,1)] +[shader("compute")] +void main() +{ + output[0] = caller(branchCheck, uniformA, uniformB); +} -- cgit v1.2.3