[llvm] [DAG] Generalize fold (not (neg x)) -> (add X, -1) (PR #154348)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 4 01:21:37 PDT 2025


================
@@ -9988,13 +9988,26 @@ 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) if Y is a constant or the subtract has
+  // a single use.
----------------
jayfoad wrote:

Should this be:
```suggestion
  // fold (not (sub Y, X)) -> (add X, ~Y) if Y is a constant and the subtract has
  // a single use.
```
?

https://github.com/llvm/llvm-project/pull/154348


More information about the llvm-commits mailing list