[Mlir-commits] [mlir] [MLIR][Vector] Add warp distribution for `vector.step` op (PR #155425)
Artem Kroviakov
llvmlistbot at llvm.org
Wed Aug 27 02:26:56 PDT 2025
================
@@ -705,6 +705,45 @@ struct WarpOpConstant : public WarpDistributionPattern {
}
};
+/// Sink out step op feeding into a warp op yield.
+/// Vector step op is treated similar to arith.constant, apart from
+/// the result that represents a sequence [0, vec_size).
+/// The sequence is semantically equivalent to warp's threads/lanes indices.
+/// ```
+/// %0 = gpu.warp_execute_on_lane_0(%arg0) -> (vector<1xindex>) {
+/// ...
+/// %cst = vector.step : vector<32xindex>
+/// gpu.yield %cst : vector<1xindex>
+/// }
+/// ```
+/// To
+/// ```
+/// gpu.warp_execute_on_lane_0(%arg0) {
+/// ...
+/// }
+/// %lane_id_vec = vector.broadcast %arg0 : index to vector<1xindex>
+struct WarpOpStep final : public WarpDistributionPattern {
+ using Base::Base;
+ LogicalResult matchAndRewrite(WarpExecuteOnLane0Op warpOp,
+ PatternRewriter &rewriter) const override {
+ OpOperand *yieldOperand =
+ getWarpResult(warpOp, llvm::IsaPred<vector::StepOp>);
+ if (!yieldOperand)
+ return failure();
+ auto stepOp = yieldOperand->get().getDefiningOp<vector::StepOp>();
+ VectorType resTy = stepOp.getResult().getType();
+ rewriter.startOpModification(warpOp);
+ rewriter.setInsertionPointAfter(warpOp);
+ Value laneIdVec = vector::BroadcastOp::create(
+ rewriter, warpOp.getLoc(), VectorType::get({1}, resTy.getElementType()),
+ warpOp.getLaneid());
+ const unsigned operandIdx = yieldOperand->getOperandNumber();
+ rewriter.replaceAllUsesWith(warpOp.getResult(operandIdx), laneIdVec);
+ rewriter.finalizeOpModification(warpOp);
----------------
akroviakov wrote:
Thanks, I wasn't sure about this, so I followed the existing practice as in `WarpOpConstant`. Now that you say it is indeed not necessary, I remove it.
https://github.com/llvm/llvm-project/pull/155425
More information about the Mlir-commits
mailing list