-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[mlir][llvm dialect] Verify element type of nested types #148975
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
Open
newling
wants to merge
5
commits into
llvm:main
Choose a base branch
from
newling:move_llvm_constant_verifier_tests_to_dialect
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5cfdb67
move them to the correct place
newling 9bae051
add checks on element attributes for types
newling edcefce
address a few review comments
newling 53b6353
use original error message (as per review comment)
newling 4ba603f
remove one liner if statement's { and } as per review comment
newling File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -394,7 +394,7 @@ llvm.func @array_attribute_two_different_types() -> !llvm.struct<(f64, f64)> { | |||
// ----- | ||||
|
||||
llvm.func @struct_wrong_attribute_type() -> !llvm.struct<(f64, f64)> { | ||||
// expected-error @+1 {{expected array attribute}} | ||||
// expected-error @+1 {{expected array attribute for struct type}} | ||||
%0 = llvm.mlir.constant(1.0 : f64) : !llvm.struct<(f64, f64)> | ||||
llvm.return %0 : !llvm.struct<(f64, f64)> | ||||
} | ||||
|
@@ -439,6 +439,111 @@ llvm.func @scalable_vec_requires_splat() -> vector<[4]xf64> { | |||
llvm.return %0 : vector<[4]xf64> | ||||
} | ||||
|
||||
|
||||
// ----- | ||||
|
||||
llvm.func @int_attr_requires_int_type() -> f32 { | ||||
// expected-error @below{{expected integer type}} | ||||
%0 = llvm.mlir.constant(1 : index) : f32 | ||||
llvm.return %0 : f32 | ||||
} | ||||
|
||||
// ----- | ||||
|
||||
llvm.func @vector_int_attr_requires_int_type() -> vector<2xf32> { | ||||
// expected-error @below{{expected integer element type}} | ||||
%0 = llvm.mlir.constant(dense<[1, 2]> : vector<2xi32>) : vector<2xf32> | ||||
llvm.return %0 : vector<2xf32> | ||||
} | ||||
|
||||
// ----- | ||||
|
||||
llvm.func @float_attr_and_type_required_same() -> f16 { | ||||
// expected-error @below{{attribute and type have different float semantics}} | ||||
%cst = llvm.mlir.constant(1.0 : bf16) : f16 | ||||
llvm.return %cst : f16 | ||||
} | ||||
|
||||
// ----- | ||||
|
||||
llvm.func @vector_float_attr_and_type_required_same() -> vector<2xf16> { | ||||
// expected-error @below{{attribute and type have different float semantics}} | ||||
%cst = llvm.mlir.constant(dense<[1.0, 2.0]> : vector<2xbf16>) : vector<2xf16> | ||||
llvm.return %cst : vector<2xf16> | ||||
} | ||||
|
||||
// ----- | ||||
|
||||
llvm.func @incompatible_integer_type_for_float_attr() -> i32 { | ||||
// expected-error @below{{expected integer type of width 16}} | ||||
%cst = llvm.mlir.constant(1.0 : f16) : i32 | ||||
llvm.return %cst : i32 | ||||
} | ||||
|
||||
// ----- | ||||
|
||||
llvm.func @vector_incompatible_integer_type_for_float_attr() -> vector<2xi8> { | ||||
// expected-error @below{{expected integer type of width 16}} | ||||
%cst = llvm.mlir.constant(dense<[1.0, 2.0]> : vector<2xf16>) : vector<2xi8> | ||||
llvm.return %cst : vector<2xi8> | ||||
} | ||||
|
||||
// ----- | ||||
|
||||
llvm.func @vector_with_non_vector_type() -> f32 { | ||||
// expected-error @below{{expected vector or array type}} | ||||
%cst = llvm.mlir.constant(dense<100.0> : vector<1xf64>) : f32 | ||||
llvm.return %cst : f32 | ||||
} | ||||
|
||||
// ----- | ||||
|
||||
llvm.func @array_attr_with_invalid_type() -> i32 { | ||||
// expected-error @below{{expected array or struct type for array attribute}} | ||||
%0 = llvm.mlir.constant([1 : i32]) : i32 | ||||
llvm.return %0 : i32 | ||||
} | ||||
|
||||
// ----- | ||||
|
||||
llvm.func @elements_attribute_incompatible_nested_array_struct1_type() -> !llvm.array<2 x array<2 x array<2 x struct<(i32)>>>> { | ||||
// expected-error @below{{expected integer element type for integer elements attribute}} | ||||
%0 = llvm.mlir.constant(dense<[[[1, 2], [3, 4]], [[42, 43], [44, 45]]]> : tensor<2x2x2xi32>) : !llvm.array<2 x array<2 x array<2 x struct<(i32)>>>> | ||||
llvm.return %0 : !llvm.array<2 x array<2 x array<2 x struct<(i32)>>>> | ||||
} | ||||
|
||||
// ----- | ||||
|
||||
llvm.func @elements_attribute_incompatible_nested_array_struct3_type() -> !llvm.array<2 x array<2 x array<2 x struct<(i32, i32, i32)>>>> { | ||||
// expected-error @below{{expected integer element type for integer elements attribute}} | ||||
%0 = llvm.mlir.constant(dense<[[[1, 2], [3, 4]], [[42, 43], [44, 45]]]> : tensor<2x2x2xi32>) : !llvm.array<2 x array<2 x array<2 x struct<(i32, i32, i32)>>>> | ||||
llvm.return %0 : !llvm.array<2 x array<2 x array<2 x struct<(i32, i32, i32)>>>> | ||||
} | ||||
|
||||
// ----- | ||||
|
||||
llvm.func @invalid_struct_element_type() -> !llvm.struct<(f64, array<2 x i32>)> { | ||||
// expected-error @below{{expected struct element types to be floating point type or integer type}} | ||||
%0 = llvm.mlir.constant([1.0 : f64, dense<[1, 2]> : tensor<2xi32>]) : !llvm.struct<(f64, array<2 x i32>)> | ||||
llvm.return %0 : !llvm.struct<(f64, array<2 x i32>)> | ||||
} | ||||
|
||||
// ----- | ||||
|
||||
llvm.func @wrong_struct_element_attr_type() -> !llvm.struct<(f64, f64)> { | ||||
// expected-error @below{{expected element of array attribute to be floating point or integer}} | ||||
%0 = llvm.mlir.constant([dense<[1, 2]> : tensor<2xi32>, 2.0 : f64]) : !llvm.struct<(f64, f64)> | ||||
llvm.return %0 : !llvm.struct<(f64, f64)> | ||||
} | ||||
|
||||
// ----- | ||||
|
||||
llvm.func @struct_wrong_attribute_element_type() -> !llvm.struct<(f64, f64)> { | ||||
// expected-error @below{{struct element at index 0 is of wrong type}} | ||||
%0 = llvm.mlir.constant([1.0 : f32, 1.0 : f32]) : !llvm.struct<(f64, f64)> | ||||
llvm.return %0 : !llvm.struct<(f64, f64)> | ||||
} | ||||
|
||||
// ----- | ||||
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.
Suggested change
nit: one split can be dropped |
||||
|
||||
func.func @insertvalue_non_llvm_type(%a : i32, %b : i32) { | ||||
|
@@ -484,13 +589,13 @@ func.func @extractvalue_invalid_type(%a : !llvm.array<4 x vector<8xf32>>) -> !ll | |||
return %b : !llvm.array<4 x vector<8xf32>> | ||||
} | ||||
|
||||
|
||||
// ----- | ||||
|
||||
func.func @extractvalue_non_llvm_type(%a : i32, %b : tensor<*xi32>) { | ||||
// expected-error@+2 {{expected LLVM IR Dialect type}} | ||||
llvm.extractvalue %b[0] : tensor<*xi32> | ||||
} | ||||
|
||||
// ----- | ||||
|
||||
func.func @extractvalue_struct_out_of_bounds() { | ||||
|
@@ -659,6 +764,7 @@ func.func @atomicrmw_scalable_vector(%ptr : !llvm.ptr, %f32_vec : vector<[2]xf32 | |||
%0 = llvm.atomicrmw fadd %ptr, %f32_vec unordered : !llvm.ptr, vector<[2]xf32> | ||||
llvm.return | ||||
} | ||||
|
||||
// ----- | ||||
|
||||
func.func @atomicrmw_vector_expected_float(%ptr : !llvm.ptr, %i32_vec : vector<3xi32>) { | ||||
|
@@ -1667,7 +1773,6 @@ func.func @tma_load(%tmaDescriptor: !llvm.ptr, %dest : !llvm.ptr<3>, %barrier: ! | |||
return | ||||
} | ||||
|
||||
|
||||
// ----- | ||||
|
||||
func.func @tma_load(%tmaDescriptor: !llvm.ptr, %dest : !llvm.ptr<3>, %barrier: !llvm.ptr<3>, %crd0: i32, %crd1: i32, %crd2: i32, %crd3: i32, %off0: i16, %off1: i16, %ctamask : i16, %cacheHint : i64, %p : i1) { | ||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: the TensorType can be dropped. It is not a compatible LLVM type (see
isCompatibleOuterType
) and since ConstantOp returns an LLVM type there should be no tensors 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.
Should the following fail to verify?
It currently roundtrips without issue.
Maybe what is confusing here is that I'm using this method to test both the attribute's element type as well the constant op's result's element type?
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 would have expected that we use:
But if the tensor type shows up in the wild on the attribute then we can keep your version of the code.