/// Return true if the hardware has a fast square-root instruction.
bool haveFastSqrt(Type *Ty) const;
+ /// Return true if the cost of the instruction is too high to speculatively
+ /// execute and should be kept behind a branch.
+ /// This normally just wraps around a getInstructionCost() call, but some
+ /// targets might report a low TCK_SizeAndLatency value that is incompatible
+ /// with the fixed TCC_Expensive value.
+ /// NOTE: This assumes the instruction passes isSafeToSpeculativelyExecute().
+ bool isExpensiveToSpeculativelyExecute(const Instruction *I) const;
+
/// Return true if it is faster to check if a floating-point value is NaN
/// (or not-NaN) versus a comparison against a constant FP zero value.
/// Targets should override this if materializing a 0.0 for comparison is
bool *Fast) = 0;
virtual PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) = 0;
virtual bool haveFastSqrt(Type *Ty) = 0;
+ virtual bool isExpensiveToSpeculativelyExecute(const Instruction *I) = 0;
virtual bool isFCmpOrdCheaperThanFCmpZero(Type *Ty) = 0;
virtual InstructionCost getFPOpCost(Type *Ty) = 0;
virtual InstructionCost getIntImmCodeSizeCost(unsigned Opc, unsigned Idx,
}
bool haveFastSqrt(Type *Ty) override { return Impl.haveFastSqrt(Ty); }
+ bool isExpensiveToSpeculativelyExecute(const Instruction* I) override {
+ return Impl.isExpensiveToSpeculativelyExecute(I);
+ }
+
bool isFCmpOrdCheaperThanFCmpZero(Type *Ty) override {
return Impl.isFCmpOrdCheaperThanFCmpZero(Ty);
}
bool haveFastSqrt(Type *Ty) const { return false; }
+ bool isExpensiveToSpeculativelyExecute(const Instruction *I) { return true; }
+
bool isFCmpOrdCheaperThanFCmpZero(Type *Ty) const { return true; }
InstructionCost getFPOpCost(Type *Ty) const {
// don't know the throughput cost.
return CostKind == TTI::TCK_RecipThroughput ? -1 : TTI::TCC_Basic;
}
+
+ bool isExpensiveToSpeculativelyExecute(const Instruction *I) {
+ auto *TargetTTI = static_cast<T *>(this);
+ SmallVector<const Value *, 4> Ops(I->operand_values());
+ InstructionCost Cost = TargetTTI->getInstructionCost(
+ I, Ops, TargetTransformInfo::TCK_SizeAndLatency);
+ return Cost >= TargetTransformInfo::TCC_Expensive;
+ }
};
} // namespace llvm
return TTIImpl->haveFastSqrt(Ty);
}
+bool TargetTransformInfo::isExpensiveToSpeculativelyExecute(
+ const Instruction *I) const {
+ return TTIImpl->isExpensiveToSpeculativelyExecute(I);
+}
+
bool TargetTransformInfo::isFCmpOrdCheaperThanFCmpZero(Type *Ty) const {
return TTIImpl->isFCmpOrdCheaperThanFCmpZero(Ty);
}
// If it's safe to speculatively execute, then it should not have side
// effects; therefore, it's safe to sink and possibly *not* execute.
return I && I->hasOneUse() && isSafeToSpeculativelyExecute(I) &&
- TTI->getInstructionCost(I, TargetTransformInfo::TCK_SizeAndLatency) >=
- TargetTransformInfo::TCC_Expensive;
+ TTI->isExpensiveToSpeculativelyExecute(I);
}
/// Returns true if a SelectInst should be turned into an explicit branch.