Skip to content

Commit 12ecc43

Browse files
authored
SCCP instead of CFG since SCCP removes code of unused branches, not CFG (shader-slang#4640)
1 parent 6bcf92d commit 12ecc43

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

source/slang/slang-emit.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ Result linkAndOptimizeIR(
911911
legalizeVectorTypes(irModule, sink);
912912

913913
// Legalize `__isTextureAccess` and related.
914-
legalizeIsTextureAccess(irModule);
914+
legalizeIsTextureAccess(irModule, sink);
915915

916916
// Once specialization and type legalization have been performed,
917917
// we should perform some of our basic optimization steps again,

source/slang/slang-ir-legalize-is-texture-access.cpp

+11-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "slang-parameter-binding.h"
99
#include "slang-ir-legalize-image-subscript.h"
1010
#include "slang-ir-legalize-varying-params.h"
11-
#include "slang-ir-simplify-cfg.h"
11+
#include "slang-ir-sccp.h"
1212

1313
namespace Slang
1414
{
@@ -17,9 +17,9 @@ namespace Slang
1717
return as<IRImageSubscript>(getRootAddr(inst->getOperand(0)));
1818
}
1919

20-
void legalizeIsTextureAccess(IRModule* module)
20+
void legalizeIsTextureAccess(IRModule* module, DiagnosticSink* sink)
2121
{
22-
HashSet<IRFunc*> functionsToSimplifyCFG;
22+
HashSet<IRFunc*> functionsToSCCP;
2323
IRBuilder builder(module);
2424
for (auto globalInst : module->getModuleInst()->getChildren())
2525
{
@@ -41,7 +41,7 @@ namespace Slang
4141
else
4242
{
4343
inst->replaceUsesWith(builder.getBoolValue(false));
44-
functionsToSimplifyCFG.add(func);
44+
functionsToSCCP.add(func);
4545
}
4646
inst->removeAndDeallocate();
4747
continue;
@@ -53,7 +53,7 @@ namespace Slang
5353
else
5454
{
5555
inst->replaceUsesWith(builder.getBoolValue(false));
56-
functionsToSimplifyCFG.add(func);
56+
functionsToSCCP.add(func);
5757
}
5858
inst->removeAndDeallocate();
5959
continue;
@@ -66,7 +66,7 @@ namespace Slang
6666
else
6767
{
6868
inst->replaceUsesWith(builder.getBoolValue(false));
69-
functionsToSimplifyCFG.add(func);
69+
functionsToSCCP.add(func);
7070
}
7171
inst->removeAndDeallocate();
7272
continue;
@@ -75,10 +75,11 @@ namespace Slang
7575
}
7676
}
7777
}
78-
// Requires a simplifyCFG to ensure Slang does not evaluate 'IRTextureType' code path for
79-
// 'inst' for when 'inst' is not a 'IRTextureType'/TextureAccessor
80-
for(auto func : functionsToSimplifyCFG)
81-
simplifyCFG(func, CFGSimplificationOptions::getFast());
78+
// Requires a SCCP to ensure Slang does not evaluate 'IRTextureType' code path
79+
// and unresolved 'isTextureAccess' operations for when 'inst' is not a
80+
// 'IRTextureType'/`TextureAccessor`
81+
for (auto func : functionsToSCCP)
82+
applySparseConditionalConstantPropagation(func, sink);
8283
}
8384
}
8485

source/slang/slang-ir-legalize-is-texture-access.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ namespace Slang
77
{
88
class DiagnosticSink;
99

10-
void legalizeIsTextureAccess(IRModule* module);
10+
void legalizeIsTextureAccess(IRModule* module, DiagnosticSink* sink);
1111
}

tests/hlsl-intrinsic/atomic/atomic-intrinsics.slang

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -shaderobj -output-using-type
22
//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=DX12):-slang -compute -dx12 -profile cs_6_0 -use-dxil -shaderobj -output-using-type -xslang -DDX12
33
//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=VK):-vk -emit-spirv-directly -compute -shaderobj -output-using-type -render-feature hardware-device -xslang -DVK
4+
//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=VK):-vk -emit-spirv-via-glsl -compute -shaderobj -output-using-type -render-feature hardware-device -xslang -DVK -xslang -minimum-slang-optimization
45
//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=VK):-vk -emit-spirv-via-glsl -compute -shaderobj -output-using-type -render-feature hardware-device -xslang -DVK
56
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type
67

0 commit comments

Comments
 (0)