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

David Green via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 24 12:20:17 PDT 2025


================
@@ -10086,6 +10086,48 @@ 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 (smin(C, x), C)) -> select (x < C), xor(x, C), 0
+  if (N0.getOpcode() == ISD::SMIN && N0.hasOneUse()) {
+    SDValue Op0 = N0.getOperand(0);
+    SDValue Op1 = N0.getOperand(1);
+
+    if(Op1 != N1) {
+      std::swap(Op0, Op1);
+    }
----------------
davemgreen wrote:

I think I would expect to have already canonicalized the constant to the RHS.

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


More information about the llvm-commits mailing list