[llvm] [InstCombine] Fold icmp (zext X), (and (trunc Y), Mask) -> icmp X, trunc Y (PR #221189)

armandeep singh via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 15 12:02:07 PDT 2026


================
@@ -5327,6 +5328,36 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I,
 
   Value *X;
 
+  // Catch the mirrored operand order: icmp Pred (and (trunc Y), Mask), (zext
+  // X). Canonicalization (like ugt -> ult) often swaps operands, pushing the
+  // zext to Operand 1. We need to handle this to avoid missing optimizations.
+  {
+    Value *X, *Y;
+    const APInt *Mask;
+
+    // Ensure we have an unsigned compare with a zext on the right side.
+    // Then look for our one use AND with a mask on the left.
+    if (match(I.getOperand(1), m_ZExt(m_Value(X))) && !I.isSigned() &&
----------------
armandeep23947 wrote:

good catch, reordered

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


More information about the llvm-commits mailing list