-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[SelectionDAG] fold (not (sub Y, X)) -> (add X, ~Y) #147825
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?
Conversation
@llvm/pr-subscribers-backend-x86 @llvm/pr-subscribers-llvm-selectiondag Author: AZero13 (AZero13) ChangesThis replaces (not (neg x)) -> (add X, -1) because that is covered by this. Full diff: https://github.com/llvm/llvm-project/pull/147825.diff 1 Files Affected:
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 9ffdda28f7899..90c673dd7e83b 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -9979,13 +9979,13 @@ SDValue DAGCombiner::visitXOR(SDNode *N) {
}
}
- // fold (not (neg x)) -> (add X, -1)
- // FIXME: This can be generalized to (not (sub Y, X)) -> (add X, ~Y) if
- // Y is a constant or the subtract has a single use.
- if (isAllOnesConstant(N1) && N0.getOpcode() == ISD::SUB &&
- isNullConstant(N0.getOperand(0))) {
- return DAG.getNode(ISD::ADD, DL, VT, N0.getOperand(1),
- DAG.getAllOnesConstant(DL, VT));
+ // fold (not (sub Y, X)) -> (add X, ~Y) is subtract is a single use
+ // or Y is a constant.
+ if (isAllOnesOrAllOnesSplat(N1) && N0.getOpcode() == ISD::SUB) {
+ ConstantSDNode *Const = dyn_cast<ConstantSDNode>(N0.getOperand(0));
+ if (Const || N0.hasOneUse())
+ return DAG.getNode(ISD::ADD, DL, VT, N0.getOperand(1),
+ DAG.getNOT(DL, N0.getOperand(0), VT));
}
// fold (not (add X, -1)) -> (neg X)
|
ec94756
to
37f723a
Compare
has there been a test for this selectiondag folding after & before the TODO? it would be beneficial to add one if not |
c4736a1
to
a972c3a
Compare
This replaces (not (neg x)) -> (add X, -1) because that is covered by this.
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.
Missing tests. Please never post functional change patches without tests
// fold (not (sub Y, X)) -> (add X, ~Y) if Y is a constant. | ||
// FIXME: We can also do this with single-use sub, but this causes an infinite | ||
// loop | ||
if (isAllOnesConstant(N1) && N0.getOpcode() == ISD::SUB) { |
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.
if (isAllOnesConstant(N1) && N0.getOpcode() == ISD::SUB) { | |
if (N0.getOpcode() == ISD::SUB && isAllOnesConstant(N1)) { |
Stop force pushing patches. I'm tired of repeating this. |
This replaces (not (neg x)) -> (add X, -1) because that is covered by this.