File tree 2 files changed +19
-1
lines changed
lib/CIR/Dialect/Transforms
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> {
62
62
LogicalResult match (ScopeOp op) const final {
63
63
// TODO: Remove this logic once CIR uses MLIR infrastructure to remove
64
64
// 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 ();
66
75
}
67
76
68
77
void rewrite (ScopeOp op, PatternRewriter &rewriter) const final {
Original file line number Diff line number Diff line change @@ -138,4 +138,13 @@ module {
138
138
cir.return %0 : !cir.ptr<!s32i, addrspace(target<2>)>
139
139
}
140
140
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
141
150
}
You can’t perform that action at this time.
0 commit comments