summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Analysis/Loads.cpp43
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp24
2 files changed, 17 insertions, 50 deletions
diff --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp
index 1a2f8e76c87..309a1d95efb 100644
--- a/llvm/lib/Analysis/Loads.cpp
+++ b/llvm/lib/Analysis/Loads.cpp
@@ -297,17 +297,27 @@ llvm::DefMaxInstsToScan("available-load-scan-limit", cl::init(6), cl::Hidden,
"to scan backward from a given instruction, when searching for "
"available loaded value"));
-
-Value *llvm::FindAvailableLoadedValue(Value *Ptr, Type *AccessTy,
- bool IsAtomicMemOp, BasicBlock *ScanBB,
+Value *llvm::FindAvailableLoadedValue(LoadInst *Load, BasicBlock *ScanBB,
BasicBlock::iterator &ScanFrom,
unsigned MaxInstsToScan,
AliasAnalysis *AA, AAMDNodes *AATags,
bool *IsLoadCSE) {
-
if (MaxInstsToScan == 0)
MaxInstsToScan = ~0U;
+
+ Value *Ptr = Load->getPointerOperand();
+ Type *AccessTy = Load->getType();
+
+ // We can never remove a volatile load
+ if (Load->isVolatile())
+ return nullptr;
+
+ // Anything stronger than unordered is currently unimplemented.
+ if (!Load->isUnordered())
+ return nullptr;
+
const DataLayout &DL = ScanBB->getModule()->getDataLayout();
+
// Try to get the store size for the type.
uint64_t AccessSize = DL.getTypeStoreSize(AccessTy);
@@ -338,7 +348,7 @@ Value *llvm::FindAvailableLoadedValue(Value *Ptr, Type *AccessTy,
// We can value forward from an atomic to a non-atomic, but not the
// other way around.
- if (LI->isAtomic() < IsAtomicMemOp)
+ if (LI->isAtomic() < Load->isAtomic())
return nullptr;
if (AATags)
@@ -359,7 +369,7 @@ Value *llvm::FindAvailableLoadedValue(Value *Ptr, Type *AccessTy,
// We can value forward from an atomic to a non-atomic, but not the
// other way around.
- if (SI->isAtomic() < IsAtomicMemOp)
+ if (SI->isAtomic() < Load->isAtomic())
return nullptr;
if (AATags)
@@ -403,24 +413,3 @@ Value *llvm::FindAvailableLoadedValue(Value *Ptr, Type *AccessTy,
// block.
return nullptr;
}
-
-
-Value *llvm::FindAvailableLoadedValue(LoadInst *Load, BasicBlock *ScanBB,
- BasicBlock::iterator &ScanFrom,
- unsigned MaxInstsToScan,
- AliasAnalysis *AA, AAMDNodes *AATags,
- bool *IsLoadCSE) {
-
- // We can never remove a volatile load
- if (Load->isVolatile())
- return nullptr;
-
- // Anything stronger than unordered is currently unimplemented.
- if (!Load->isUnordered())
- return nullptr;
-
- // Return the full value of the load if available.
- return FindAvailableLoadedValue(Load->getPointerOperand(), Load->getType(),
- Load->isAtomic(), ScanBB, ScanFrom,
- MaxInstsToScan, AA, AATags, IsLoadCSE);
-}
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index 395e83661d5..20556157188 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -13,10 +13,9 @@
#include "InstCombineInternal.h"
#include "llvm/Analysis/ConstantFolding.h"
-#include "llvm/Analysis/Loads.h"
-#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/PatternMatch.h"
+#include "llvm/Analysis/TargetLibraryInfo.h"
using namespace llvm;
using namespace PatternMatch;
@@ -576,27 +575,6 @@ Instruction *InstCombiner::visitTrunc(TruncInst &CI) {
if (Instruction *I = foldVecTruncToExtElt(CI, *this, DL))
return I;
- // When trunc operand is a widened load, see if we can get the value from a
- // previous store/load
- if (auto *LI = dyn_cast<LoadInst>(Src)) {
- BasicBlock::iterator BBI(*LI);
-
- // Scan a few instructions up from LI and if we find a partial load/store
- // of Type DestTy that feeds into LI, we can replace all uses of the trunc
- // with the load/store value.
- // This replacement can be done only in the case of non-volatile loads, with
- // ordering at most unordered. If the load is atomic, its only use should be
- // the trunc instruction. We don't want to allow other users of LI to see a
- // value that is out of sync with the value we're folding the trunc to (in
- // case of a race).
- if (LI->isUnordered() && (!LI->isAtomic() || LI->hasOneUse()))
- if (Value *AvailableVal = FindAvailableLoadedValue(
- LI->getPointerOperand(), DestTy, LI->isAtomic(), LI->getParent(),
- BBI, DefMaxInstsToScan))
- return replaceInstUsesWith(
- CI, Builder->CreateBitOrPointerCast(AvailableVal, CI.getType(),
- CI.getName() + ".cast"));
- }
return nullptr;
}
OpenPOWER on IntegriCloud