-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir] IntegerRangeAnalysis: add support for vector type #112292
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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// RUN: mlir-opt -int-range-optimizations -canonicalize %s | FileCheck %s | ||
|
||
|
||
Hardcode84 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// CHECK-LABEL: func @constant_vec | ||
// CHECK: test.reflect_bounds {smax = 7 : index, smin = 0 : index, umax = 7 : index, umin = 0 : index} | ||
func.func @constant_vec() -> vector<8xindex> { | ||
%0 = arith.constant dense<[0, 1, 2, 3, 4, 5, 6, 7]> : vector<8xindex> | ||
%1 = test.reflect_bounds %0 : vector<8xindex> | ||
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. I don't really know what these test Ops do and I couldn't find any documentation in code. Could add some docs, pls? 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. These test ops are from existing integer range inference tests - they have an implement of the integer range inference interface that sets attributes on 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. Yes, I gathered that much from mlir/test/lib/Dialect/Test/TestOps.td, but it doesn’t quite clarify things for me. The lack of documentation for these operations makes it hard to understand the distinction between Given that @Hardcode84 is already using these ops for testing, it would be fantastic if some of that expertise could be shared through documentation. This would benefit everyone working with these tests! 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. added some description to the ops |
||
func.return %1 : vector<8xindex> | ||
} | ||
|
||
// CHECK-LABEL: func @constant_splat | ||
// CHECK: test.reflect_bounds {smax = 3 : si32, smin = 3 : si32, umax = 3 : ui32, umin = 3 : ui32} | ||
func.func @constant_splat() -> vector<8xi32> { | ||
%0 = arith.constant dense<3> : vector<8xi32> | ||
%1 = test.reflect_bounds %0 : vector<8xi32> | ||
func.return %1 : vector<8xi32> | ||
} | ||
|
||
// CHECK-LABEL: func @vector_splat | ||
// CHECK: test.reflect_bounds {smax = 5 : index, smin = 4 : index, umax = 5 : index, umin = 4 : index} | ||
func.func @vector_splat() -> vector<4xindex> { | ||
%0 = test.with_bounds { umin = 4 : index, umax = 5 : index, smin = 4 : index, smax = 5 : index } : index | ||
%1 = vector.splat %0 : vector<4xindex> | ||
%2 = test.reflect_bounds %1 : vector<4xindex> | ||
func.return %2 : vector<4xindex> | ||
} | ||
|
||
// CHECK-LABEL: func @vector_broadcast | ||
// CHECK: test.reflect_bounds {smax = 5 : index, smin = 4 : index, umax = 5 : index, umin = 4 : index} | ||
func.func @vector_broadcast() -> vector<4x16xindex> { | ||
%0 = test.with_bounds { umin = 4 : index, umax = 5 : index, smin = 4 : index, smax = 5 : index } : vector<16xindex> | ||
%1 = vector.broadcast %0 : vector<16xindex> to vector<4x16xindex> | ||
%2 = test.reflect_bounds %1 : vector<4x16xindex> | ||
func.return %2 : vector<4x16xindex> | ||
} | ||
|
||
// CHECK-LABEL: func @vector_shape_cast | ||
// CHECK: test.reflect_bounds {smax = 5 : index, smin = 4 : index, umax = 5 : index, umin = 4 : index} | ||
func.func @vector_shape_cast() -> vector<4x4xindex> { | ||
%0 = test.with_bounds { umin = 4 : index, umax = 5 : index, smin = 4 : index, smax = 5 : index } : vector<16xindex> | ||
%1 = vector.shape_cast %0 : vector<16xindex> to vector<4x4xindex> | ||
%2 = test.reflect_bounds %1 : vector<4x4xindex> | ||
func.return %2 : vector<4x4xindex> | ||
} | ||
|
||
// CHECK-LABEL: func @vector_extract | ||
// CHECK: test.reflect_bounds {smax = 6 : index, smin = 5 : index, umax = 6 : index, umin = 5 : index} | ||
func.func @vector_extract() -> index { | ||
%0 = test.with_bounds { umin = 5 : index, umax = 6 : index, smin = 5 : index, smax = 6 : index } : vector<4xindex> | ||
%1 = vector.extract %0[0] : index from vector<4xindex> | ||
%2 = test.reflect_bounds %1 : index | ||
func.return %2 : index | ||
} | ||
|
||
// CHECK-LABEL: func @vector_extractelement | ||
// CHECK: test.reflect_bounds {smax = 7 : index, smin = 6 : index, umax = 7 : index, umin = 6 : index} | ||
func.func @vector_extractelement() -> index { | ||
%c0 = arith.constant 0 : index | ||
%0 = test.with_bounds { umin = 6 : index, umax = 7 : index, smin = 6 : index, smax = 7 : index } : vector<4xindex> | ||
%1 = vector.extractelement %0[%c0 : index] : vector<4xindex> | ||
%2 = test.reflect_bounds %1 : index | ||
func.return %2 : index | ||
} | ||
|
||
// CHECK-LABEL: func @vector_add | ||
// CHECK: test.reflect_bounds {smax = 12 : index, smin = 10 : index, umax = 12 : index, umin = 10 : index} | ||
func.func @vector_add() -> vector<4xindex> { | ||
%0 = test.with_bounds { umin = 4 : index, umax = 5 : index, smin = 4 : index, smax = 5 : index } : vector<4xindex> | ||
%1 = test.with_bounds { umin = 6 : index, umax = 7 : index, smin = 6 : index, smax = 7 : index } : vector<4xindex> | ||
%2 = arith.addi %0, %1 : vector<4xindex> | ||
%3 = test.reflect_bounds %2 : vector<4xindex> | ||
func.return %3 : vector<4xindex> | ||
} | ||
|
||
// CHECK-LABEL: func @vector_insert | ||
// CHECK: test.reflect_bounds {smax = 8 : index, smin = 5 : index, umax = 8 : index, umin = 5 : index} | ||
func.func @vector_insert() -> vector<4xindex> { | ||
%0 = test.with_bounds { umin = 5 : index, umax = 7 : index, smin = 5 : index, smax = 7 : index } : vector<4xindex> | ||
%1 = test.with_bounds { umin = 6 : index, umax = 8 : index, smin = 6 : index, smax = 8 : index } : index | ||
%2 = vector.insert %1, %0[0] : index into vector<4xindex> | ||
%3 = test.reflect_bounds %2 : vector<4xindex> | ||
func.return %3 : vector<4xindex> | ||
} | ||
|
||
// CHECK-LABEL: func @vector_insertelement | ||
// CHECK: test.reflect_bounds {smax = 8 : index, smin = 5 : index, umax = 8 : index, umin = 5 : index} | ||
func.func @vector_insertelement() -> vector<4xindex> { | ||
%c0 = arith.constant 0 : index | ||
%0 = test.with_bounds { umin = 5 : index, umax = 7 : index, smin = 5 : index, smax = 7 : index } : vector<4xindex> | ||
%1 = test.with_bounds { umin = 6 : index, umax = 8 : index, smin = 6 : index, smax = 8 : index } : index | ||
%2 = vector.insertelement %1, %0[%c0 : index] : vector<4xindex> | ||
%3 = test.reflect_bounds %2 : vector<4xindex> | ||
func.return %3 : vector<4xindex> | ||
} | ||
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. So, just because I can't remember exactly func.func @test_loaded_vector_extract(%memref : memref<16xi32>) -> i32 {
%c0 = arith.constant 0 : index
%v = vector.load %memref[%c0] : vector<4xi32>
%e = vector.extract %v[0]
%bounds = test.reflect_bounds %e : i32
func.return %bounds : i32
} 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. done |
||
|
||
// CHECK-LABEL: func @test_loaded_vector_extract | ||
// No bounds | ||
// CHECK: test.reflect_bounds %{{.*}} : i32 | ||
func.func @test_loaded_vector_extract(%memref : memref<16xi32>) -> i32 { | ||
%c0 = arith.constant 0 : index | ||
%v = vector.load %memref[%c0] : memref<16xi32>, vector<4xi32> | ||
%e = vector.extract %v[0] : i32 from vector<4xi32> | ||
%bounds = test.reflect_bounds %e : i32 | ||
func.return %bounds : i32 | ||
} |
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.
These look like unrelated changes?
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've added
mlir/Interfaces/InferIntRangeInterface.td
and sorted rests of the includes.