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/Analysis/Loads.cpp | |
parent | 0160570a0f4f460cf5df5afd1123785aae416fde (diff) | |
download | llvm-1a3c2c414ca7f9cbd54778fca0e333edd3d45b94.zip llvm-1a3c2c414ca7f9cbd54778fca0e333edd3d45b94.tar.gz llvm-1a3c2c414ca7f9cbd54778fca0e333edd3d45b94.tar.bz2 |
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/Analysis/Loads.cpp')
-rw-r--r-- | llvm/lib/Analysis/Loads.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp index bb0d60e..5042eb9 100644 --- a/llvm/lib/Analysis/Loads.cpp +++ b/llvm/lib/Analysis/Loads.cpp @@ -176,8 +176,13 @@ Value *llvm::FindAvailableLoadedValue(Value *Ptr, BasicBlock *ScanBB, Type *AccessTy = cast<PointerType>(Ptr->getType())->getElementType(); - // If we're using alias analysis to disambiguate get the size of *Ptr. - uint64_t AccessSize = AA ? AA->getTypeStoreSize(AccessTy) : 0; + // Try to get the DataLayout for this module. This may be null, in which case + // the optimizations will be limited. + const DataLayout *DL = ScanBB->getDataLayout(); + + // Try to get the store size for the type. + uint64_t AccessSize = DL ? DL->getTypeStoreSize(AccessTy) + : AA ? AA->getTypeStoreSize(AccessTy) : 0; Value *StrippedPtr = Ptr->stripPointerCasts(); @@ -202,7 +207,7 @@ Value *llvm::FindAvailableLoadedValue(Value *Ptr, BasicBlock *ScanBB, if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) if (AreEquivalentAddressValues( LI->getPointerOperand()->stripPointerCasts(), StrippedPtr) && - CastInst::isBitCastable(LI->getType(), AccessTy)) { + CastInst::isBitOrNoopPointerCastable(LI->getType(), AccessTy, DL)) { if (AATags) LI->getAAMetadata(*AATags); return LI; @@ -214,7 +219,8 @@ Value *llvm::FindAvailableLoadedValue(Value *Ptr, BasicBlock *ScanBB, // (This is true even if the store is volatile or atomic, although // those cases are unlikely.) if (AreEquivalentAddressValues(StorePtr, StrippedPtr) && - CastInst::isBitCastable(SI->getValueOperand()->getType(), AccessTy)) { + CastInst::isBitOrNoopPointerCastable(SI->getValueOperand()->getType(), + AccessTy, DL)) { if (AATags) SI->getAAMetadata(*AATags); return SI->getOperand(0); |