[llvm] [DAG] Fold (and X, (add (not Y), Z)) -> (and X, (not (sub Y, Z))). (PR #141476)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 2 08:20:06 PDT 2025


================
@@ -11609,6 +11625,28 @@ SDValue DAGCombiner::foldShiftToAvg(SDNode *N) {
   return DAG.getNode(FloorISD, SDLoc(N), N->getValueType(0), {A, B});
 }
 
+SDValue DAGCombiner::foldBitwiseOpWithNeg(SDNode *N, const SDLoc &DL, EVT VT) {
+  if (!TLI.hasAndNot(SDValue(N, 0)))
----------------
RKSimon wrote:

hasAndNot/hasAndNotCompare were added but nothing else - its not the ideal API for this kind of thing either (only hasAndNotCompare need the SDValue)

(yak shaving) A possible refactor would be to replace hasAndNot with a new `hasBitwiseLogicNot(Opcode, EVT)` variant - along with removing the dependency on hasAndNotCompare

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


More information about the llvm-commits mailing list