Signal when SPIR-V legalization needs loop unroll#15
Draft
AnastaZIuk wants to merge 2 commits intomainfrom
Draft
Signal when SPIR-V legalization needs loop unroll#15AnastaZIuk wants to merge 2 commits intomainfrom
AnastaZIuk wants to merge 2 commits intomainfrom
Conversation
You can test this locally with the following command:git-clang-format --diff 54afd2c6a5f1a5bcbef66967515fa69f5a3650fd 9ac57982725c4264348b20ad3fb271acc0993754 -- tools/clang/lib/Frontend/Rewrite/RewriteObjC.cpp tools/clang/lib/SPIRV/SpirvEmitter.cpp tools/clang/lib/SPIRV/SpirvEmitter.hView the diff from clang-format here.diff --git a/tools/clang/lib/SPIRV/SpirvEmitter.cpp b/tools/clang/lib/SPIRV/SpirvEmitter.cpp
index 4a616a00..0920fc1c 100644
--- a/tools/clang/lib/SPIRV/SpirvEmitter.cpp
+++ b/tools/clang/lib/SPIRV/SpirvEmitter.cpp
@@ -593,8 +593,7 @@ SpirvEmitter::SpirvEmitter(CompilerInstance &ci)
constEvaluator(astContext, spvBuilder), entryFunction(nullptr),
curFunction(nullptr), curThis(nullptr), seenPushConstantAt(),
isSpecConstantMode(false), needsLegalization(false),
- needsLegalizationLoopUnroll(false),
- needsLegalizationSsaRewrite(false),
+ needsLegalizationLoopUnroll(false), needsLegalizationSsaRewrite(false),
beforeHlslLegalization(false), mainSourceFile(nullptr) {
// Get ShaderModel from command line hlsl profile option.
@@ -957,8 +956,7 @@ void SpirvEmitter::HandleTranslationUnit(ASTContext &context) {
!dsetbindingsToCombineImageSampler.empty() ||
spirvOptions.signaturePacking;
needsLegalizationSsaRewrite =
- needsLegalizationSsaRewrite ||
- !dsetbindingsToCombineImageSampler.empty();
+ needsLegalizationSsaRewrite || !dsetbindingsToCombineImageSampler.empty();
// Run legalization passes
if (spirvOptions.codeGenHighLevel) {
@@ -16679,9 +16677,9 @@ bool SpirvEmitter::spirvToolsLegalize(std::vector<uint32_t> *mod,
} else if (needsLegalizationSsaRewrite) {
legalizationSsaRewriteMode = spvtools::SSARewriteMode::OpaqueOnly;
}
- optimizer.RegisterLegalizationPasses(
- spirvOptions.preserveInterface, needsLegalizationLoopUnroll,
- legalizationSsaRewriteMode);
+ optimizer.RegisterLegalizationPasses(spirvOptions.preserveInterface,
+ needsLegalizationLoopUnroll,
+ legalizationSsaRewriteMode);
// Add flattening of resources if needed.
if (spirvOptions.flattenResourceArrays) {
optimizer.RegisterPass(
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SpirvEmitterbits for legalization-time loop unroll and legalization-time SSA rewriteCodeGenSPIRVchecks so they validate the semantically relevant SPIR-V shape instead of the older inflated IR shape58kLoCRoot cause
The expensive blanket policy lives in the SPIR-V optimizer recipe, not in HLSL parsing or the DXC CLI front-end.
DXC is still the producer that knows when a specific lowering path genuinely needs those expensive legalization transforms for correctness, so the optimizer should not have to guess that globally.
Two confirmed correctness-sensitive cases are:
ConstOffsetThis patch provides that producer-side signal. The companion optimizer change in KhronosGroup/SPIRV-Tools#6612 then uses it to avoid the broader blanket defaults.
Validation
58kLoCAMD Ryzen 5 5600G with Radeon Graphics,6physical cores,12logical processors, Windows-reported max clock3901 MHz19.161 sto6.042 s4.702 s2.464 sCodeGenSPIRVlit/FileCheck passes:1403expected passes,2expected failures,0unexpectedCompanion SPIR-V optimizer PR:
KhronosGroup/SPIRV-Tools#6612