[llvm] [DAGCombiner] add fold (xor (smin(x, C), C)) and fold (xor (smax(x, C), C)) (PR #155141)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 4 05:04:19 PDT 2025


================
@@ -10086,6 +10086,50 @@ SDValue DAGCombiner::visitXOR(SDNode *N) {
   if (SDValue Combined = combineCarryDiamond(DAG, TLI, N0, N1, N))
     return Combined;
 
+  // fold (xor (smin(x, C), C)) -> select (x < C), xor(x, C), 0
+  // fold (xor (smax(x, C), C)) -> select (x > C), xor(x, C), 0
+  // fold (xor (umin(x, C), C)) -> select (x < C), xor(x, C), 0
+  // fold (xor (umax(x, C), C)) -> select (x > C), xor(x, C), 0
+  SDValue Op0;
+  if ((sd_match(N0, m_OneUse(m_AnyOf(m_SMin(m_Value(Op0), m_Specific(N1)),
+                                     m_SMax(m_Value(Op0), m_Specific(N1)),
+                                     m_UMin(m_Value(Op0), m_Specific(N1)),
+                                     m_UMax(m_Value(Op0), m_Specific(N1))))))) {
----------------
RKSimon wrote:

remove outermost ()

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


More information about the llvm-commits mailing list