Skip to content

Conversation

Keenuts
Copy link
Contributor

@Keenuts Keenuts commented Sep 10, 2025

Some passes like LoopSimplify/SimplifyCFF are running between IRPasses and ISelPrepare. This is an issue because the structurizer generates OpSelectionMerge/OpLoopMerge instructions at specific places, and those passes are moving them.
Moving the structurizer later solves this issue.

@llvmbot
Copy link
Member

llvmbot commented Sep 10, 2025

@llvm/pr-subscribers-backend-spir-v

Author: Nathan Gauër (Keenuts)

Changes

Some passes like LoopSimplify/SimplifyCFF are running between IRPasses and ISelPrepare. This is an issue because the structurizer generates OpSelectionMerge/OpLoopMerge instructions at specific places, and those passes are moving them.
Moving the structurizer later solves this issue.


Full diff: https://github.com/llvm/llvm-project/pull/157886.diff

1 Files Affected:

  • (modified) llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp (+5-5)
diff --git a/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp b/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
index e0bfb77f4b530..9c58f468c9bd6 100644
--- a/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
@@ -189,6 +189,11 @@ TargetPassConfig *SPIRVTargetMachine::createPassConfig(PassManagerBase &PM) {
 void SPIRVPassConfig::addIRPasses() {
   TargetPassConfig::addIRPasses();
 
+  addPass(createSPIRVRegularizerPass());
+  addPass(createSPIRVPrepareFunctionsPass(TM));
+}
+
+void SPIRVPassConfig::addISelPrepare() {
   if (TM.getSubtargetImpl()->isShader()) {
     // Vulkan does not allow address space casts. This pass is run to remove
     // address space casts that can be removed.
@@ -220,12 +225,7 @@ void SPIRVPassConfig::addIRPasses() {
     addPass(createPromoteMemoryToRegisterPass());
   }
 
-  addPass(createSPIRVRegularizerPass());
-  addPass(createSPIRVPrepareFunctionsPass(TM));
   addPass(createSPIRVStripConvergenceIntrinsicsPass());
-}
-
-void SPIRVPassConfig::addISelPrepare() {
   addPass(createSPIRVLegalizeImplicitBindingPass());
   addPass(createSPIRVEmitIntrinsicsPass(&getTM<SPIRVTargetMachine>()));
   if (TM.getSubtargetImpl()->isLogicalSPIRV())

Some passes like LoopSimplify/SimplifyCFF are running between
IRPasses and ISelPrepare. This is an issue because the structurizer
generates OpSelectionMerge/OpLoopMerge instructions at specific places,
and those passes are moving them.
Moving the structurizer later solves this issue.
@Keenuts
Copy link
Contributor Author

Keenuts commented Sep 11, 2025

Rebased on main. There was one SPIR-V test failure I could not reproduce locally. Will see if this has been fixed, or if I need to dig into it first.

@Keenuts
Copy link
Contributor Author

Keenuts commented Sep 11, 2025

Turns out my version of spirv-val was just too old. Can reproduce the issue which is also on main, so unrelated to this PR.

@Keenuts Keenuts merged commit d67ab11 into llvm:main Sep 11, 2025
11 of 13 checks passed
@Keenuts Keenuts deleted the move-passes branch September 11, 2025 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[HLSL][SPIRV] Fix wave tests from the offload test suite
3 participants