[Mlir-commits] [mlir] [MLIR][Vector] Step op warp distribution (PR #155425)
Charitha Saumya
llvmlistbot at llvm.org
Tue Aug 26 10:21:06 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(
----------------
charithaintc wrote:
why broadcast? why not lower to a vector.step and arith.add which is more general.
Example:
input:
```
%s = vector.step : vector<32xindex>
```
lower to:
```
%s = vector.step : vector<1xindex>
%laneid = gpu.laneid
%o = vector.from_elements %laneid : vector<1xindex>
%r = arith.add %s, %o
```
This will work if the step output is a multiple of sg size.
https://github.com/llvm/llvm-project/pull/155425
More information about the Mlir-commits
mailing list