[llvm] [InstCombine] Fold (X ^ (or disjoint Y, C1)) ^ C2 to (X ^ Y) ^ (C1 ^ C2) (PR #191638)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 11 21:45:58 PDT 2026
================
@@ -5440,6 +5440,12 @@ Instruction *InstCombinerImpl::visitXor(BinaryOperator &I) {
MaskedValueIsZero(X, *C, &I))
return BinaryOperator::CreateXor(X, ConstantInt::get(Ty, *C ^ *RHSC));
+ // (X ^ (or disjoint Y, C1)) ^ C2 --> (X ^ Y) ^ (C1 ^ C2)
----------------
Jinlock9 wrote:
Thanks for the catch! The base case `(X ^ (Y ^ C)) ^ RHSC` is already handled in two steps: first, the constant-hoisting at the bottom of `visitXor` rewrites `(X ^ C) ^ Y → (X ^ Y) ^ C`, and then `SimplifyAssociativeOrCommutative` folds `((X ^ Y) ^ C1) ^ C2 → (X ^ Y) ^ (C1 ^ C2)`.
I missed this in the initial patch and added a one-off fold. Revised to extend the existing hoist to also match `m_DisjointOr`, so it feeds into the same infrastructure.
https://github.com/llvm/llvm-project/pull/191638
More information about the llvm-commits
mailing list