Skip to content

Commit

Permalink
[CostModel][TTI] Replace BAD_ICMP_PREDICATE with ICMP_SGT for generic…
Browse files Browse the repository at this point in the history
… sadd/ssub sat cost expansion

The comparison always checks for negative values so know the icmp predicate will be ICMP_SGT
  • Loading branch information
RKSimon committed Oct 7, 2021
1 parent 5197520 commit 7168837
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 90 deletions.
11 changes: 5 additions & 6 deletions llvm/include/llvm/CodeGen/BasicTTIImpl.h
Expand Up @@ -1724,19 +1724,18 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
Intrinsic::ID OverflowOp = IID == Intrinsic::sadd_sat
? Intrinsic::sadd_with_overflow
: Intrinsic::ssub_with_overflow;
CmpInst::Predicate Pred = CmpInst::ICMP_SGT;

// SatMax -> Overflow && SumDiff < 0
// SatMin -> Overflow && SumDiff >= 0
InstructionCost Cost = 0;
IntrinsicCostAttributes Attrs(OverflowOp, OpTy, {RetTy, RetTy}, FMF,
nullptr, ScalarizationCostPassed);
Cost += thisT()->getIntrinsicInstrCost(Attrs, CostKind);
Cost +=
thisT()->getCmpSelInstrCost(BinaryOperator::ICmp, RetTy, CondTy,
CmpInst::BAD_ICMP_PREDICATE, CostKind);
Cost += 2 * thisT()->getCmpSelInstrCost(
BinaryOperator::Select, RetTy, CondTy,
CmpInst::BAD_ICMP_PREDICATE, CostKind);
Cost += thisT()->getCmpSelInstrCost(BinaryOperator::ICmp, RetTy, CondTy,
Pred, CostKind);
Cost += 2 * thisT()->getCmpSelInstrCost(BinaryOperator::Select, RetTy,
CondTy, Pred, CostKind);
return Cost;
}
case Intrinsic::uadd_sat:
Expand Down

0 comments on commit 7168837

Please sign in to comment.