Skip to content

Conversation

@IgWod-IMG
Copy link
Contributor

This fixes the bug where deserializer would fail, with as assert, during the control flow structurization when a block to be removed still had uses. This indicates that the block that was sunk still is being referenced outside the region as the control flow is not structured.

closes #163099

…ucturization

This fixes the bug where deserializer would fail, with as assert,
during the control flow structurization when a block to be removed
still had uses. This indicates that the block that was sunk still
is being referenced outside the region as the control flow is not
structured.

closes llvm#163099
@llvmbot
Copy link
Member

llvmbot commented Oct 17, 2025

@llvm/pr-subscribers-mlir-spirv

@llvm/pr-subscribers-mlir

Author: Igor Wodiany (IgWod-IMG)

Changes

This fixes the bug where deserializer would fail, with as assert, during the control flow structurization when a block to be removed still had uses. This indicates that the block that was sunk still is being referenced outside the region as the control flow is not structured.

closes #163099


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

1 Files Affected:

  • (modified) mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp (+5)
diff --git a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
index 0c3e87a8dc1ef..d9ad8fb144b61 100644
--- a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
+++ b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
@@ -2619,6 +2619,11 @@ LogicalResult ControlFlowStructurizer::structurize() {
   // region. We cannot handle such cases given that once a value is sinked into
   // the SelectionOp/LoopOp's region, there is no escape for it.
   for (auto *block : constructBlocks) {
+    if (!block->use_empty())
+      return emitError(block->getParent()->getLoc(),
+                       "failed control flow structurization: "
+                       "block has uses outside of the "
+                       "enclosing selection/loop construct");
     for (Operation &op : *block)
       if (!op.use_empty())
         return op.emitOpError("failed control flow structurization: value has "

@IgWod-IMG
Copy link
Contributor Author

I tired to add a test similar to selection.spv but unfortunetely you cannot have expected-error {{...}} in this setting.

Also, any idea why libcxx tests failed? It looks like CI just gave up, but this change should have no impact on it. I guess I can just ignore it?

@IgWod-IMG IgWod-IMG merged commit 5d0a4a1 into llvm:main Oct 17, 2025
12 of 14 checks passed
@IgWod-IMG IgWod-IMG deleted the img_block-uses-error branch October 17, 2025 12:35
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.

mlir deserialize spirv: "Cannot destroy a value that still has uses!"

3 participants