[llvm] [InstCombine] Fold `(add X, (sext/zext (icmp eq X, C)))` (PR #93840)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 1 03:07:16 PDT 2024
================
@@ -1694,6 +1694,26 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
return BinaryOperator::CreateOr(LHS, Zext);
}
+ {
+ Value *Cond, *Ext;
+ Constant *C;
+ // (add X, (sext/zext (icmp eq X, C)))
+ // -> (select (icmp eq X, C), (add C, (sext/zext 1)), X)
+ auto CondMatcher = m_CombineAnd(
+ m_Value(Cond), m_ICmp(Pred, m_Deferred(A), m_ImmConstant(C)));
----------------
nikic wrote:
I think it might be a bit more elegant if you match m_Value(Cond) first and then do a second match call on Cond. Especially with this in a separate variable (so that m_Deferred occurs before the corresponding m_Value) I found this confusing.
https://github.com/llvm/llvm-project/pull/93840
More information about the llvm-commits
mailing list