summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-11-27 08:56:30 +0000
committerChris Lattner <sabre@nondot.org>2008-11-27 08:56:30 +0000
commite0d019def6413f61ccc1cdc9bbe55773015b7a40 (patch)
tree00e9f65329a50a5c23fd771a143e8e750b28ce77 /llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
parent378b041f03f03c2038b2afbd1819eeb6ea662156 (diff)
downloadbcm5719-llvm-e0d019def6413f61ccc1cdc9bbe55773015b7a40.tar.gz
bcm5719-llvm-e0d019def6413f61ccc1cdc9bbe55773015b7a40.zip
switch InstCombine::visitLoadInst to use
FindAvailableLoadedValue llvm-svn: 60169
Diffstat (limited to 'llvm/lib/Transforms/Utils/BasicBlockUtils.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/BasicBlockUtils.cpp27
1 files changed, 25 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index d38099f4eb1..bd32a99516e 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -373,6 +373,29 @@ BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB,
return NewBB;
}
+/// AreEquivalentAddressValues - Test if A and B will obviously have the same
+/// value. This includes recognizing that %t0 and %t1 will have the same
+/// value in code like this:
+/// %t0 = getelementptr @a, 0, 3
+/// store i32 0, i32* %t0
+/// %t1 = getelementptr @a, 0, 3
+/// %t2 = load i32* %t1
+///
+static bool AreEquivalentAddressValues(const Value *A, const Value *B) {
+ // Test if the values are trivially equivalent.
+ if (A == B) return true;
+
+ // Test if the values come form identical arithmetic instructions.
+ if (isa<BinaryOperator>(A) || isa<CastInst>(A) ||
+ isa<PHINode>(A) || isa<GetElementPtrInst>(A))
+ if (const Instruction *BI = dyn_cast<Instruction>(B))
+ if (cast<Instruction>(A)->isIdenticalTo(BI))
+ return true;
+
+ // Otherwise they may not be equivalent.
+ return false;
+}
+
/// FindAvailableLoadedValue - Scan the ScanBB block backwards (starting at the
/// instruction before ScanFrom) checking to see if we have the value at the
/// memory address *Ptr locally available within a small number of instructions.
@@ -407,12 +430,12 @@ Value *llvm::FindAvailableLoadedValue(Value *Ptr, BasicBlock *ScanBB,
// If this is a load of Ptr, the loaded value is available.
if (LoadInst *LI = dyn_cast<LoadInst>(Inst))
- if (LI->getOperand(0) == Ptr)
+ if (AreEquivalentAddressValues(LI->getOperand(0), Ptr))
return LI;
if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
// If this is a store through Ptr, the value is available!
- if (SI->getOperand(1) == Ptr)
+ if (AreEquivalentAddressValues(SI->getOperand(1), Ptr))
return SI->getOperand(0);
// If Ptr is an alloca and this is a store to a different alloca, ignore
OpenPOWER on IntegriCloud