[llvm] [AArch64][InstCombine] xor(cmpne) -> cmpeq (PR #207007)
Paul Walker via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 2 05:32:09 PDT 2026
================
@@ -2142,10 +2142,43 @@ 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 = cast<Instruction>(*II.user_begin());
+ if (!match(User, m_c_Xor(m_Specific(&II), m_Specific(II.getOperand(0)))))
+ return std::nullopt;
+
+ 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;
+ }
+
+ IC.Builder.SetInsertPoint(User);
+ Value *CMPEQ = IC.Builder.CreateIntrinsic(
+ IID, II.getOperand(1)->getType(),
+ {II.getOperand(0), II.getOperand(1), II.getOperand(2)});
+ IC.replaceInstUsesWith(*User, CMPEQ);
+ IC.eraseInstFromFunction(*User);
+ return &II;
+}
+
static std::optional<Instruction *> instCombineSVECmpNE(InstCombiner &IC,
IntrinsicInst &II) {
LLVMContext &Ctx = II.getContext();
+ if (auto Res = instCombineXorSVECmpNE(IC, II))
+ return *Res;
----------------
paulwalker-arm wrote:
```suggestion
return Res;
```
Not 100% sure but I figure instCombineSVECmpNE and instCombineXorSVECmpNE have the same return type so there is no need to unwrap and rewrap the optional.
https://github.com/llvm/llvm-project/pull/207007
More information about the llvm-commits
mailing list