[Mlir-commits] [mlir] [MLIR][EmitC] Fix bug in EmitC form-expressions pass (PR #91084)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat May 4 14:15:06 PDT 2024
https://github.com/christopherbate created https://github.com/llvm/llvm-project/pull/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.
>From e047cb8aebd14c12951fc045e8e6246b86c75e78 Mon Sep 17 00:00:00 2001
From: Christopher Bate <cbate at nvidia.com>
Date: Sat, 4 May 2024 14:20:38 -0600
Subject: [PATCH] [MLIR][EmitC] Fix bug in EmitC form-expressions pass
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.
---
mlir/lib/Dialect/EmitC/Transforms/FormExpressions.cpp | 3 ++-
mlir/test/Dialect/EmitC/transforms.mlir | 9 +++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/mlir/lib/Dialect/EmitC/Transforms/FormExpressions.cpp b/mlir/lib/Dialect/EmitC/Transforms/FormExpressions.cpp
index e7c431f39e3f08..82bd031430d36c 100644
--- a/mlir/lib/Dialect/EmitC/Transforms/FormExpressions.cpp
+++ b/mlir/lib/Dialect/EmitC/Transforms/FormExpressions.cpp
@@ -37,7 +37,8 @@ struct FormExpressionsPass
OpBuilder builder(context);
auto matchFun = [&](Operation *op) {
if (op->hasTrait<OpTrait::emitc::CExpression>() &&
- !op->getParentOfType<emitc::ExpressionOp>())
+ !op->getParentOfType<emitc::ExpressionOp>() &&
+ op->getNumResults() == 1)
createExpression(op, builder);
};
rootOp->walk(matchFun);
diff --git a/mlir/test/Dialect/EmitC/transforms.mlir b/mlir/test/Dialect/EmitC/transforms.mlir
index 8ac606a2c8c0a1..a5c582be4aa7f6 100644
--- a/mlir/test/Dialect/EmitC/transforms.mlir
+++ b/mlir/test/Dialect/EmitC/transforms.mlir
@@ -124,3 +124,12 @@ func.func @no_nested_expression(%arg0: i32, %arg1: i32) -> i1 {
}
return %a : i1
}
+
+
+// CHECK-LABEL: func.func @single_result_requirement
+// CHECK-NOT: emitc.expression
+
+func.func @single_result_requirement() -> (i32, i32) {
+ %0:2 = emitc.call_opaque "foo" () : () -> (i32, i32)
+ return %0#0, %0#1 : i32, i32
+}
More information about the Mlir-commits
mailing list