-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[SelectionDAG] Allow vselect in foldBinOpIntoSelect #143283
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2490,7 +2490,8 @@ SDValue DAGCombiner::foldBinOpIntoSelect(SDNode *BO) { | |
| unsigned SelOpNo = 0; | ||
| SDValue Sel = BO->getOperand(0); | ||
| auto BinOpcode = BO->getOpcode(); | ||
| if (Sel.getOpcode() != ISD::SELECT || !Sel.hasOneUse()) { | ||
| if ((Sel.getOpcode() != ISD::SELECT && Sel.getOpcode() != ISD::VSELECT) || | ||
| !Sel.hasOneUse()) { | ||
| SelOpNo = 1; | ||
| Sel = BO->getOperand(1); | ||
|
|
||
|
|
@@ -2506,7 +2507,8 @@ SDValue DAGCombiner::foldBinOpIntoSelect(SDNode *BO) { | |
| } | ||
| } | ||
|
|
||
| if (Sel.getOpcode() != ISD::SELECT || !Sel.hasOneUse()) | ||
| if ((Sel.getOpcode() != ISD::SELECT && Sel.getOpcode() != ISD::VSELECT) || | ||
| !Sel.hasOneUse()) | ||
| return SDValue(); | ||
|
|
||
| SDValue CT = Sel.getOperand(1); | ||
|
|
@@ -10017,7 +10019,8 @@ SDValue DAGCombiner::visitShiftByConstant(SDNode *N) { | |
| BinOpLHSVal.getOpcode() == ISD::SRL) && | ||
| isa<ConstantSDNode>(BinOpLHSVal.getOperand(1)); | ||
| bool IsCopyOrSelect = BinOpLHSVal.getOpcode() == ISD::CopyFromReg || | ||
| BinOpLHSVal.getOpcode() == ISD::SELECT; | ||
| BinOpLHSVal.getOpcode() == ISD::SELECT || | ||
| BinOpLHSVal.getOpcode() == ISD::VSELECT; | ||
|
|
||
| if (!IsShiftByConstant && !IsCopyOrSelect) | ||
| return SDValue(); | ||
|
|
@@ -13435,7 +13438,7 @@ static SDValue tryToFoldExtendOfConstant(SDNode *N, const SDLoc &DL, | |
| // fold (sext (select cond, c1, c2)) -> (select cond, sext c1, sext c2) | ||
| // fold (zext (select cond, c1, c2)) -> (select cond, zext c1, zext c2) | ||
| // fold (aext (select cond, c1, c2)) -> (select cond, sext c1, sext c2) | ||
| if (N0->getOpcode() == ISD::SELECT) { | ||
| if (N0->getOpcode() == ISD::SELECT || N0->getOpcode() == ISD::VSELECT) { | ||
| SDValue Op1 = N0->getOperand(1); | ||
| SDValue Op2 = N0->getOperand(2); | ||
| if (isa<ConstantSDNode>(Op1) && isa<ConstantSDNode>(Op2) && | ||
|
|
@@ -17763,10 +17766,11 @@ SDValue DAGCombiner::visitFMUL(SDNode *N) { | |
| // fold (fmul X, (select (fcmp X > 0.0), -1.0, 1.0)) -> (fneg (fabs X)) | ||
| // fold (fmul X, (select (fcmp X > 0.0), 1.0, -1.0)) -> (fabs X) | ||
| if (Flags.hasNoNaNs() && Flags.hasNoSignedZeros() && | ||
| (N0.getOpcode() == ISD::SELECT || N1.getOpcode() == ISD::SELECT) && | ||
| (N0.getOpcode() == ISD::SELECT || N0.getOpcode() == ISD::VSELECT || | ||
|
Collaborator
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. This code isn't in the function this PR title references. |
||
| N1.getOpcode() == ISD::SELECT || N1.getOpcode() == ISD::VSELECT) && | ||
| TLI.isOperationLegal(ISD::FABS, VT)) { | ||
| SDValue Select = N0, X = N1; | ||
| if (Select.getOpcode() != ISD::SELECT) | ||
| if (Select.getOpcode() != ISD::SELECT && Select.getOpcode() != ISD::VSELECT) | ||
| std::swap(Select, X); | ||
|
|
||
| SDValue Cond = Select.getOperand(0); | ||
|
Collaborator
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. Don't the checks for ConstantFPSDNode right below this prevent this from doing anything for VSELECT? ConstantFPSDNode is only used for scalars. |
||
|
|
||
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.
Split this and the fmul negation changes into their own patches with test coverage