Skip to content

Commit 77914c9

Browse files
authored
[mlir][Vector] Do not propagate vector.extract on dynamic position (#148245)
Propagating vector.extract when a dynamic position is present can cause dominance issues and needs better handling. For now, disable propagation if there is a dynamic position present.
1 parent 84e15d0 commit 77914c9

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,12 @@ class ExtractOpFromElementwise final
10881088
if (!llvm::all_equal(eltwise->getOperandTypes()))
10891089
return rewriter.notifyMatchFailure(op, "operand types are different");
10901090

1091+
// Dynamic position can cause dominance issues, so conservatively fail for
1092+
// now.
1093+
if (!op.getDynamicPosition().empty())
1094+
return rewriter.notifyMatchFailure(
1095+
op, "dynamic position not yet implemented");
1096+
10911097
Type dstType = op.getType();
10921098

10931099
OpBuilder::InsertionGuard g(rewriter);

mlir/test/Dialect/Vector/vector-sink.mlir

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,18 @@ func.func @negative_extract_vec_fma(%arg0: vector<4xf32>, %arg1: vector<4xf32>,
514514
return %1 : f32
515515
}
516516

517+
// CHECK-LABEL: @negative_extract_dynamic_pos
518+
func.func @negative_extract_dynamic_pos(%arg0: vector<4xf32>, %arg1 : vector<4xf32>, %idx : vector<4xindex>) -> f32 {
519+
// CHECK-NOT: vector.extract
520+
// CHECK: arith.addf %{{.*}}, %{{.*}} : vector<4xf32>
521+
// CHECK: vector.extract
522+
// CHECK: vector.extract
523+
%0 = arith.addf %arg0, %arg1 : vector<4xf32>
524+
%1 = vector.extract %idx[0] : index from vector<4xindex>
525+
%2 = vector.extract %0[%1] : f32 from vector<4xf32>
526+
return %2 : f32
527+
}
528+
517529
//-----------------------------------------------------------------------------
518530
// [Pattern: ExtractOpFromLoad]
519531
//-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)