+/// IsPromotionProfitable - Check whether or not promoting an instruction
+/// to a wider type was profitable.
+/// \p MatchedSize gives the number of instructions that have been matched
+/// in the addressing mode after the promotion was applied.
+/// \p SizeWithPromotion gives the number of created instructions for
+/// the promotion plus the number of instructions that have been
+/// matched in the addressing mode before the promotion.
+/// \p PromotedOperand is the value that has been promoted.
+/// \return True if the promotion is profitable, false otherwise.
+bool
+AddressingModeMatcher::IsPromotionProfitable(unsigned MatchedSize,
+ unsigned SizeWithPromotion,
+ Value *PromotedOperand) const {
+ // We folded less instructions than what we created to promote the operand.
+ // This is not profitable.
+ if (MatchedSize < SizeWithPromotion)
+ return false;
+ if (MatchedSize > SizeWithPromotion)
+ return true;
+ // The promotion is neutral but it may help folding the sign extension in
+ // loads for instance.
+ // Check that we did not create an illegal instruction.
+ Instruction *PromotedInst = dyn_cast<Instruction>(PromotedOperand);
+ if (!PromotedInst)
+ return false;
+ return TLI.isOperationLegalOrCustom(PromotedInst->getOpcode(),
+ EVT::getEVT(PromotedInst->getType()));
+}
+