[llvm] [AArch64][InstCombine] Fold zext of all-active SVE cmpne-zero (PR #207720)

Paul Walker via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 9 07:10:31 PDT 2026


================
@@ -2174,31 +2174,32 @@ static std::optional<Instruction *> instCombineXorSVECmpNE(InstCombiner &IC,
 }
 
 // zext(cmpne(ptrue, %v, 0))
-// -> umin(ptrue, %v, 1)
+// -> umin(%pg, %v, 1)
 static std::optional<Instruction *> instCombineZExtSVECmpNE(InstCombiner &IC,
                                                             IntrinsicInst &II) {
-  if (!isAllActivePredicate(II.getOperand(0)) || !II.hasOneUse())
+  if (!isAllActivePredicate(II.getOperand(0)) ||
+      !match(II.getOperand(2), m_Zero()))
     return std::nullopt;
 
-  Value *Zero = II.getOperand(1);
-  Value *Op = II.getOperand(2);
-  if (!match(Zero, m_Zero())) {
-    std::swap(Zero, Op);
-    if (!match(Zero, m_Zero()))
-      return std::nullopt;
+  bool Changed = false;
+  for (auto *U : II.users()) {
+    if (match(U, m_ZExt(m_Specific(&II)))) {
+      auto *User = cast<Instruction>(U);
+      Type *Ty = II.getOperand(1)->getType();
+      if (User->getType() != Ty)
+        continue;
+      IC.Builder.SetInsertPoint(User);
+      Value *UMin = IC.Builder.CreateIntrinsic(
+          Intrinsic::aarch64_sve_umin, Ty,
+          {II.getOperand(0), II.getOperand(1), ConstantInt::get(Ty, 1)});
+      IC.replaceInstUsesWith(*User, UMin);
+      IC.eraseInstFromFunction(*User);
+      Changed = true;
+    } else
+      continue;
----------------
paulwalker-arm wrote:

I mean, really? :)

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


More information about the llvm-commits mailing list