[clang] [CIR] Add canonicalizer for CleanupScopeOp (PR #191084)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 9 06:10:55 PDT 2026


================
@@ -1449,6 +1449,41 @@ cir::CleanupScopeOp::getSuccessorInputs(RegionSuccessor successor) {
   return ValueRange();
 }
 
+LogicalResult cir::CleanupScopeOp::canonicalize(CleanupScopeOp op,
+                                                PatternRewriter &rewriter) {
+  auto isRegionTrivial = [](Region &region) {
+    if (!region.hasOneBlock())
+      return false;
+    Block &block = region.front();
+    return llvm::hasSingleElement(block) && isa<cir::YieldOp>(block.front());
----------------
erichkeane wrote:

Huh, TIL!  Interestingly there is also a `llvm::getSingleElement` too! Wonder for readability/symmetry if the `block.front` being `llvm::getSingleElement` makes sense.

https://github.com/llvm/llvm-project/pull/191084


More information about the cfe-commits mailing list