[Mlir-commits] [mlir] [mlir][EmitC] Add an `emitc.conditional` operator (PR #84883)

Tina Jung llvmlistbot at llvm.org
Tue Mar 12 01:41:44 PDT 2024


================
@@ -54,6 +54,26 @@ class ArithOpConversion final : public OpConversionPattern<ArithOp> {
     return success();
   }
 };
+
+class SelectOpConversion : public OpConversionPattern<arith::SelectOp> {
+public:
+  using OpConversionPattern<arith::SelectOp>::OpConversionPattern;
+
+  LogicalResult
+  matchAndRewrite(arith::SelectOp selectOp, OpAdaptor adaptor,
+                  ConversionPatternRewriter &rewriter) const override {
+
+    if (!selectOp.getCondition().getType().isInteger())
+      return rewriter.notifyMatchFailure(
+          selectOp, "can only converted if condition is a scalar of type i1");
----------------
TinaAMD wrote:

Since the ConditionalOp only allows for `i1` as condition and the message states this already, it would be good to check it explicitly here. In case `arith::SelectOp` changes to allow more integer types, the conversion would fail rather then generating an invalid emitc op.

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


More information about the Mlir-commits mailing list