[llvm] [InstCombine] Fold (sub (xor X, (sext C)), (sext C)) => (select C (neg X), X) (PR #79417)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 26 07:57:59 PST 2024
================
@@ -2448,6 +2448,21 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator &I) {
}
}
+ {
+ // (sub (xor X, (sext C)), (sext C)) => (select C, (neg X), X)
+ // (sub (sext C), (xor X, (sext C))) => (select C, X, (neg X))
+ Value *C, *X;
+ auto m_SubXorCmp = [&C, &X](Value *LHS, Value *RHS) {
+ return match(LHS, m_c_Xor(m_Value(X), m_SExt(m_OneUse(m_Value(C))))) &&
----------------
RKSimon wrote:
What is the purpose of the m_OneUse?
Could the patterns be better matched as?
```cpp
return match(LHS, m_c_Xor(m_Value(X), m_Specific(RHS))) &&
match(RHS, m_SExt(m_Specific(C)) &&
(C->getType()->getScalarSizeInBits() == 1);
```
https://github.com/llvm/llvm-project/pull/79417
More information about the llvm-commits
mailing list