-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[mlir][vector] Folder: shape_cast(extract) -> extract #146368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
09ba159
1c46b4e
302cb34
8c85bc7
cb30613
d9f45c1
4601e2b
899c108
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -823,17 +823,27 @@ func.func @negative_fold_extract_broadcast(%a : vector<1x1xf32>) -> vector<4xf32 | |
|
||
// ----- | ||
|
||
// CHECK-LABEL: fold_extract_splat | ||
// CHECK-LABEL: fold_extract_scalar_from_splat | ||
// CHECK-SAME: %[[A:.*]]: f32 | ||
// CHECK: return %[[A]] : f32 | ||
func.func @fold_extract_splat(%a : f32, %idx0 : index, %idx1 : index, %idx2 : index) -> f32 { | ||
func.func @fold_extract_scalar_from_splat(%a : f32, %idx0 : index, %idx1 : index, %idx2 : index) -> f32 { | ||
%b = vector.splat %a : vector<1x2x4xf32> | ||
%r = vector.extract %b[%idx0, %idx1, %idx2] : f32 from vector<1x2x4xf32> | ||
return %r : f32 | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: fold_extract_vector_from_splat | ||
// CHECK: vector.broadcast {{.*}} f32 to vector<4xf32> | ||
func.func @fold_extract_vector_from_splat(%a : f32, %idx0 : index, %idx1 : index) -> vector<4xf32> { | ||
%b = vector.splat %a : vector<1x2x4xf32> | ||
%r = vector.extract %b[%idx0, %idx1] : vector<4xf32> from vector<1x2x4xf32> | ||
return %r : vector<4xf32> | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: fold_extract_broadcast_dim1_broadcasting | ||
// CHECK-SAME: %[[A:.*]]: vector<2x1xf32> | ||
// CHECK-SAME: %[[IDX:.*]]: index, %[[IDX1:.*]]: index, %[[IDX2:.*]]: index | ||
|
@@ -863,6 +873,35 @@ func.func @fold_extract_broadcast_to_lower_rank(%a : vector<2x4xf32>, | |
|
||
// ----- | ||
|
||
// Test where the shape_cast is broadcast-like. | ||
// CHECK-LABEL: fold_extract_shape_cast_to_lower_rank | ||
// CHECK-SAME: %[[A:.*]]: vector<2x4xf32> | ||
// CHECK-SAME: %[[IDX0:.*]]: index, %[[IDX1:.*]]: index | ||
// CHECK: %[[B:.+]] = vector.extract %[[A]][%[[IDX1]]] : vector<4xf32> from vector<2x4xf32> | ||
// CHECK: return %[[B]] : vector<4xf32> | ||
func.func @fold_extract_shape_cast_to_lower_rank(%a : vector<2x4xf32>, | ||
%idx0 : index, %idx1 : index) -> vector<4xf32> { | ||
%b = vector.shape_cast %a : vector<2x4xf32> to vector<1x2x4xf32> | ||
%r = vector.extract %b[%idx0, %idx1] : vector<4xf32> from vector<1x2x4xf32> | ||
return %r : vector<4xf32> | ||
} | ||
|
||
// ----- | ||
|
||
// Test where the shape_cast is not broadcast-like, even though it prepends 1s. | ||
// CHECK-LABEL: negative_fold_extract_shape_cast_to_lower_rank | ||
// CHECK-NEXT: vector.shape_cast | ||
// CHECK-NEXT: vector.extract | ||
// CHECK-NEXT: return | ||
func.func @negative_fold_extract_shape_cast_to_lower_rank(%a : vector<2x4xf32>, | ||
%idx0 : index, %idx1 : index) -> vector<2xf32> { | ||
%b = vector.shape_cast %a : vector<2x4xf32> to vector<1x4x2xf32> | ||
%r = vector.extract %b[%idx0, %idx1] : vector<2xf32> from vector<1x4x2xf32> | ||
return %r : vector<2xf32> | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: fold_extract_broadcast_to_higher_rank | ||
// CHECK: %[[B:.*]] = vector.broadcast %{{.*}} : f32 to vector<4xf32> | ||
// CHECK: return %[[B]] : vector<4xf32> | ||
|
@@ -890,6 +929,19 @@ func.func @fold_extract_broadcast_to_equal_rank(%a : vector<1xf32>, %idx0 : inde | |
|
||
// ----- | ||
|
||
// CHECK-LABEL: fold_extract_broadcastlike_shape_cast | ||
// CHECK-SAME: %[[A:.*]]: vector<1xf32> | ||
// CHECK: %[[R:.*]] = vector.broadcast %[[A]] : vector<1xf32> to vector<1x1xf32> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the number of elements doesn't change, why not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shape_cast is the canonical form is definitely the end goal, your compass is still reading correctly! Getting there with small steps requires taking this little diversion though. Basically, this PR is ensuring that using shape_cast instead of broadcast/extract never results in missed folds. |
||
// CHECK: return %[[R]] : vector<1x1xf32> | ||
func.func @fold_extract_broadcastlike_shape_cast(%a : vector<1xf32>, %idx0 : index) | ||
-> vector<1x1xf32> { | ||
%s = vector.shape_cast %a : vector<1xf32> to vector<1x1x1xf32> | ||
%r = vector.extract %s[%idx0] : vector<1x1xf32> from vector<1x1x1xf32> | ||
return %r : vector<1x1xf32> | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: @fold_extract_shuffle | ||
// CHECK-SAME: %[[A:.*]]: vector<8xf32>, %[[B:.*]]: vector<8xf32> | ||
// CHECK-NOT: vector.shuffle | ||
|
@@ -1623,7 +1675,7 @@ func.func @negative_store_to_load_tensor_memref( | |
%arg0 : tensor<?x?xf32>, | ||
%arg1 : memref<?x?xf32>, | ||
%v0 : vector<4x2xf32> | ||
) -> vector<4x2xf32> | ||
) -> vector<4x2xf32> | ||
{ | ||
%c0 = arith.constant 0 : index | ||
%cf0 = arith.constant 0.0 : f32 | ||
|
@@ -1680,7 +1732,7 @@ func.func @negative_store_to_load_tensor_broadcast_out_of_bounds(%arg0 : tensor< | |
// CHECK: vector.transfer_read | ||
func.func @negative_store_to_load_tensor_broadcast_masked( | ||
%arg0 : tensor<?x?xf32>, %v0 : vector<4x2xf32>, %mask : vector<4x2xi1>) | ||
-> vector<4x2x6xf32> | ||
-> vector<4x2x6xf32> | ||
{ | ||
%c0 = arith.constant 0 : index | ||
%cf0 = arith.constant 0.0 : f32 | ||
|
Uh oh!
There was an error while loading. Please reload this page.