[llvm-branch-commits] [llvm] [LoongArch][DAGCombiner] Combine vxor (vand ..) to vandn (PR #161037)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Sep 29 01:27:31 PDT 2025


================
@@ -4939,6 +4939,86 @@ void LoongArchTargetLowering::ReplaceNodeResults(
   }
 }
 
+// Helper to attempt to return a cheaper, bit-inverted version of \p V.
+static SDValue isNOT(SDValue V, SelectionDAG &DAG) {
+  // TODO: don't always ignore oneuse constraints.
+  V = peekThroughBitcasts(V);
+  EVT VT = V.getValueType();
+
+  // Match not(xor X, -1) -> X.
+  if (V.getOpcode() == ISD::XOR &&
+      (ISD::isBuildVectorAllOnes(V.getOperand(1).getNode()) ||
+       isAllOnesConstant(V.getOperand(1))))
+    return V.getOperand(0);
+
+  // Match not(extract_subvector(not(X)) -> extract_subvector(X).
+  if (V.getOpcode() == ISD::EXTRACT_SUBVECTOR &&
+      (isNullConstant(V.getOperand(1)) || V.getOperand(0).hasOneUse())) {
----------------
heiher wrote:

Could you add a test to cover this case?

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


More information about the llvm-branch-commits mailing list