[Mlir-commits] [mlir] [mlir][xegpu] add support for structure control flow ops in workgroup to subgroup distribution (PR #142618)
Charitha Saumya
llvmlistbot at llvm.org
Tue Jun 10 10:19:15 PDT 2025
================
@@ -314,14 +328,64 @@ struct WgToSgPrefetchNdOp : public OpConversionPattern<xegpu::PrefetchNdOp> {
}
};
+// Handles UnrealizedConversionCastOp generated during
+// SCFStructuralTypeConversions (step 1). This op may appear as either a
+// target or source materialization for Vector values, e.g.:
+// 1. unrealized_cast %1 : vector<256xf32> to vector<16xf32>, ...
+// 2. unrealized_cast %1 : vector<16xf32>, ... to vector<256xf32>
+// it could be either 1:N or N:1 cast. In both cases, the pattern
+// simply forwards the inputs to the outputs using 1:1 or 1:N interface.
+// TODO: remove it when context-aware type converter is ready.
+struct UnrealizedConversionCastOpPattern
+ : public OpConversionPattern<mlir::UnrealizedConversionCastOp> {
+ using OpConversionPattern<
+ mlir::UnrealizedConversionCastOp>::OpConversionPattern;
+
+ mlir::LogicalResult
+ matchAndRewrite(mlir::UnrealizedConversionCastOp op, OneToNOpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter) const override {
+ SmallVector<Value> inputs = xegpu::flattenValues(adaptor.getInputs());
+
+ auto inputTy = dyn_cast<VectorType>(inputs[0].getType());
+ auto outputTy = dyn_cast<VectorType>(op->getOpResult(0).getType());
+
+ if (!inputTy || !outputTy || !llvm::all_equal(op->getResultTypes()) ||
+ !llvm::all_equal(ValueRange(inputs).getTypes()))
+ return failure();
+
+ // Handles the case where cast %1 : vector<256xf32> to vector<16xf32>, ...
+ // the input values provided by the adaptor should already be distributed,
+ // and their types should correspond exactly to the result types of the
+ // operation.
+ if (op.getNumOperands() == 1 &&
+ llvm::equal(ValueRange(inputs).getTypes(), op->getResultTypes())) {
+ rewriter.replaceOp(op, inputs);
+ return success();
+ }
+
+ // Handles the case where cast %1 : vector<16xf32>, ... to vector<256xf32>.
+ // All input values must have the same vector type, and their shape must be
+ // evenly divisible by the output vector's shape.
+ // TODO: it is not safe to do such forward, since such N:1 cast could be
----------------
charithaintc wrote:
I think its better to give an example on how the IR looks like in each of this two cases.
https://github.com/llvm/llvm-project/pull/142618
More information about the Mlir-commits
mailing list