Skip to content

Commit 56cd6e3

Browse files
committed
[NFC][TTI] Use switch in getCastInstrCost
Introduce a switch statement for trunc, bitcast, addrspacecast and zext in BasicTTIImpl.
1 parent f4cb9c9 commit 56cd6e3

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -704,28 +704,33 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
704704
std::pair<unsigned, MVT> SrcLT = TLI->getTypeLegalizationCost(DL, Src);
705705
std::pair<unsigned, MVT> DstLT = TLI->getTypeLegalizationCost(DL, Dst);
706706

707-
// Check for NOOP conversions.
708-
if (SrcLT.first == DstLT.first &&
709-
SrcLT.second.getSizeInBits() == DstLT.second.getSizeInBits()) {
707+
unsigned SrcSize = SrcLT.second.getSizeInBits();
708+
unsigned DstSize = DstLT.second.getSizeInBits();
710709

710+
switch (Opcode) {
711+
default:
712+
break;
713+
case Instruction::Trunc:
714+
// Check for NOOP conversions.
715+
if (TLI->isTruncateFree(SrcLT.second, DstLT.second))
716+
return 0;
717+
LLVM_FALLTHROUGH;
718+
case Instruction::BitCast:
711719
// Bitcast between types that are legalized to the same type are free.
712-
if (Opcode == Instruction::BitCast || Opcode == Instruction::Trunc)
720+
if (SrcLT.first == DstLT.first && SrcSize == DstSize)
721+
return 0;
722+
break;
723+
case Instruction::ZExt:
724+
if (TLI->isZExtFree(SrcLT.second, DstLT.second))
725+
return 0;
726+
break;
727+
case Instruction::AddrSpaceCast:
728+
if (TLI->isFreeAddrSpaceCast(Src->getPointerAddressSpace(),
729+
Dst->getPointerAddressSpace()))
713730
return 0;
731+
break;
714732
}
715733

716-
if (Opcode == Instruction::Trunc &&
717-
TLI->isTruncateFree(SrcLT.second, DstLT.second))
718-
return 0;
719-
720-
if (Opcode == Instruction::ZExt &&
721-
TLI->isZExtFree(SrcLT.second, DstLT.second))
722-
return 0;
723-
724-
if (Opcode == Instruction::AddrSpaceCast &&
725-
TLI->isFreeAddrSpaceCast(Src->getPointerAddressSpace(),
726-
Dst->getPointerAddressSpace()))
727-
return 0;
728-
729734
// If this is a zext/sext of a load, return 0 if the corresponding
730735
// extending load exists on target.
731736
if ((Opcode == Instruction::ZExt || Opcode == Instruction::SExt) &&

0 commit comments

Comments
 (0)