[llvm] [AArch64][InstCombine] xor(cmpne) -> cmpeq (PR #207007)

Paul Walker via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 2 03:35:25 PDT 2026


================
@@ -2142,10 +2142,45 @@ static std::optional<Instruction *> instCombineSVEDupX(InstCombiner &IC,
   return IC.replaceInstUsesWith(II, Splat);
 }
 
+static std::optional<Instruction *> instCombineXorSVECmpNE(InstCombiner &IC,
+                                                           IntrinsicInst &II) {
+  if (!match(II.getOperand(2), m_Zero()) || !II.hasOneUse())
+    return std::nullopt;
+
+  auto *User = dyn_cast<Instruction>(*II.user_begin());
+  if (!User ||
+      (!match(User, m_Xor(m_Specific(&II), m_Specific(II.getOperand(0)))) &&
+       !match(User, m_Xor(m_Specific(II.getOperand(0)), m_Specific(&II)))))
+    return std::nullopt;
+
+  IC.Builder.SetInsertPoint(User);
+  Intrinsic::ID IID;
+  switch ((II.getIntrinsicID())) {
+  case Intrinsic::aarch64_sve_cmpne:
+    IID = Intrinsic::aarch64_sve_cmpeq;
+    break;
+  case Intrinsic::aarch64_sve_cmpne_wide:
+    IID = Intrinsic::aarch64_sve_cmpeq_wide;
+    break;
+  default:
+    return std::nullopt;
+  }
+
+  Value *CMPEQ = IC.Builder.CreateIntrinsic(
+      IID, II.getOperand(1)->getType(),
+      {II.getOperand(0), II.getOperand(1), II.getOperand(2)});
+  CMPEQ->takeName(User);
+  IC.replaceInstUsesWith(*User, CMPEQ);
+  return IC.eraseInstFromFunction(*User);
----------------
paulwalker-arm wrote:

On second thoughts I think you want to return `II` here and then Instcombine will take care of it for you.

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


More information about the llvm-commits mailing list