-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[GlobalISel] Add G_EXTRACT_VECTOR_ELT for computeKnownBits
#164825
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
41200f3
[GlobalISel] Add G_EXTRACT_VECTOR_ELT for computeKnownBits
mooori 9a8b6ee
Bail if return_type != elt_type
mooori ab16e2c
Simpler known bits computation
mooori 8972b50
Merge remote-tracking branch 'upstream/main' into gisel-extr-vec
mooori d6c5c6b
fix format
mooori 2b91f9e
Merge remote-tracking branch 'upstream/main' into gisel-extr-vec
mooori 29db457
Remove `{}` and empty line
mooori 836dac5
Merge remote-tracking branch 'upstream/main' into gisel-extr-vec
mooori 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -641,6 +641,44 @@ void GISelValueTracking::computeKnownBitsImpl(Register R, KnownBits &Known, | |||
| Known.Zero.setBitsFrom(LowBits); | ||||
| break; | ||||
| } | ||||
| case TargetOpcode::G_EXTRACT_VECTOR_ELT: { | ||||
| GExtractVectorElement &Extract = cast<GExtractVectorElement>(MI); | ||||
| Register InVec = Extract.getVectorReg(); | ||||
| Register EltNo = Extract.getIndexReg(); | ||||
|
|
||||
| auto ConstEltNo = getIConstantVRegVal(EltNo, MRI); | ||||
|
|
||||
| LLT VecVT = MRI.getType(InVec); | ||||
| // computeKnownBits not yet implemented for scalable vectors. | ||||
| if (VecVT.isScalableVector()) | ||||
| break; | ||||
|
|
||||
| Known.Zero.setAllBits(); | ||||
| Known.One.setAllBits(); | ||||
|
|
||||
| const unsigned EltBitWidth = VecVT.getScalarSizeInBits(); | ||||
| const unsigned NumSrcElts = VecVT.getNumElements(); | ||||
|
|
||||
| // If BitWidth > EltBitWidth the value is anyext:ed. So we do not know | ||||
| // anything about the extended bits. | ||||
| if (BitWidth > EltBitWidth) | ||||
| Known = Known.trunc(EltBitWidth); | ||||
|
|
||||
| // If we know the element index, just demand that vector element, else for | ||||
| // an unknown element index, ignore DemandedElts and demand them all. | ||||
| APInt DemandedSrcElts = APInt::getAllOnes(NumSrcElts); | ||||
| if (ConstEltNo && ConstEltNo->ult(NumSrcElts)) | ||||
| DemandedSrcElts = | ||||
| APInt::getOneBitSet(NumSrcElts, ConstEltNo->getZExtValue()); | ||||
|
|
||||
| computeKnownBitsImpl(InVec, Known2, DemandedSrcElts, Depth + 1); | ||||
| Known = Known.intersectWith(Known2); | ||||
|
|
||||
| if (BitWidth > EltBitWidth) | ||||
| Known = Known.anyext(BitWidth); | ||||
|
|
||||
|
||||
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
117 changes: 117 additions & 0 deletions
117
llvm/test/CodeGen/AArch64/GlobalISel/knownbits-extract-vector.mir
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 |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| # NOTE: Assertions have been autogenerated by utils/update_givaluetracking_test_checks.py UTC_ARGS: --version 6 | ||
| # RUN: llc -mtriple aarch64 -passes="print<gisel-value-tracking>" %s -filetype=null 2>&1 | FileCheck %s | ||
|
|
||
| --- | ||
| name: all_knownbits_const_idx | ||
| body: | | ||
| bb.0: | ||
| ; CHECK-LABEL: name: @all_knownbits_const_idx | ||
| ; CHECK-NEXT: %0:_ KnownBits:00000011 SignBits:6 | ||
| ; CHECK-NEXT: %1:_ KnownBits:00001010 SignBits:4 | ||
| ; CHECK-NEXT: %2:_ KnownBits:0000?01? SignBits:4 | ||
| ; CHECK-NEXT: %idx:_ KnownBits:0000000000000000000000000000000000000000000000000000000000000001 SignBits:63 | ||
| ; CHECK-NEXT: %4:_ KnownBits:00001010 SignBits:4 | ||
| %0:_(s8) = G_CONSTANT i8 3 | ||
| %1:_(s8) = G_CONSTANT i8 10 | ||
| %2:_(<2 x s8>) = G_BUILD_VECTOR %0, %1 | ||
| %idx:_(s64) = G_CONSTANT i64 1 | ||
| %3:_(s8) = G_EXTRACT_VECTOR_ELT %2, %idx | ||
| ... | ||
| --- | ||
| name: all_knownbits | ||
| body: | | ||
| bb.0: | ||
| ; CHECK-LABEL: name: @all_knownbits | ||
| ; CHECK-NEXT: %0:_ KnownBits:00000011 SignBits:6 | ||
| ; CHECK-NEXT: %1:_ KnownBits:00001010 SignBits:4 | ||
| ; CHECK-NEXT: %2:_ KnownBits:0000?01? SignBits:4 | ||
| ; CHECK-NEXT: %idx:_ KnownBits:???????????????????????????????????????????????????????????????? SignBits:1 | ||
| ; CHECK-NEXT: %4:_ KnownBits:0000?01? SignBits:4 | ||
| %0:_(s8) = G_CONSTANT i8 3 | ||
| %1:_(s8) = G_CONSTANT i8 10 | ||
| %2:_(<2 x s8>) = G_BUILD_VECTOR %0, %1 | ||
| %idx:_(s64) = COPY $d0 | ||
| %3:_(s8) = G_EXTRACT_VECTOR_ELT %2, %idx | ||
| ... | ||
| --- | ||
| name: no_knownbits_const_idx | ||
| body: | | ||
| bb.0: | ||
| ; CHECK-LABEL: name: @no_knownbits_const_idx | ||
| ; CHECK-NEXT: %0:_ KnownBits:???????? SignBits:1 | ||
| ; CHECK-NEXT: %idx:_ KnownBits:0000000000000000000000000000000000000000000000000000000000000001 SignBits:63 | ||
| ; CHECK-NEXT: %2:_ KnownBits:???????? SignBits:1 | ||
| %0:_(<2 x s8>) = COPY $h0 | ||
| %idx:_(s64) = G_CONSTANT i64 1 | ||
| %1:_(s8) = G_EXTRACT_VECTOR_ELT %0, %idx | ||
| ... | ||
| --- | ||
| name: no_knownbits | ||
| body: | | ||
| bb.0: | ||
| ; CHECK-LABEL: name: @no_knownbits | ||
| ; CHECK-NEXT: %0:_ KnownBits:???????? SignBits:1 | ||
| ; CHECK-NEXT: %idx:_ KnownBits:???????????????????????????????????????????????????????????????? SignBits:1 | ||
| ; CHECK-NEXT: %2:_ KnownBits:???????? SignBits:1 | ||
| %0:_(<2 x s8>) = COPY $h0 | ||
| %idx:_(s64) = COPY $d1 | ||
| %1:_(s8) = G_EXTRACT_VECTOR_ELT %0, %idx | ||
| ... | ||
| --- | ||
| name: zext_const_idx | ||
| body: | | ||
| bb.0: | ||
| ; CHECK-LABEL: name: @zext_const_idx | ||
| ; CHECK-NEXT: %0:_ KnownBits:???????? SignBits:1 | ||
| ; CHECK-NEXT: %zext0:_ KnownBits:00000000???????? SignBits:8 | ||
| ; CHECK-NEXT: %idx:_ KnownBits:0000000000000000000000000000000000000000000000000000000000000001 SignBits:63 | ||
| ; CHECK-NEXT: %3:_ KnownBits:00000000???????? SignBits:8 | ||
| %0:_(<2 x s8>) = COPY $h0 | ||
| %zext0:_(<2 x s16>) = G_ZEXT %0 | ||
| %idx:_(s64) = G_CONSTANT i64 1 | ||
| %1:_(s16) = G_EXTRACT_VECTOR_ELT %zext0, %idx | ||
| ... | ||
| --- | ||
| name: zext | ||
| body: | | ||
| bb.0: | ||
|
|
||
| ; CHECK-LABEL: name: @zext | ||
| ; CHECK-NEXT: %0:_ KnownBits:???????? SignBits:1 | ||
| ; CHECK-NEXT: %zext0:_ KnownBits:00000000???????? SignBits:8 | ||
| ; CHECK-NEXT: %idx:_ KnownBits:???????????????????????????????????????????????????????????????? SignBits:1 | ||
| ; CHECK-NEXT: %3:_ KnownBits:00000000???????? SignBits:8 | ||
| %0:_(<2 x s8>) = COPY $h0 | ||
| %zext0:_(<2 x s16>) = G_ZEXT %0 | ||
| %idx:_(s64) = COPY $d1 | ||
| %1:_(s16) = G_EXTRACT_VECTOR_ELT %zext0, %idx | ||
| ... | ||
| --- | ||
| name: sext_const_idx | ||
| body: | | ||
| bb.0: | ||
| ; CHECK-LABEL: name: @sext_const_idx | ||
| ; CHECK-NEXT: %0:_ KnownBits:???????? SignBits:1 | ||
| ; CHECK-NEXT: %sext0:_ KnownBits:???????????????? SignBits:9 | ||
| ; CHECK-NEXT: %idx:_ KnownBits:0000000000000000000000000000000000000000000000000000000000000001 SignBits:63 | ||
| ; CHECK-NEXT: %3:_ KnownBits:???????????????? SignBits:1 | ||
| %0:_(<2 x s8>) = COPY $h0 | ||
| %sext0:_(<2 x s16>) = G_SEXT %0 | ||
| %idx:_(s64) = G_CONSTANT i64 1 | ||
| %1:_(s16) = G_EXTRACT_VECTOR_ELT %sext0, %idx | ||
| ... | ||
| --- | ||
| name: sext | ||
| body: | | ||
| bb.0: | ||
| ; CHECK-LABEL: name: @sext | ||
| ; CHECK-NEXT: %0:_ KnownBits:???????? SignBits:1 | ||
| ; CHECK-NEXT: %sext0:_ KnownBits:???????????????? SignBits:9 | ||
| ; CHECK-NEXT: %idx:_ KnownBits:???????????????????????????????????????????????????????????????? SignBits:1 | ||
| ; CHECK-NEXT: %3:_ KnownBits:???????????????? SignBits:1 | ||
| %0:_(<2 x s8>) = COPY $h0 | ||
| %sext0:_(<2 x s16>) = G_SEXT %0 | ||
| %idx:_(s64) = COPY $d1 | ||
| %1:_(s16) = G_EXTRACT_VECTOR_ELT %sext0, %idx | ||
| ... | ||
| --- |
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
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.
Can this just do
computeKnownBitsImpl(InVec, Known, DemandedSrcElts, Depth + 1);?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.
Done, it has not affected the generated code.