-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[DAG] SimplifyDemandedBits - ICMP_SLT(X,0) - only sign mask of X is required #164946
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
Open
an1k3sh
wants to merge
13
commits into
llvm:main
Choose a base branch
from
an1k3sh:dag-setcc-simplifydemanded
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5cf0b09
[DAG] SimplifyDemandedBits - ICMP_SLT(X,0) - only sign mask of X is r…
an1k3sh cd33ea9
clang-format changes
an1k3sh 4fe479e
Merge branch 'main' into dag-setcc-simplifydemanded
an1k3sh c52a02e
update tests for #164589 [DAG]SimplifyDemandedBits - ICMP_SLT(X,0) - …
an1k3sh 6276068
Update sign mask requirement for SETGE
an1k3sh b5f73f5
Update tests for SETGE
an1k3sh 82aa5ac
Combine scalar and vector checks for zero
an1k3sh 232ff84
bug fix - insert not when removing >= 0
an1k3sh 1b67549
update tests for >=0
an1k3sh f7def1c
add optimizations for <= -1 and > -1
an1k3sh 3ebf72d
update tests for <= -1 and > -1
an1k3sh 0bb1be8
clang-format changes
an1k3sh a79eda0
replace getNode with getNOT
an1k3sh 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1754,24 +1754,44 @@ bool TargetLowering::SimplifyDemandedBits( | |
| SDValue Op0 = Op.getOperand(0); | ||
| SDValue Op1 = Op.getOperand(1); | ||
| ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get(); | ||
| // If (1) we only need the sign-bit, (2) the setcc operands are the same | ||
| // width as the setcc result, and (3) the result of a setcc conforms to 0 or | ||
| // -1, we may be able to bypass the setcc. | ||
| if (DemandedBits.isSignMask() && | ||
| Op0.getScalarValueSizeInBits() == BitWidth && | ||
| getBooleanContents(Op0.getValueType()) == | ||
| BooleanContent::ZeroOrNegativeOneBooleanContent) { | ||
| // If we're testing X < 0, then this compare isn't needed - just use X! | ||
| // FIXME: We're limiting to integer types here, but this should also work | ||
| // if we don't care about FP signed-zero. The use of SETLT with FP means | ||
| // that we don't care about NaNs. | ||
| if (CC == ISD::SETLT && Op1.getValueType().isInteger() && | ||
| (isNullConstant(Op1) || ISD::isBuildVectorAllZeros(Op1.getNode()))) | ||
| return TLO.CombineTo(Op, Op0); | ||
|
|
||
| // TODO: Should we check for other forms of sign-bit comparisons? | ||
| // Examples: X <= -1, X >= 0 | ||
| // If we're testing X < 0, X >= 0, X <= -1 (X is of integer type) or X > -1 | ||
| // (X is of integer type) then we only need the sign mask of the previous | ||
| // result | ||
| // FIXME: We're limiting to integer types for X < 0 or X >= 0 here, but this | ||
| // should also work if we don't care about FP signed-zero. The use of SETLT | ||
| // with FP means that we don't care about NaNs. | ||
| if (((CC == ISD::SETLT || CC == ISD::SETGE) && | ||
| Op1.getValueType().isInteger() && isNullOrNullSplat(Op1)) || | ||
| ((CC == ISD::SETLE || CC == ISD::SETGT) && | ||
| Op1.getValueType().isInteger() && isAllOnesOrAllOnesSplat(Op1))) { | ||
| KnownBits KnownOp0; | ||
| bool Changed = false; | ||
| if (SimplifyDemandedBits( | ||
| Op0, APInt::getSignMask(Op0.getScalarValueSizeInBits()), | ||
| DemandedElts, KnownOp0, TLO, Depth + 1)) | ||
| Changed = true; | ||
| // If (1) we only need the sign-bit, (2) the setcc operands are the same | ||
| // width as the setcc result, and (3) the result of a setcc conforms to 0 | ||
| // or -1, we may be able to bypass the setcc. | ||
| if (DemandedBits.isSignMask() && | ||
| Op0.getScalarValueSizeInBits() == BitWidth && | ||
| getBooleanContents(Op0.getValueType()) == | ||
| BooleanContent::ZeroOrNegativeOneBooleanContent) { | ||
| // If we remove a >= 0 or > -1 (for integers), we need to introduce a | ||
| // NOT Operation | ||
| if (CC == ISD::SETGE || CC == ISD::SETGT) { | ||
| SDLoc DL(Op); | ||
| EVT VT = Op0.getValueType(); | ||
| SDValue NotOp0 = TLO.DAG.getNOT(DL, Op0, VT); | ||
| Changed |= TLO.CombineTo(Op, NotOp0); | ||
| } else { | ||
| Changed |= TLO.CombineTo(Op, Op0); | ||
| } | ||
| } | ||
| return Changed; | ||
| } | ||
| // TODO: Should we check for other forms of sign-bit comparisons? | ||
| // Example: X <= -1, X > -1 | ||
|
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. Is this FIXME still relevant? |
||
| if (getBooleanContents(Op0.getValueType()) == | ||
| TargetLowering::ZeroOrOneBooleanContent && | ||
| BitWidth > 1) | ||
|
|
||
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
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.
Can we just return true instead of allowing multiple optimizations. I think we will end up revisiting. Do any other places in this file do multiple optimizations like this?