[Mlir-commits] [mlir] c0f4408 - [mlir] Create a std op instead of chain of ops.
Hanhan Wang
llvmlistbot at llvm.org
Tue Mar 10 15:03:32 PDT 2020
Author: Hanhan Wang
Date: 2020-03-10T15:01:44-07:00
New Revision: c0f4408d76f06cc106a257e8a160ec66c5b15025
URL: https://github.com/llvm/llvm-project/commit/c0f4408d76f06cc106a257e8a160ec66c5b15025
DIFF: https://github.com/llvm/llvm-project/commit/c0f4408d76f06cc106a257e8a160ec66c5b15025.diff
LOG: [mlir] Create a std op instead of chain of ops.
Summary:
1-bit integer is tricky in different dialects sometimes. E.g., there is no
arithmetic instructions on 1-bit integer in SPIR-V, i.e., `spv.IMul %0, %1 : i1`
is not valid. Instead, `spv.LogicalAnd %0, %1 : i1` is valid. Creating the op
directly makes lowering easier because we don't need to match a complicated
pattern like `!(!lhs && !rhs)`. Also, this matches the semantic better.
Also add assertions on inputs.
Differential Revision: https://reviews.llvm.org/D75764
Added:
Modified:
mlir/lib/Dialect/AffineOps/EDSC/Builders.cpp
mlir/test/EDSC/builder-api-test.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/AffineOps/EDSC/Builders.cpp b/mlir/lib/Dialect/AffineOps/EDSC/Builders.cpp
index 301d3fded858..e69f3d6c8c7a 100644
--- a/mlir/lib/Dialect/AffineOps/EDSC/Builders.cpp
+++ b/mlir/lib/Dialect/AffineOps/EDSC/Builders.cpp
@@ -209,11 +209,13 @@ ValueHandle mlir::edsc::op::operator!(ValueHandle value) {
ValueHandle mlir::edsc::op::operator&&(ValueHandle lhs, ValueHandle rhs) {
assert(lhs.getType().isInteger(1) && "expected boolean expression on LHS");
assert(rhs.getType().isInteger(1) && "expected boolean expression on RHS");
- return lhs * rhs;
+ return ValueHandle::create<AndOp>(lhs, rhs);
}
ValueHandle mlir::edsc::op::operator||(ValueHandle lhs, ValueHandle rhs) {
- return !(!lhs && !rhs);
+ assert(lhs.getType().isInteger(1) && "expected boolean expression on LHS");
+ assert(rhs.getType().isInteger(1) && "expected boolean expression on RHS");
+ return ValueHandle::create<OrOp>(lhs, rhs);
}
static ValueHandle createIComparisonExpr(CmpIPredicate predicate,
diff --git a/mlir/test/EDSC/builder-api-test.cpp b/mlir/test/EDSC/builder-api-test.cpp
index ed42278c6410..69f615e6434c 100644
--- a/mlir/test/EDSC/builder-api-test.cpp
+++ b/mlir/test/EDSC/builder-api-test.cpp
@@ -480,6 +480,44 @@ TEST_FUNC(zero_and_std_sign_extendi_op_i1_to_i8) {
f.erase();
}
+TEST_FUNC(operator_or) {
+ auto i1Type = IntegerType::get(/*width=*/1, &globalContext());
+ auto f = makeFunction("operator_or", {}, {i1Type, i1Type});
+
+ OpBuilder builder(f.getBody());
+ ScopedContext scope(builder, f.getLoc());
+
+ using op::operator||;
+ ValueHandle lhs(f.getArgument(0));
+ ValueHandle rhs(f.getArgument(1));
+ lhs || rhs;
+
+ // CHECK-LABEL: @operator_or
+ // CHECK: [[ARG0:%.*]]: i1, [[ARG1:%.*]]: i1
+ // CHECK: or [[ARG0]], [[ARG1]]
+ f.print(llvm::outs());
+ f.erase();
+}
+
+TEST_FUNC(operator_and) {
+ auto i1Type = IntegerType::get(/*width=*/1, &globalContext());
+ auto f = makeFunction("operator_and", {}, {i1Type, i1Type});
+
+ OpBuilder builder(f.getBody());
+ ScopedContext scope(builder, f.getLoc());
+
+ using op::operator&&;
+ ValueHandle lhs(f.getArgument(0));
+ ValueHandle rhs(f.getArgument(1));
+ lhs &&rhs;
+
+ // CHECK-LABEL: @operator_and
+ // CHECK: [[ARG0:%.*]]: i1, [[ARG1:%.*]]: i1
+ // CHECK: and [[ARG0]], [[ARG1]]
+ f.print(llvm::outs());
+ f.erase();
+}
+
TEST_FUNC(select_op_i32) {
using namespace edsc::op;
auto indexType = IndexType::get(&globalContext());
More information about the Mlir-commits
mailing list