-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mlir][emitc] Fix form-expressions inside expression #86081
Conversation
@llvm/pr-subscribers-mlir-emitc @llvm/pr-subscribers-mlir Author: Kirill Chibisov (kchibisov) ChangesMake form-expressions not create -- I've discovered it when I wanted to run this pass after some other transformation I perform, so I don't have to re-implement it inside my own pass, however given that I have Not sure whether it's the right way to fix it. Full diff: https://github.com/llvm/llvm-project/pull/86081.diff 2 Files Affected:
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..30551f09fd4da8 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_expression_in_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_expression_in_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
+}
|
CI failure looks unrelated. |
856846b
to
b5750c2
Compare
Seems like CI fixed itself. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this! Just a minor suggestion regarding the name of the test.
b5750c2
to
a731729
Compare
Make form-expressions not create `emitc.expression`s for operations inside the `emitc.expression`s, since they are invalid.
a731729
to
c021354
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good to me.
Before commiting on your behalf, are you okay with using everything above |
I try to have commit messages correct/make sense, though you can also extend/reword if you feel like it. |
Ah, I am not familiar with that tool :) But makes sense. I normally only add what I want in my squash commit message to the PR description. For everything else, I add an additional comment. But that's due to the GitHub workflow...
No need to, your explanation makes sense and also providing an additional note is perfectly fine. |
I got it a bit wrong, it's |
Thanks for fixing this @kchibisov ! |
Make form-expressions not create `emitc.expression`s for operations inside the `emitc.expression`s, since they are invalid.
Make form-expressions not create `emitc.expression`s for operations inside the `emitc.expression`s, since they are invalid.
Make form-expressions not create
emitc.expression
s for operations inside theemitc.expression
s, since they are invalid.--
I've discovered it when I wanted to run this pass after some other transformation I perform, so I don't have to re-implement it inside my own pass, however given that I have
emitc.expression
inside the input, it was producing invalid IR.Not sure whether it's the right way to fix it.