Skip to content

[mlir][spirv] Fix incorrect argument erasure in deserializer #134610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2025

Conversation

IgWod-IMG
Copy link
Contributor

The current implementation iterates and modifies the list of arguments at the same time. Depending on the number of arguments this will trigger an assert: assert(index < arguments.size()). This change replaces loop with a range based erasure.

The current implementation iterates and modifies the list of
arguments at the same time. Depending on the number of arguments
this will trigger an assert: `assert(index < arguments.size())`.
This change replaces loop with a range based erasure.
@llvmbot
Copy link
Member

llvmbot commented Apr 7, 2025

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-spirv

Author: Igor Wodiany (IgWod-IMG)

Changes

The current implementation iterates and modifies the list of arguments at the same time. Depending on the number of arguments this will trigger an assert: assert(index &lt; arguments.size()). This change replaces loop with a range based erasure.


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

1 Files Affected:

  • (modified) mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp (+1-2)
diff --git a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
index d471d9a8e3d6c..25749ec598f00 100644
--- a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
+++ b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
@@ -2077,8 +2077,7 @@ LogicalResult ControlFlowStructurizer::structurize() {
     // block arguments from the original merge block.
     for (unsigned i = 0, e = outsideUses.size(); i != e; ++i)
       outsideUses[i].replaceAllUsesWith(selectionOp.getResult(i));
-    for (unsigned i = 0, e = mergeBlock->getNumArguments(); i != e; ++i)
-      mergeBlock->eraseArgument(i);
+    mergeBlock->eraseArguments(0, mergeBlock->getNumArguments());
   }
 
   // Check that whether some op in the to-be-erased blocks still has uses. Those

@IgWod-IMG IgWod-IMG merged commit cff6565 into llvm:main Apr 7, 2025
14 checks passed
@IgWod-IMG IgWod-IMG deleted the img_fix-arg-erase branch April 7, 2025 14:00
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.

3 participants