From 34f4a9ef2a1de4aad978d0185f77b484077849bf Mon Sep 17 00:00:00 2001 From: Johannes Reifferscheid Date: Mon, 5 Sep 2022 11:25:58 +0200 Subject: [PATCH] Add ArithBuilder::sub, make add, mul work with IndexTypes. sgt and slt already worked with IndexTypes, the others did not. Reviewed By: pifon2a Differential Revision: https://reviews.llvm.org/D133285 --- mlir/include/mlir/Dialect/Arithmetic/Utils/Utils.h | 1 + mlir/lib/Dialect/Arithmetic/Utils/Utils.cpp | 29 +++++++++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/mlir/include/mlir/Dialect/Arithmetic/Utils/Utils.h b/mlir/include/mlir/Dialect/Arithmetic/Utils/Utils.h index 924de08..fd11bd3 100644 --- a/mlir/include/mlir/Dialect/Arithmetic/Utils/Utils.h +++ b/mlir/include/mlir/Dialect/Arithmetic/Utils/Utils.h @@ -99,6 +99,7 @@ struct ArithBuilder { Value _and(Value lhs, Value rhs); Value add(Value lhs, Value rhs); + Value sub(Value lhs, Value rhs); Value mul(Value lhs, Value rhs); Value select(Value cmp, Value lhs, Value rhs); Value sgt(Value lhs, Value rhs); diff --git a/mlir/lib/Dialect/Arithmetic/Utils/Utils.cpp b/mlir/lib/Dialect/Arithmetic/Utils/Utils.cpp index b568891..ca61669 100644 --- a/mlir/lib/Dialect/Arithmetic/Utils/Utils.cpp +++ b/mlir/lib/Dialect/Arithmetic/Utils/Utils.cpp @@ -93,24 +93,29 @@ Value ArithBuilder::_and(Value lhs, Value rhs) { return b.create(loc, lhs, rhs); } Value ArithBuilder::add(Value lhs, Value rhs) { - if (lhs.getType().isa()) - return b.create(loc, lhs, rhs); - return b.create(loc, lhs, rhs); + if (lhs.getType().isa()) + return b.create(loc, lhs, rhs); + return b.create(loc, lhs, rhs); +} +Value ArithBuilder::sub(Value lhs, Value rhs) { + if (lhs.getType().isa()) + return b.create(loc, lhs, rhs); + return b.create(loc, lhs, rhs); } Value ArithBuilder::mul(Value lhs, Value rhs) { - if (lhs.getType().isa()) - return b.create(loc, lhs, rhs); - return b.create(loc, lhs, rhs); + if (lhs.getType().isa()) + return b.create(loc, lhs, rhs); + return b.create(loc, lhs, rhs); } Value ArithBuilder::sgt(Value lhs, Value rhs) { - if (lhs.getType().isa()) - return b.create(loc, arith::CmpIPredicate::sgt, lhs, rhs); - return b.create(loc, arith::CmpFPredicate::OGT, lhs, rhs); + if (lhs.getType().isa()) + return b.create(loc, arith::CmpFPredicate::OGT, lhs, rhs); + return b.create(loc, arith::CmpIPredicate::sgt, lhs, rhs); } Value ArithBuilder::slt(Value lhs, Value rhs) { - if (lhs.getType().isa()) - return b.create(loc, arith::CmpIPredicate::slt, lhs, rhs); - return b.create(loc, arith::CmpFPredicate::OLT, lhs, rhs); + if (lhs.getType().isa()) + return b.create(loc, arith::CmpFPredicate::OLT, lhs, rhs); + return b.create(loc, arith::CmpIPredicate::slt, lhs, rhs); } Value ArithBuilder::select(Value cmp, Value lhs, Value rhs) { return b.create(loc, cmp, lhs, rhs); -- 2.7.4