[Mlir-commits] [mlir] 09adb53 - [MLIR][EmitC] Fix bug in EmitC form-expressions pass (#91084)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon May 6 05:12:42 PDT 2024


Author: Chris
Date: 2024-05-06T06:12:39-06:00
New Revision: 09adb53118e50ad433b7df6d84a4e2937bfb97d5

URL: https://github.com/llvm/llvm-project/commit/09adb53118e50ad433b7df6d84a4e2937bfb97d5
DIFF: https://github.com/llvm/llvm-project/commit/09adb53118e50ad433b7df6d84a4e2937bfb97d5.diff

LOG: [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.

Added: 
    

Modified: 
    mlir/lib/Dialect/EmitC/Transforms/FormExpressions.cpp
    mlir/test/Dialect/EmitC/transforms.mlir

Removed: 
    


################################################################################
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