Skip to content

[mlir] Use llvm::hasSingleElement (NFC) #133648

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

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Mar 30, 2025

@llvm/pr-subscribers-mlir-spirv

@llvm/pr-subscribers-mlir

Author: Kazu Hirata (kazutakahirata)

Changes

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

1 Files Affected:

  • (modified) mlir/lib/Dialect/SPIRV/IR/ControlFlowOps.cpp (+1-2)
diff --git a/mlir/lib/Dialect/SPIRV/IR/ControlFlowOps.cpp b/mlir/lib/Dialect/SPIRV/IR/ControlFlowOps.cpp
index bcfd7ebccd12d..2959d67b366b9 100644
--- a/mlir/lib/Dialect/SPIRV/IR/ControlFlowOps.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/ControlFlowOps.cpp
@@ -255,8 +255,7 @@ static bool hasOneBranchOpTo(Block &srcBlock, Block &dstBlock) {
 
 /// Returns true if the given `block` only contains one `spirv.mlir.merge` op.
 static bool isMergeBlock(Block &block) {
-  return !block.empty() && std::next(block.begin()) == block.end() &&
-         isa<spirv::MergeOp>(block.front());
+  return llvm::hasSingleElement(block) && isa<spirv::MergeOp>(block.front());
 }
 
 /// Returns true if a `spirv.mlir.merge` op outside the merge block.

Copy link
Member

@kuhar kuhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@kazutakahirata kazutakahirata merged commit 1c8647a into llvm:main Mar 30, 2025
14 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_hasSingleElement_mlir branch March 30, 2025 19:21
SchrodingerZhu pushed a commit to SchrodingerZhu/llvm-project that referenced this pull request Mar 31, 2025
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