-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir] Replace dynamic sizes in insert_slice of tensor.cast canonicalization #91352
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
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 |
---|---|---|
|
@@ -755,6 +755,34 @@ func.func @fold_dim_of_tensor.cast(%arg0 : tensor<4x?xf32>) -> (index, index) { | |
|
||
// ----- | ||
|
||
// CHECK-LABEL: func @insert_slice_cast | ||
func.func @insert_slice_cast(%arg0 : tensor<1x?xf32>, %arg1 : tensor<?x?xf32>, %arg2 : index, %arg3 : index, %arg4 : index, %arg5 : index, %arg6 : index, %arg7 : index) -> tensor<?x?xf32> { | ||
// CHECK-SAME: %[[ARG0:.*]]: tensor<1x?xf32> | ||
%0 = tensor.cast %arg0 : tensor<1x?xf32> to tensor<?x?xf32> | ||
// CHECK: %[[RES:.*]] = tensor.insert_slice %[[ARG0]] | ||
// CHECK-SAME: [{{.*}}, {{.*}}] [1, {{.*}}] [{{.*}}, {{.*}}] | ||
// CHECK-SAME: : tensor<1x?xf32> into tensor<?x?xf32> | ||
%1 = tensor.insert_slice %0 into %arg1[%arg2, %arg3] [%arg4, %arg5] [%arg6, %arg7] : tensor<?x?xf32> into tensor<?x?xf32> | ||
// CHECK: return %[[RES]] : tensor<?x?xf32> | ||
return %1 : tensor<?x?xf32> | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: func @insert_slice_cast_no_fold | ||
func.func @insert_slice_cast_no_fold(%arg0 : tensor<1x?xf32>, %arg1 : tensor<?x?xf32>, %arg2 : index, %arg3 : index, %arg4 : index, %arg5 : index, %arg6 : index, %arg7 : index) -> tensor<?x?xf32> { | ||
%0 = tensor.cast %arg0 : tensor<1x?xf32> to tensor<?x5xf32> | ||
// CHECK: %[[CAST:.*]] = tensor.cast | ||
// CHECK: %[[RES:.*]] = tensor.insert_slice %[[CAST]] | ||
// CHECK-SAME: [{{.*}}, {{.*}}] [{{.*}}, 5] [{{.*}}, {{.*}}] | ||
// CHECK-SAME: : tensor<?x5xf32> into tensor<?x?xf32> | ||
%1 = tensor.insert_slice %0 into %arg1[%arg2, %arg3] [%arg4, 5] [%arg6, %arg7] : tensor<?x5xf32> into tensor<?x?xf32> | ||
// CHECK: return %[[RES]] : tensor<?x?xf32> | ||
return %1 : tensor<?x?xf32> | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: func @insert_tensor_cast_on_insert_slice_src( | ||
// CHECK-SAME: %[[arg0:.*]]: tensor<?x5x?xf32>, %[[arg1:.*]]: tensor<?x?x?xf32> | ||
// CHECK: %[[cast:.*]] = tensor.cast %[[arg0]] : tensor<?x5x?xf32> to tensor<64x5x64xf32> | ||
|
@@ -1890,21 +1918,6 @@ func.func @splat_dynamic_no_fold(%m: index) -> tensor<4x?xf32> { | |
|
||
// ----- | ||
|
||
// There was an issue in cast + insert_slice folding generating invalid ir. | ||
// https://github.com/llvm/llvm-project/issues/53099 | ||
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. hmm this test was guarding against an issue that was previously fixed. 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. It is moved to l.758. I think the revision adds the support for the case. It is generating valid IR now. 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. ah yes, thank you! |
||
// CHECK-LABEL: func @insert_slice_cast | ||
func.func @insert_slice_cast(%arg0 : tensor<1x?xf32>, %arg1 : tensor<?x?xf32>, %arg2 : index, %arg3 : index, %arg4 : index, %arg5 : index, %arg6 : index, %arg7 : index) -> tensor<?x?xf32> { | ||
// CHECK: %[[CAST:.*]] = tensor.cast %{{.*}} : tensor<1x?xf32> to tensor<?x?xf32> | ||
%0 = tensor.cast %arg0 : tensor<1x?xf32> to tensor<?x?xf32> | ||
// CHECK: %[[RES:.*]] = tensor.insert_slice %[[CAST]] | ||
// CHECK-SAME: : tensor<?x?xf32> into tensor<?x?xf32> | ||
%1 = tensor.insert_slice %0 into %arg1[%arg2, %arg3] [%arg4, %arg5] [%arg6, %arg7] : tensor<?x?xf32> into tensor<?x?xf32> | ||
// CHECK: return %[[RES]] : tensor<?x?xf32> | ||
return %1 : tensor<?x?xf32> | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: func @cast_extract_slice | ||
func.func @cast_extract_slice(%arg0 : tensor<128x512xf32>, %s : index, %o : index) | ||
-> tensor<16x512xf32> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The values won't be modified, how about using
ArrayRef<int64_t>
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They actually do get modified later on L2735.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, somehow I missed it when I was searching the use of the variable.