[llvm] [DAGCombiner] Add sra-xor-sra pattern fold (PR #166777)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 7 01:10:59 PST 2025


================
@@ -10987,6 +10968,25 @@ SDValue DAGCombiner::visitSRA(SDNode *N) {
     }
   }
 
+  // fold (sra (xor (sra x, c1), -1), c2) -> (xor (sra x, c3), -1)
+  // This allows merging two arithmetic shifts even when there's a NOT in
+  // between.
+  SDValue X;
+  APInt C1;
+  if (sd_match(N0,
+               m_OneUse(m_Not(m_OneUse(m_Sra(m_Value(X), m_ConstInt(C1)))))) &&
+      N1C) {
+    APInt C2 = N1C->getAPIntValue();
----------------
RKSimon wrote:

zeroExtendToMatch will alter both C1 and C2 - it can't be a const ref

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


More information about the llvm-commits mailing list