[llvm-branch-commits] [llvm] [AArch64][TTI] Cost NEON Nots absorbed by And/Or users as free (PR #232788)
Florian Hahn via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Oct 20 02:14:15 PDT 2026
================
@@ -5123,14 +5123,26 @@ InstructionCost AArch64TTIImpl::getArithmeticInstrCost(
if (!is_contained({ISD::ADD, ISD::SUB, ISD::MUL}, ISD))
return InstructionCost::getInvalid();
- if (CtxI && CtxI->getOpcode() == Opcode && CtxI->hasOneUse() &&
+ if (CtxI && CtxI->getOpcode() == Opcode && !CtxI->use_empty() &&
useNeonVector(Ty)) {
// The Ands of a bit select are folded into the BSL that the Or becomes.
Instruction *MainAnd, *OtherAnd;
Value *A, *B;
- if (Opcode == Instruction::And &&
+ if (Opcode == Instruction::And && CtxI->hasOneUse() &&
matchBSL(CtxI->user_back(), MainAnd, OtherAnd, A, B))
return 0;
+
+ // A Not is folded into the BIC, ORN or BSL of each And/Or using it, unless
+ // that And/Or negates both of its operands.
+ if (match(CtxI, m_Not(m_Value())) &&
+ all_of(CtxI->users(), [&](const User *U) {
----------------
fhahn wrote:
If we want to use those hooks more widely (e.g. inliner https://github.com/llvm/llvm-project/pull/232397), it may be a good idea to cap the user walks to limit compile-time increase
https://github.com/llvm/llvm-project/pull/232788
More information about the llvm-branch-commits
mailing list