diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2014-11-25 08:20:27 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2014-11-25 08:20:27 +0000 |
commit | 1a3c2c414ca7f9cbd54778fca0e333edd3d45b94 (patch) | |
tree | b5801745e7ee7fe74051461c39233101c71ea861 /llvm/lib/IR/Instructions.cpp | |
parent | 0160570a0f4f460cf5df5afd1123785aae416fde (diff) | |
download | bcm5719-llvm-1a3c2c414ca7f9cbd54778fca0e333edd3d45b94.tar.gz bcm5719-llvm-1a3c2c414ca7f9cbd54778fca0e333edd3d45b94.zip |
Revert r220349 to re-instate r220277 with a fix for PR21330 -- quite
clearly only exactly equal width ptrtoint and inttoptr casts are no-op
casts, it says so right there in the langref. Make the code agree.
Original log from r220277:
Teach the load analysis to allow finding available values which require
inttoptr or ptrtoint cast provided there is datalayout available.
Eventually, the datalayout can just be required but in practice it will
always be there today.
To go with the ability to expose available values requiring a ptrtoint
or inttoptr cast, helpers are added to perform one of these three casts.
These smarts are necessary to finish canonicalizing loads and stores to
the operational type requirements without regressing fundamental
combines.
I've added some test cases. These should actually improve as the load
combining and store combining improves, but they may fundamentally be
highlighting some missing combines for select in addition to exercising
the specific added logic to load analysis.
llvm-svn: 222739
Diffstat (limited to 'llvm/lib/IR/Instructions.cpp')
-rw-r--r-- | llvm/lib/IR/Instructions.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index 57a4f0b61dd..f4c6a289b80 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -2559,6 +2559,17 @@ CastInst *CastInst::CreatePointerBitCastOrAddrSpaceCast( return Create(Instruction::BitCast, S, Ty, Name, InsertBefore); } +CastInst *CastInst::CreateBitOrPointerCast(Value *S, Type *Ty, + const Twine &Name, + Instruction *InsertBefore) { + if (S->getType()->isPointerTy() && Ty->isIntegerTy()) + return Create(Instruction::PtrToInt, S, Ty, Name, InsertBefore); + if (S->getType()->isIntegerTy() && Ty->isPointerTy()) + return Create(Instruction::IntToPtr, S, Ty, Name, InsertBefore); + + return Create(Instruction::BitCast, S, Ty, Name, InsertBefore); +} + CastInst *CastInst::CreateIntegerCast(Value *C, Type *Ty, bool isSigned, const Twine &Name, Instruction *InsertBefore) { @@ -2716,6 +2727,18 @@ bool CastInst::isBitCastable(Type *SrcTy, Type *DestTy) { return true; } +bool CastInst::isBitOrNoopPointerCastable(Type *SrcTy, Type *DestTy, + const DataLayout *DL) { + if (auto *PtrTy = dyn_cast<PointerType>(SrcTy)) + if (auto *IntTy = dyn_cast<IntegerType>(DestTy)) + return DL && IntTy->getBitWidth() == DL->getPointerTypeSizeInBits(PtrTy); + if (auto *PtrTy = dyn_cast<PointerType>(DestTy)) + if (auto *IntTy = dyn_cast<IntegerType>(SrcTy)) + return DL && IntTy->getBitWidth() == DL->getPointerTypeSizeInBits(PtrTy); + + return isBitCastable(SrcTy, DestTy); +} + // Provide a way to get a "cast" where the cast opcode is inferred from the // types and size of the operand. This, basically, is a parallel of the // logic in the castIsValid function below. This axiom should hold: |