-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[SelectionDAG] Add MaskedValueIsZero check to allow folding of zero extended variables we know are safe to extend #85573
Merged
Conversation
This file contains 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
@llvm/pr-subscribers-backend-x86 @llvm/pr-subscribers-llvm-selectiondag Author: AtariDreams (AtariDreams) ChangesFull diff: https://github.com/llvm/llvm-project/pull/85573.diff 1 Files Affected:
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index b6a5925123f13f..e733916eaeefdb 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -13802,11 +13802,19 @@ SDValue DAGCombiner::visitZERO_EXTEND(SDNode *N) {
if (N0.getOpcode() == ISD::SHL) {
// If the original shl may be shifting out bits, do not perform this
// transformation.
- // TODO: Add MaskedValueIsZero check.
unsigned KnownZeroBits = ShVal.getValueSizeInBits() -
ShVal.getOperand(0).getValueSizeInBits();
- if (ShAmtC->getAPIntValue().ugt(KnownZeroBits))
- return SDValue();
+ if (ShAmtC->getAPIntValue().ugt(KnownZeroBits)) {
+ // Create a mask that has ones for the bits being shifted out.
+ llvm::APInt ShiftOutMask = llvm::APInt::getHighBitsSet(
+ ShVal.getValueSizeInBits(),
+ ShAmtC->getAPIntValue().getZExtValue());
+
+ // Check if the bits being shifted out are known to be zero.
+ if (!DAG.MaskedValueIsZero(ShVal, ShiftOutMask)) {
+ return SDValue();
+ }
+ }
}
// Ensure that the shift amount is wide enough for the shifted value.
|
AtariDreams
force-pushed
the
NX
branch
2 times, most recently
from
March 17, 2024 17:38
f50fe3d
to
7263953
Compare
AtariDreams
changed the title
Add MaskedValueIsZero check
[SelectionDAG] Replace KnownZeros ugt check with MaskedValueIsZero check
Mar 17, 2024
AtariDreams
force-pushed
the
NX
branch
4 times, most recently
from
March 18, 2024 00:06
5757125
to
4f775c6
Compare
AtariDreams
changed the title
[SelectionDAG] Replace KnownZeros ugt check with MaskedValueIsZero check
[SelectionDAG] Add MaskedValueIsZero check to allow folding of zero extended variables we know are safe to extend
Mar 18, 2024
AtariDreams
force-pushed
the
NX
branch
4 times, most recently
from
March 18, 2024 01:48
f01082a
to
035fec6
Compare
arsenm
reviewed
Mar 18, 2024
AtariDreams
force-pushed
the
NX
branch
2 times, most recently
from
March 18, 2024 16:00
8267260
to
bcf9e89
Compare
RKSimon
reviewed
Mar 18, 2024
AtariDreams
force-pushed
the
NX
branch
2 times, most recently
from
March 18, 2024 19:44
1ee29ec
to
d8d1ac1
Compare
arsenm
approved these changes
Mar 19, 2024
RKSimon
reviewed
Mar 19, 2024
AtariDreams
force-pushed
the
NX
branch
2 times, most recently
from
March 19, 2024 14:04
ed53ff1
to
a99f2b0
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
arsenm
approved these changes
Mar 20, 2024
clang-format error |
@arsenm Fixed! |
…xtended variables we know are safe to extend Add ones for every high bit that will cleared. This will allow us to evaluate variables that have their bits known to see if they have no risk of overflow despite the shift amount being greater than the difference between the two types.
chencha3
pushed a commit
to chencha3/llvm-project
that referenced
this pull request
Mar 23, 2024
…xtended variables we know are safe to extend (llvm#85573) Add ones for every high bit that will cleared. This will allow us to evaluate variables that have their bits known to see if they have no risk of overflow despite the shift amount being greater than the difference between the two types.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add ones for every high bit that will cleared.
This will allow us to evaluate variables that have their bits known to see if they have no risk of overflow despite the shift amount being greater than the difference between the two types.