[llvm] [Analysis][AArch64] Add cost model for loop.dependence.{war/raw}.mask (PR #167551)
Sander de Smalen via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 11 05:09:19 PST 2025
================
@@ -2139,6 +2139,53 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
// Otherwise, fallback to default scalarization cost.
break;
}
+ case Intrinsic::loop_dependence_war_mask:
+ case Intrinsic::loop_dependence_raw_mask: {
+ // Compute the cost of the expanded version of these intrinsics:
+ //
+ // The possible expansions are...
+ //
+ // loop_dependence_war_mask:
+ // diff = (ptrB - ptrA) / eltSize
+ // cmp = icmp sle diff, 0
+ // upper_bound = select cmp, -1, diff
+ // mask = get_active_lane_mask lane_offset, upper_bound
+ //
+ // loop_dependence_raw_mask:
+ // diff = (abs(ptrB - ptrA)) / eltSize
+ // cmp = icmp eq diff, 0
+ // upper_bound = select cmp, -1, diff
+ // mask = get_active_lane_mask lane_offset, upper_bound
+ //
+ InstructionCost Cost = 0;
+ Type *PtrTy = ICA.getArgTypes()[0];
+ unsigned EltSizeInBytes =
+ cast<ConstantInt>(ICA.getArgs()[2])->getZExtValue();
+ bool IsReadAfterWrite = IID == Intrinsic::loop_dependence_raw_mask;
+
+ Cost +=
+ thisT()->getArithmeticInstrCost(Instruction::Sub, PtrTy, CostKind);
+ if (IsReadAfterWrite) {
+ IntrinsicCostAttributes AbsAttrs(Intrinsic::abs, PtrTy, {PtrTy}, {});
+ Cost += thisT()->getIntrinsicInstrCost(AbsAttrs, CostKind);
+ }
+ Cost += thisT()->getArithmeticInstrCost(
+ isPowerOf2_32(EltSizeInBytes) ? Instruction::AShr : Instruction::SDiv,
----------------
sdesmalen-arm wrote:
This looks like something that can be moved to `BasicTTIImpl::getArithmeticInstrCost`, because `OperandValueInfo` has a `isPowerOf2()` method.
https://github.com/llvm/llvm-project/pull/167551
More information about the llvm-commits
mailing list