Skip to content

Commit 09adb53

Browse files
[MLIR][EmitC] Fix bug in EmitC form-expressions pass (#91084)
An `emitc.expression` can only yield a single result, but some operations which have the `CExpression` trait can have multiple results, which can result in a crash when applying the `fold-expressions` pass. This change adds a check for the single-result condition and a simple test.
1 parent 10ec0d2 commit 09adb53

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

mlir/lib/Dialect/EmitC/Transforms/FormExpressions.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ struct FormExpressionsPass
3737
OpBuilder builder(context);
3838
auto matchFun = [&](Operation *op) {
3939
if (op->hasTrait<OpTrait::emitc::CExpression>() &&
40-
!op->getParentOfType<emitc::ExpressionOp>())
40+
!op->getParentOfType<emitc::ExpressionOp>() &&
41+
op->getNumResults() == 1)
4142
createExpression(op, builder);
4243
};
4344
rootOp->walk(matchFun);

mlir/test/Dialect/EmitC/transforms.mlir

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,12 @@ func.func @no_nested_expression(%arg0: i32, %arg1: i32) -> i1 {
124124
}
125125
return %a : i1
126126
}
127+
128+
129+
// CHECK-LABEL: func.func @single_result_requirement
130+
// CHECK-NOT: emitc.expression
131+
132+
func.func @single_result_requirement() -> (i32, i32) {
133+
%0:2 = emitc.call_opaque "foo" () : () -> (i32, i32)
134+
return %0#0, %0#1 : i32, i32
135+
}

0 commit comments

Comments
 (0)