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

Matthew Devereau via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 2 08:05:29 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;
----------------
MDevereau wrote:

Because of the zeroing predicate:

with cmpne(0, 1)->xor(1), if an element is inactive, the resulting element will be 1
with cmpne(1, 1)->xor(1), if an element is inactive, the resulting element will be 1
with cmpne(0, 0)->xor(1) if an element is active, the resulting element will be 1
with cmpne(1, 0)->xor(1) if an element is active, the resulting element will be 0

with cmpeq(0, 1), if an element is inactive, the resulting element will be 0
with cmpeq(1, 1), if an element is inactive, the resulting element will be 0
with cmpeq(0, 0) if an element is active, the resulting element will be 1
with cmpeq(1, 0) if an element is active, the resulting element will be 0

So the combine is only correct when op2 of the cmpne is zero unless I'm missing something? If it was constricted to ptrue then the values wouldn't matter.




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


More information about the llvm-commits mailing list