[Mlir-commits] [mlir] [mlir][spirv] Add pattern matching for arith.index_cast index to i1 for ArithToSPIRV (PR #156031)
Jakub Kuderski
llvmlistbot at llvm.org
Sat Aug 30 10:36:39 PDT 2025
================
@@ -607,6 +607,32 @@ struct UIToFPI1Pattern final : public OpConversionPattern<arith::UIToFPOp> {
}
};
+//===----------------------------------------------------------------------===//
+// IndexCastOp
+//===----------------------------------------------------------------------===//
+
+// Converts arith.index_cast to spirv.INotEqual if the target type is i1.
+struct IndexCastIndexI1Pattern final
+ : public OpConversionPattern<arith::IndexCastOp> {
+ using OpConversionPattern::OpConversionPattern;
+
+ LogicalResult
+ matchAndRewrite(arith::IndexCastOp op, OpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter) const override {
+ Type srcType = adaptor.getOperands().front().getType();
+ // Indexes have already been converted to its respective spirv type:
+ Type indexType = getTypeConverter<SPIRVTypeConverter>()->getIndexType();
+ if (srcType != indexType || !op.getType().isInteger(1))
+ return failure();
+
+ Location loc = op.getLoc();
+ Value zeroIdx = spirv::ConstantOp::getZero(srcType, loc, rewriter);
+ rewriter.replaceOpWithNewOp<spirv::INotEqualOp>(
+ op, rewriter.getI1Type(), zeroIdx, adaptor.getOperands().front());
----------------
kuhar wrote:
Use `srcType`
https://github.com/llvm/llvm-project/pull/156031
More information about the Mlir-commits
mailing list