[llvm] Optimized Constant Xor And And Not Operation (PR #161784)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 9 23:49:52 PDT 2025
================
@@ -1262,6 +1262,41 @@ SDValue DAGCombiner::reassociateOpsCommutative(unsigned Opc, const SDLoc &DL,
if (N1 == N00 || N1 == N01)
return N0;
}
+
+ // Optimize (Constant XOR a) & b & ~c -> (Constant XOR a) & (b & ~c)
+ // This allows the andn operation to be done in parallel with the xor
+ if (Opc == ISD::AND && TLI.hasAndNot(N1)) {
+ // Look for pattern: AND(AND(XOR(Constant, a), b), NOT(c))
+ // Transform to: AND(XOR(Constant, a), AND(b, NOT(c)))
+
+ // Check if N1 is NOT(c) - i.e., XOR(c, -1)
+ if (N1.getOpcode() == ISD::XOR &&
+ DAG.isConstantIntBuildVectorOrConstantInt(N1.getOperand(1)) &&
+ isAllOnesConstant(N1.getOperand(1))) {
----------------
arsenm wrote:
This would probably be cleaner using sd_match. And you can fuse with the above condition into one if?
https://github.com/llvm/llvm-project/pull/161784
More information about the llvm-commits
mailing list