Factorize code: remove variants of "strip off
pointer bitcasts and GEP's", and centralize the
logic in Value::getUnderlyingObject. The
difference with stripPointerCasts is that
stripPointerCasts only strips GEPs if all
indices are zero, while getUnderlyingObject
strips GEPs no matter what the indices are.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56922 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp
index 1e5be4a..25b61c1 100644
--- a/lib/Transforms/Scalar/GVN.cpp
+++ b/lib/Transforms/Scalar/GVN.cpp
@@ -992,16 +992,7 @@
isa<AllocationInst>(dep)) {
// Check that this load is actually from the
// allocation we found
- Value* v = L->getOperand(0);
- while (true) {
- if (BitCastInst *BC = dyn_cast<BitCastInst>(v))
- v = BC->getOperand(0);
- else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(v))
- v = GEP->getOperand(0);
- else
- break;
- }
- if (v == dep) {
+ if (L->getOperand(0)->getUnderlyingObject() == dep) {
// If this load depends directly on an allocation, there isn't
// anything stored there; therefore, we can optimize this load
// to undef.