-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[Instcombine] Combine extractelement from a vector_extract at index 0 #151491
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 3 commits
0341313
d93bdea
d9b7aa9
c43f883
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
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. Add a negative test with non-zero vector.extract? Also test a variable index extract?
Contributor
Author
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. Thank you @nikic, while adding a variable index test I realised this case wasn't handled. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
| ; RUN: opt -S -passes=instcombine < %s | FileCheck %s | ||
|
|
||
| define i1 @extract_const_idx(<vscale x 4 x i1> %a) { | ||
| ; CHECK-LABEL: define i1 @extract_const_idx( | ||
| ; CHECK-SAME: <vscale x 4 x i1> [[A:%.*]]) { | ||
| ; CHECK-NEXT: [[ELT:%.*]] = extractelement <vscale x 4 x i1> [[A]], i64 1 | ||
| ; CHECK-NEXT: ret i1 [[ELT]] | ||
| ; | ||
| %subvec = call <vscale x 2 x i1> @llvm.vector.extract.nxv2i1.nxv4i1.i64(<vscale x 4 x i1> %a, i64 0) | ||
| %elt = extractelement <vscale x 2 x i1> %subvec, i32 1 | ||
| ret i1 %elt | ||
| } | ||
|
|
||
| define float @extract_variable_idx(<vscale x 4 x float> %a, i32 %idx) { | ||
| ; CHECK-LABEL: define float @extract_variable_idx( | ||
| ; CHECK-SAME: <vscale x 4 x float> [[A:%.*]], i32 [[IDX:%.*]]) { | ||
| ; CHECK-NEXT: [[ELT:%.*]] = extractelement <vscale x 4 x float> [[A]], i32 [[IDX]] | ||
| ; CHECK-NEXT: ret float [[ELT]] | ||
| ; | ||
| %subvec = call <vscale x 2 x float> @llvm.vector.extract.nxv2f32.nxv4f32.i64(<vscale x 4 x float> %a, i64 0) | ||
| %elt = extractelement <vscale x 2 x float> %subvec, i32 %idx | ||
| ret float %elt | ||
| } | ||
|
|
||
| define float @negative_test(<vscale x 4 x float> %a) { | ||
| ; CHECK-LABEL: define float @negative_test( | ||
| ; CHECK-SAME: <vscale x 4 x float> [[A:%.*]]) { | ||
| ; CHECK-NEXT: [[SUBVEC:%.*]] = call <vscale x 2 x float> @llvm.vector.extract.nxv2f32.nxv4f32(<vscale x 4 x float> [[A]], i64 2) | ||
| ; CHECK-NEXT: [[ELT:%.*]] = extractelement <vscale x 2 x float> [[SUBVEC]], i64 1 | ||
| ; CHECK-NEXT: ret float [[ELT]] | ||
| ; | ||
| %subvec = call <vscale x 2 x float> @llvm.vector.extract.nxv2f32.nxv4f32.i64(<vscale x 4 x float> %a, i64 2) | ||
| %elt = extractelement <vscale x 2 x float> %subvec, i32 1 | ||
| ret float %elt | ||
| } |
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.
Up to you but using PatternMatch would remove the need for II and casts. For example: