[llvm] [SLP]Consider (f)sub, being operand of llvm.(f)abs/icmp eq/ne 0, commutative. (PR #86196)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 22 10:16:17 PDT 2024
================
@@ -305,7 +305,32 @@ static bool isCommutative(Instruction *I) {
if (auto *Cmp = dyn_cast<CmpInst>(I))
return Cmp->isCommutative();
if (auto *BO = dyn_cast<BinaryOperator>(I))
- return BO->isCommutative();
+ return BO->isCommutative() ||
+ (BO->getOpcode() == Instruction::Sub &&
+ !BO->hasNUsesOrMore(UsesLimit) &&
+ all_of(BO->uses(),
+ [](const Use &U) {
+ // Commutative, if icmp eq/ne sub, 0
+ ICmpInst::Predicate Pred;
+ if (match(U.getUser(),
+ m_ICmp(Pred, m_Specific(U.get()), m_Zero())) &&
+ (Pred == ICmpInst::ICMP_EQ ||
+ Pred == ICmpInst::ICMP_NE))
+ return true;
+ // Commutative, if abs(sub, flag).
+ if (U.getOperandNo() != 0)
+ return false;
+ const auto *IC = dyn_cast<IntrinsicInst>(U.getUser());
+ return IC && IC->getIntrinsicID() == Intrinsic::abs;
+ })) ||
+ (BO->getOpcode() == Instruction::FSub &&
+ !BO->hasNUsesOrMore(UsesLimit) &&
+ all_of(BO->uses(), [](const Use &U) {
+ if (U.getOperandNo() != 0)
+ return false;
+ const auto *IC = dyn_cast<IntrinsicInst>(U.getUser());
+ return IC && IC->getIntrinsicID() == Intrinsic::fabs;
+ }));
----------------
RKSimon wrote:
OK.
https://github.com/llvm/llvm-project/pull/86196
More information about the llvm-commits
mailing list