[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
Sun Aug 24 09:59:22 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()) {
----------------
RKSimon wrote:

Use sd_match to simplify the commutation matching?

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


More information about the llvm-commits mailing list