-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[X86] Fold generic ADD/SUB with constants to X86ISD::SUB/ADD #164316
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 1 commit
1a92b33
b9f1d0f
576b93e
4662b9e
64521e9
918285d
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 |
|---|---|---|
|
|
@@ -57616,10 +57616,10 @@ static SDValue combineX86AddSub(SDNode *N, SelectionDAG &DAG, | |
| } | ||
|
|
||
| // Fold any similar generic ADD/SUB opcodes to reuse this node. | ||
| auto MatchGeneric = [&](SDValue N0, SDValue N1, bool Negate) { | ||
| auto MatchGeneric = [&](unsigned Opc, SDValue N0, SDValue N1, bool Negate) { | ||
| SDValue Ops[] = {N0, N1}; | ||
| SDVTList VTs = DAG.getVTList(N->getValueType(0)); | ||
| if (SDNode *GenericAddSub = DAG.getNodeIfExists(GenericOpc, VTs, Ops)) { | ||
| if (SDNode *GenericAddSub = DAG.getNodeIfExists(Opc, VTs, Ops)) { | ||
| SDValue Op(N, 0); | ||
| if (Negate) { | ||
| // Bail if this is only used by a user of the x86 add/sub. | ||
|
|
@@ -57631,8 +57631,25 @@ static SDValue combineX86AddSub(SDNode *N, SelectionDAG &DAG, | |
| DCI.CombineTo(GenericAddSub, Op); | ||
| } | ||
| }; | ||
| MatchGeneric(LHS, RHS, false); | ||
| MatchGeneric(RHS, LHS, X86ISD::SUB == N->getOpcode()); | ||
| MatchGeneric(GenericOpc, LHS, RHS, false); | ||
| MatchGeneric(GenericOpc, RHS, LHS, X86ISD::SUB == N->getOpcode()); | ||
|
|
||
| if (ConstantSDNode *Const = dyn_cast<ConstantSDNode>(RHS)) { | ||
| SDValue NegC = DAG.getConstant(-Const->getAPIntValue(), DL, VT); | ||
| if (X86ISD::SUB == N->getOpcode()) { | ||
| // With LHS - C, fold LHS + (-C) | ||
|
||
| MatchGeneric(ISD::ADD, LHS, NegC, false); | ||
| } else { | ||
| // With -(LHS + C), fold (-C) - LHS | ||
|
||
| MatchGeneric(ISD::SUB, NegC, LHS, true); | ||
| } | ||
| } else if (ConstantSDNode *Const = dyn_cast<ConstantSDNode>(LHS)) { | ||
RKSimon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| SDValue NegC = DAG.getConstant(-Const->getAPIntValue(), DL, VT); | ||
RKSimon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (X86ISD::SUB == N->getOpcode()) { | ||
| // With -(C - RHS), fold RHS + (-C) | ||
| MatchGeneric(ISD::ADD, RHS, NegC, true); | ||
| } | ||
| } | ||
|
|
||
| // TODO: Can we drop the ZeroSecondOpOnly limit? This is to guarantee that the | ||
| // EFLAGS result doesn't change. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.