[Mlir-commits] [mlir] [mlir][emitc] Arith to EmitC: Handle addi, subi and muli (PR #86120)

Simon Camphausen llvmlistbot at llvm.org
Fri Mar 22 01:30:56 PDT 2024


================
@@ -55,6 +55,50 @@ class ArithOpConversion final : public OpConversionPattern<ArithOp> {
   }
 };
 
+template <typename ArithOp, typename EmitCOp>
+class IntegerOpConversion final : public OpConversionPattern<ArithOp> {
+public:
+  using OpConversionPattern<ArithOp>::OpConversionPattern;
+
+  LogicalResult
+  matchAndRewrite(ArithOp op, typename ArithOp::Adaptor adaptor,
+                  ConversionPatternRewriter &rewriter) const override {
+
+    Type type = this->getTypeConverter()->convertType(op.getType());
+    if (!isa_and_nonnull<IntegerType, IndexType>(type)) {
+      return rewriter.notifyMatchFailure(op, "expected integer type");
+    }
+
----------------
simon-camp wrote:

Return a match failure for `i1`, as these are emitted as `bool` and the arithmetic doesn't wrap around as expected. We can add additional patterns in a follow up.

https://github.com/llvm/llvm-project/pull/86120


More information about the Mlir-commits mailing list