[llvm] 56cd6e3 - [NFC][TTI] Use switch in getCastInstrCost
Sam Parker via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 16 05:52:23 PDT 2020
Author: Sam Parker
Date: 2020-03-16T12:52:08Z
New Revision: 56cd6e356f158c4a38e9f7eac2f23250c2104e93
URL: https://github.com/llvm/llvm-project/commit/56cd6e356f158c4a38e9f7eac2f23250c2104e93
DIFF: https://github.com/llvm/llvm-project/commit/56cd6e356f158c4a38e9f7eac2f23250c2104e93.diff
LOG: [NFC][TTI] Use switch in getCastInstrCost
Introduce a switch statement for trunc, bitcast, addrspacecast and
zext in BasicTTIImpl.
Added:
Modified:
llvm/include/llvm/CodeGen/BasicTTIImpl.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
index f3dd322940d3..3b1658929c34 100644
--- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h
+++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
@@ -704,28 +704,33 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
std::pair<unsigned, MVT> SrcLT = TLI->getTypeLegalizationCost(DL, Src);
std::pair<unsigned, MVT> DstLT = TLI->getTypeLegalizationCost(DL, Dst);
- // Check for NOOP conversions.
- if (SrcLT.first == DstLT.first &&
- SrcLT.second.getSizeInBits() == DstLT.second.getSizeInBits()) {
+ unsigned SrcSize = SrcLT.second.getSizeInBits();
+ unsigned DstSize = DstLT.second.getSizeInBits();
+ switch (Opcode) {
+ default:
+ break;
+ case Instruction::Trunc:
+ // Check for NOOP conversions.
+ 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;
+ break;
+ case Instruction::ZExt:
+ if (TLI->isZExtFree(SrcLT.second, DstLT.second))
+ return 0;
+ break;
+ case Instruction::AddrSpaceCast:
+ if (TLI->isFreeAddrSpaceCast(Src->getPointerAddressSpace(),
+ Dst->getPointerAddressSpace()))
return 0;
+ break;
}
- if (Opcode == Instruction::Trunc &&
- TLI->isTruncateFree(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(),
- Dst->getPointerAddressSpace()))
- return 0;
-
// If this is a zext/sext of a load, return 0 if the corresponding
// extending load exists on target.
if ((Opcode == Instruction::ZExt || Opcode == Instruction::SExt) &&
More information about the llvm-commits
mailing list