-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][Vector] Remove uses of vector.extractelement/vector.insertelement #113827
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
Closed
Closed
Changes from all commits
Commits
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 |
---|---|---|
|
@@ -157,7 +157,7 @@ static Value generateMaskCheck(OpBuilder &b, OpTy xferOp, Value iv) { | |
return Value(); | ||
|
||
Location loc = xferOp.getLoc(); | ||
return b.create<vector::ExtractElementOp>(loc, xferOp.getMask(), iv); | ||
return b.create<vector::ExtractOp>(loc, xferOp.getMask(), iv); | ||
} | ||
|
||
/// Helper function TransferOpConversion and TransferOp1dConversion. | ||
|
@@ -686,7 +686,7 @@ struct PrepareTransferWriteConversion | |
/// %lastIndex = arith.subi %length, %c1 : index | ||
/// vector.print punctuation <open> | ||
/// scf.for %i = %c0 to %length step %c1 { | ||
/// %el = vector.extractelement %v[%i : index] : vector<[4]xi32> | ||
/// %el = vector.extract %v[%i : index] : vector<[4]xi32> | ||
/// vector.print %el : i32 punctuation <no_punctuation> | ||
/// %notLastIndex = arith.cmpi ult, %i, %lastIndex : index | ||
/// scf.if %notLastIndex { | ||
|
@@ -756,7 +756,8 @@ struct DecomposePrintOpConversion : public VectorToSCFPattern<vector::PrintOp> { | |
if (vectorType.getRank() != 1) { | ||
// Flatten n-D vectors to 1D. This is done to allow indexing with a | ||
// non-constant value (which can currently only be done via | ||
// vector.extractelement for 1D vectors). | ||
// vector.extract for 1D vectors). | ||
// TODO: vector.extract supports N-D non-constant indices now. | ||
auto flatLength = std::accumulate(shape.begin(), shape.end(), 1, | ||
std::multiplies<int64_t>()); | ||
auto flatVectorType = | ||
|
@@ -819,8 +820,7 @@ struct DecomposePrintOpConversion : public VectorToSCFPattern<vector::PrintOp> { | |
} | ||
|
||
// Print the scalar elements in the inner most loop. | ||
auto element = | ||
rewriter.create<vector::ExtractElementOp>(loc, value, flatIndex); | ||
auto element = rewriter.create<vector::ExtractOp>(loc, value, flatIndex); | ||
rewriter.create<vector::PrintOp>(loc, element, | ||
vector::PrintPunctuation::NoPunctuation); | ||
|
||
|
@@ -1563,7 +1563,7 @@ struct Strategy1d<TransferReadOp> { | |
[&](OpBuilder &b, Location loc) { | ||
Value val = | ||
b.create<memref::LoadOp>(loc, xferOp.getSource(), indices); | ||
return b.create<vector::InsertElementOp>(loc, val, vec, iv); | ||
return b.create<vector::InsertOp>(loc, val, vec, iv); | ||
}, | ||
/*outOfBoundsCase=*/ | ||
[&](OpBuilder & /*b*/, Location loc) { return vec; }); | ||
|
@@ -1591,8 +1591,7 @@ struct Strategy1d<TransferWriteOp> { | |
generateInBoundsCheck( | ||
b, xferOp, iv, dim, | ||
/*inBoundsCase=*/[&](OpBuilder &b, Location loc) { | ||
auto val = | ||
b.create<vector::ExtractElementOp>(loc, xferOp.getVector(), iv); | ||
auto val = b.create<vector::ExtractOp>(loc, xferOp.getVector(), iv); | ||
b.create<memref::StoreOp>(loc, val, xferOp.getSource(), indices); | ||
}); | ||
b.create<scf::YieldOp>(loc); | ||
|
@@ -1614,7 +1613,7 @@ struct Strategy1d<TransferWriteOp> { | |
/// This pattern generates IR as follows: | ||
/// | ||
/// 1. Generate a for loop iterating over each vector element. | ||
/// 2. Inside the loop, generate a InsertElementOp or ExtractElementOp, | ||
/// 2. Inside the loop, generate a InsertOp or ExtractOp, | ||
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. nit: an |
||
/// depending on OpTy. | ||
/// | ||
/// TODO: In some cases (no masking, etc.), LLVM::MatrixColumnMajorLoadOp | ||
|
@@ -1630,7 +1629,7 @@ struct Strategy1d<TransferWriteOp> { | |
/// Is rewritten to approximately the following pseudo-IR: | ||
/// ``` | ||
/// for i = 0 to 9 { | ||
/// %t = vector.extractelement %vec[i] : vector<9xf32> | ||
/// %t = vector.extract %vec[i] : vector<9xf32> | ||
/// memref.store %t, %arg0[%a + i, %b] : memref<?x?xf32> | ||
/// } | ||
/// ``` | ||
|
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
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
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
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
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 |
---|---|---|
|
@@ -233,10 +233,9 @@ func.func @broadcast_vec2d_from_vec0d(%arg0: vector<f32>) -> vector<3x2xf32> { | |
// CHECK-LABEL: @broadcast_vec2d_from_vec0d( | ||
// CHECK-SAME: %[[A:.*]]: vector<f32>) | ||
// CHECK: %[[T0:.*]] = builtin.unrealized_conversion_cast %[[A]] : vector<f32> to vector<1xf32> | ||
// CHECK: %[[T5:.*]] = builtin.unrealized_conversion_cast %[[T0]] : vector<1xf32> to f32 | ||
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. Hm, why wouldn't this be lowered to |
||
// CHECK: %[[T1:.*]] = arith.constant dense<0.000000e+00> : vector<3x2xf32> | ||
// CHECK: %[[T2:.*]] = builtin.unrealized_conversion_cast %[[T1]] : vector<3x2xf32> to !llvm.array<3 x vector<2xf32>> | ||
// CHECK: %[[T4:.*]] = llvm.mlir.constant(0 : index) : i64 | ||
// CHECK: %[[T5:.*]] = llvm.extractelement %[[T0]][%[[T4]] : i64] : vector<1xf32> | ||
// CHECK: %[[T6Insert:.*]] = llvm.insertelement %[[T5]] | ||
// CHECK: %[[T6:.*]] = llvm.shufflevector %[[T6Insert]] | ||
// CHECK: %[[T7:.*]] = llvm.insertvalue %[[T6]], %[[T2]][0] : !llvm.array<3 x vector<2xf32>> | ||
|
Oops, something went wrong.
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.
Let's either remove this block (preferred) or rephrase the outdated comment - right now it's not clear what the TODO is (missing verb).
Suggestion (but I'd really prefer this being removed instead):
Or something similar :)
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.
Fully dynamic n-D vector.inserts/extracts still do not have a lowering.