diff options
author | Mikael Holmen <mikael.holmen@ericsson.com> | 2017-10-05 07:07:09 +0000 |
---|---|---|
committer | Mikael Holmen <mikael.holmen@ericsson.com> | 2017-10-05 07:07:09 +0000 |
commit | 0ec1d25d3322064fdcd458c5e8e8342d4809952c (patch) | |
tree | 16a05280533232736c0ed0e13682bc542af21b87 /llvm/lib/IR/Instructions.cpp | |
parent | 8dcba551d940b58d4f40e481fe0e517089487088 (diff) | |
download | bcm5719-llvm-0ec1d25d3322064fdcd458c5e8e8342d4809952c.tar.gz bcm5719-llvm-0ec1d25d3322064fdcd458c5e8e8342d4809952c.zip |
Minor refactoring regarding Cast::isNoopCast(), NFC
Summary:
FastISel::hasTrivialKill() was the only user of the "IntPtrTy" version of
Cast::isNoopCast(). According to review comments in D37894 we could instead
use the "DataLayout" version of the method, and thus get rid of the
"IntPtrTy" versions of isNoopCast() completely.
With the above done, the remaining isNoopCast() could then be simplified
a bit more.
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: wdng, llvm-commits
Differential Revision: https://reviews.llvm.org/D38497
llvm-svn: 314969
Diffstat (limited to 'llvm/lib/IR/Instructions.cpp')
-rw-r--r-- | llvm/lib/IR/Instructions.cpp | 28 |
1 files changed, 3 insertions, 25 deletions
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index d6297cb6cae..55c8ab6d5fd 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -2299,7 +2299,7 @@ bool CastInst::isLosslessCast() const { bool CastInst::isNoopCast(Instruction::CastOps Opcode, Type *SrcTy, Type *DestTy, - Type *IntPtrTy) { + const DataLayout &DL) { switch (Opcode) { default: llvm_unreachable("Invalid CastOp"); case Instruction::Trunc: @@ -2317,36 +2317,14 @@ bool CastInst::isNoopCast(Instruction::CastOps Opcode, case Instruction::BitCast: return true; // BitCast never modifies bits. case Instruction::PtrToInt: - return IntPtrTy->getScalarSizeInBits() == + return DL.getIntPtrType(SrcTy)->getScalarSizeInBits() == DestTy->getScalarSizeInBits(); case Instruction::IntToPtr: - return IntPtrTy->getScalarSizeInBits() == + return DL.getIntPtrType(DestTy)->getScalarSizeInBits() == SrcTy->getScalarSizeInBits(); } } -/// @brief Determine if a cast is a no-op. -bool CastInst::isNoopCast(Instruction::CastOps Opcode, - Type *SrcTy, - Type *DestTy, - const DataLayout &DL) { - Type *PtrOpTy = nullptr; - if (Opcode == Instruction::PtrToInt) - PtrOpTy = SrcTy; - else if (Opcode == Instruction::IntToPtr) - PtrOpTy = DestTy; - - Type *IntPtrTy = PtrOpTy ? DL.getIntPtrType(PtrOpTy) : - DL.getIntPtrType(SrcTy->getContext(), 0); - - return isNoopCast(Opcode, SrcTy, DestTy, IntPtrTy); -} - -/// @brief Determine if a cast is a no-op. -bool CastInst::isNoopCast(Type *IntPtrTy) const { - return isNoopCast(getOpcode(), getOperand(0)->getType(), getType(), IntPtrTy); -} - bool CastInst::isNoopCast(const DataLayout &DL) const { return isNoopCast(getOpcode(), getOperand(0)->getType(), getType(), DL); } |