[Mlir-commits] [mlir] 5344a37 - [mlir][emitc] Fix form-expressions inside expression (#86081)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Mar 21 06:35:04 PDT 2024


Author: Kirill Chibisov
Date: 2024-03-21T14:35:00+01:00
New Revision: 5344a370fe85d9119729d9036540bbd91956da38

URL: https://github.com/llvm/llvm-project/commit/5344a370fe85d9119729d9036540bbd91956da38
DIFF: https://github.com/llvm/llvm-project/commit/5344a370fe85d9119729d9036540bbd91956da38.diff

LOG: [mlir][emitc] Fix form-expressions inside expression (#86081)

Make form-expressions not create `emitc.expression`s for operations
inside the `emitc.expression`s, since they are invalid.

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 5b03f81b305fd5..e7c431f39e3f08 100644
--- a/mlir/lib/Dialect/EmitC/Transforms/FormExpressions.cpp
+++ b/mlir/lib/Dialect/EmitC/Transforms/FormExpressions.cpp
@@ -36,7 +36,8 @@ struct FormExpressionsPass
     // Wrap each C operator op with an expression op.
     OpBuilder builder(context);
     auto matchFun = [&](Operation *op) {
-      if (op->hasTrait<OpTrait::emitc::CExpression>())
+      if (op->hasTrait<OpTrait::emitc::CExpression>() &&
+          !op->getParentOfType<emitc::ExpressionOp>())
         createExpression(op, builder);
     };
     rootOp->walk(matchFun);

diff  --git a/mlir/test/Dialect/EmitC/transforms.mlir b/mlir/test/Dialect/EmitC/transforms.mlir
index ad167fa455a1a5..8ac606a2c8c0a1 100644
--- a/mlir/test/Dialect/EmitC/transforms.mlir
+++ b/mlir/test/Dialect/EmitC/transforms.mlir
@@ -107,3 +107,20 @@ func.func @expression_with_address_taken(%arg0: i32, %arg1: i32, %arg2: !emitc.p
   %d = emitc.cmp lt, %c, %arg2 :(!emitc.ptr<i32>, !emitc.ptr<i32>) -> i1
   return %d : i1
 }
+
+// CHECK-LABEL: func.func @no_nested_expression(
+// CHECK-SAME:      %[[VAL_0:.*]]: i32, %[[VAL_1:.*]]: i32) -> i1 {
+// CHECK:         %[[VAL_2:.*]] = emitc.expression : i1 {
+// CHECK:           %[[VAL_3:.*]] = emitc.cmp lt, %[[VAL_0]], %[[VAL_1]] : (i32, i32) -> i1
+// CHECK:           emitc.yield %[[VAL_3]] : i1
+// CHECK:         }
+// CHECK:         return %[[VAL_2]] : i1
+// CHECK:       }
+
+func.func @no_nested_expression(%arg0: i32, %arg1: i32) -> i1 {
+  %a = emitc.expression : i1 {
+    %b = emitc.cmp lt, %arg0, %arg1 :(i32, i32) -> i1
+    emitc.yield %b : i1
+  }
+  return %a : i1
+}


        


More information about the Mlir-commits mailing list