File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
lib/CIR/Dialect/Transforms Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -62,7 +62,16 @@ struct RemoveEmptyScope : public OpRewritePattern<ScopeOp> {
6262 LogicalResult match (ScopeOp op) const final {
6363 // TODO: Remove this logic once CIR uses MLIR infrastructure to remove
6464 // trivially dead operations
65- return success (op.isEmpty ());
65+ if (op.isEmpty ()) {
66+ return success ();
67+ }
68+
69+ Region *region = op.getRegions ().front ();
70+ if (region && region->getBlocks ().front ().getOperations ().size () == 1 ) {
71+ return success (isa<YieldOp>(region->getBlocks ().front ().front ()));
72+ }
73+
74+ return failure ();
6675 }
6776
6877 void rewrite (ScopeOp op, PatternRewriter &rewriter) const final {
Original file line number Diff line number Diff line change @@ -138,4 +138,13 @@ module {
138138 cir.return %0 : !cir.ptr<!s32i, addrspace(target<2>)>
139139 }
140140
141+ // Should remove scope with only yield
142+ cir.func @removeBlockWithScopeYeild(%arg0: !s32i) {
143+ cir.scope {
144+ cir.yield
145+ }
146+ cir.return
147+ }
148+ // CHECK: cir.func @removeBlockWithScopeYeild
149+ // CHECK-NEXT: cir.return
141150}
You can’t perform that action at this time.
0 commit comments