[NFC][TTI] Use switch in getCastInstrCost

Introduce a switch statement for trunc, bitcast, addrspacecast and
zext in BasicTTIImpl.
This commit is contained in:
Sam Parker 2020-03-16 12:48:12 +00:00
parent f4cb9c919e
commit 56cd6e356f
1 changed files with 23 additions and 18 deletions

View File

@ -704,27 +704,32 @@ public:
std::pair<unsigned, MVT> SrcLT = TLI->getTypeLegalizationCost(DL, Src);
std::pair<unsigned, MVT> DstLT = TLI->getTypeLegalizationCost(DL, Dst);
unsigned SrcSize = SrcLT.second.getSizeInBits();
unsigned DstSize = DstLT.second.getSizeInBits();
switch (Opcode) {
default:
break;
case Instruction::Trunc:
// Check for NOOP conversions.
if (SrcLT.first == DstLT.first &&
SrcLT.second.getSizeInBits() == DstLT.second.getSizeInBits()) {
if (TLI->isTruncateFree(SrcLT.second, DstLT.second))
return 0;
LLVM_FALLTHROUGH;
case Instruction::BitCast:
// Bitcast between types that are legalized to the same type are free.
if (Opcode == Instruction::BitCast || Opcode == Instruction::Trunc)
if (SrcLT.first == DstLT.first && SrcSize == DstSize)
return 0;
}
if (Opcode == Instruction::Trunc &&
TLI->isTruncateFree(SrcLT.second, DstLT.second))
break;
case Instruction::ZExt:
if (TLI->isZExtFree(SrcLT.second, DstLT.second))
return 0;
if (Opcode == Instruction::ZExt &&
TLI->isZExtFree(SrcLT.second, DstLT.second))
return 0;
if (Opcode == Instruction::AddrSpaceCast &&
TLI->isFreeAddrSpaceCast(Src->getPointerAddressSpace(),
break;
case Instruction::AddrSpaceCast:
if (TLI->isFreeAddrSpaceCast(Src->getPointerAddressSpace(),
Dst->getPointerAddressSpace()))
return 0;
break;
}
// If this is a zext/sext of a load, return 0 if the corresponding
// extending load exists on target.