[llvm] [InstCombine] Fold xor(zext(or disjoint X, C1), C2) (PR #214970)
Andreas Jonson via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 8 09:56:24 PDT 2026
=?utf-8?b?7KGw7JiB7KeEKEpveW91bmdqaW4p?Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/214970 at github.com>
================
@@ -1775,6 +1775,27 @@ static Instruction *foldLogicCastConstant(BinaryOperator &Logic, CastInst *Cast,
Type *DestTy = Logic.getType();
Type *SrcTy = Cast->getSrcTy();
+ // xor (zext (or disjoint X, NarrowC)), WideC
+ // -> xor (zext X), WideC ^ zext(NarrowC)
+ if (LogicOpc == Instruction::Xor && SrcTy->isIntegerTy() &&
+ DestTy->isIntegerTy()) {
+ Value *X;
+ ConstantInt *NarrowC, *WideC;
+
+ if (match(C, m_ConstantInt(WideC)) &&
+ match(Cast,
+ m_OneUse(m_ZExt(m_OneUse(
+ m_c_DisjointOr(m_Value(X), m_ConstantInt(NarrowC))))))) {
----------------
andjo403 wrote:
no need to use the m_c_DisjointOr as constants is swaped to be on the right before his fold
and if m_APInt is used instead this also works for splat vectors so then there is no need to check the types as zext must be integer or vector integers
```suggestion
m_DisjointOr(m_Value(X), m_APInt(NarrowC))))))) {
```
https://github.com/llvm/llvm-project/pull/214970
More information about the llvm-commits
mailing list