[Mlir-commits] [mlir] [mlir][ArithToSPIRV] Fix crash converting arith.addi/subi/muli on i1 types (PR #189239)
Mehdi Amini
llvmlistbot at llvm.org
Mon Mar 30 04:03:49 PDT 2026
================
@@ -572,6 +577,75 @@ struct XOrIOpBooleanPattern final : public OpConversionPattern<arith::XOrIOp> {
}
};
+/// Converts arith.addi to spirv.LogicalNotEqual if the type is i1 or vector of
+/// i1. For booleans, addition mod 2 is equivalent to XOR / not-equal.
+struct AddIOpBooleanPattern final : public OpConversionPattern<arith::AddIOp> {
+ using Base::Base;
+
+ LogicalResult
+ matchAndRewrite(arith::AddIOp op, OpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter) const override {
+ assert(adaptor.getOperands().size() == 2);
+
+ if (!isBoolScalarOrVector(adaptor.getOperands().front().getType()))
+ return failure();
+
+ Type dstType = getTypeConverter()->convertType(op.getType());
+ if (!dstType)
+ return getTypeConversionFailure(rewriter, op);
+
+ rewriter.replaceOpWithNewOp<spirv::LogicalNotEqualOp>(
+ op, dstType, adaptor.getOperands());
+ return success();
+ }
+};
+
+/// Converts arith.subi to spirv.LogicalNotEqual if the type is i1 or vector of
+/// i1. For booleans, subtraction mod 2 is equivalent to XOR / not-equal.
+struct SubIOpBooleanPattern final : public OpConversionPattern<arith::SubIOp> {
----------------
joker-eph wrote:
Yes!
https://github.com/llvm/llvm-project/pull/189239
More information about the Mlir-commits
mailing list