[llvm] [TargetLowering] Fold (a | b) ==/!= b -> (a & ~b) ==/!= 0 when and-not exists (PR #145368)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 24 09:22:37 PDT 2025
================
@@ -4212,6 +4212,53 @@ SDValue TargetLowering::foldSetCCWithAnd(EVT VT, SDValue N0, SDValue N1,
return SDValue();
}
+/// This helper function of SimplifySetCC tries to optimize the comparison when
+/// either operand of the SetCC node is a bitwise-or instruction.
+SDValue TargetLowering::foldSetCCWithOr(EVT VT, SDValue N0, SDValue N1,
+ ISD::CondCode Cond, const SDLoc &DL,
+ DAGCombinerInfo &DCI) const {
+ if (N1.getOpcode() == ISD::OR && N0.getOpcode() != ISD::OR)
+ std::swap(N0, N1);
+
+ SelectionDAG &DAG = DCI.DAG;
+ EVT OpVT = N0.getValueType();
+ if (N0.getOpcode() != ISD::OR || !OpVT.isInteger() ||
+ (Cond != ISD::SETEQ && Cond != ISD::SETNE))
+ return SDValue();
+
+ // Match these patterns in any of their permutations:
+ // (X | Y) == Y
+ // (X | Y) != Y
+ SDValue X, Y;
+ if (N0.getOperand(0) == N1) {
----------------
topperc wrote:
sd_match is relatively new compared to the rest of TargetLowering. It was introduced last year. Just because it isn't used doesn't mean it can't be used.
https://github.com/llvm/llvm-project/pull/145368
More information about the llvm-commits
mailing list