summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/InstructionSimplify.cpp
diff options
context:
space:
mode:
authorJohannes Doerfert <jdoerfert@anl.gov>2019-07-11 01:14:48 +0000
committerJohannes Doerfert <jdoerfert@anl.gov>2019-07-11 01:14:48 +0000
commit3ed286a388836d0cdd2c8a19fb4c295a19935b47 (patch)
treef37b2e311f7a7847475e5e222331353a8d0ee2bf /llvm/lib/Analysis/InstructionSimplify.cpp
parent24830ea7108197c7880939aa2e32db3aa4bc6284 (diff)
downloadbcm5719-llvm-3ed286a388836d0cdd2c8a19fb4c295a19935b47.tar.gz
bcm5719-llvm-3ed286a388836d0cdd2c8a19fb4c295a19935b47.zip
Replace three "strip & accumulate" implementations with a single one
This patch replaces the three almost identical "strip & accumulate" implementations for constant pointer offsets with a single one, combining the respective functionalities. The old interfaces are kept for now. Differential Revision: https://reviews.llvm.org/D64468 llvm-svn: 365723
Diffstat (limited to 'llvm/lib/Analysis/InstructionSimplify.cpp')
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp27
1 files changed, 1 insertions, 26 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index ce0b8a0fe64..0a2be059a9b 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -659,32 +659,7 @@ static Constant *stripAndComputeConstantOffsets(const DataLayout &DL, Value *&V,
Type *IntPtrTy = DL.getIntPtrType(V->getType())->getScalarType();
APInt Offset = APInt::getNullValue(IntPtrTy->getIntegerBitWidth());
- // Even though we don't look through PHI nodes, we could be called on an
- // instruction in an unreachable block, which may be on a cycle.
- SmallPtrSet<Value *, 4> Visited;
- Visited.insert(V);
- do {
- if (GEPOperator *GEP = dyn_cast<GEPOperator>(V)) {
- if ((!AllowNonInbounds && !GEP->isInBounds()) ||
- !GEP->accumulateConstantOffset(DL, Offset))
- break;
- V = GEP->getPointerOperand();
- } else if (Operator::getOpcode(V) == Instruction::BitCast) {
- V = cast<Operator>(V)->getOperand(0);
- } else if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
- if (GA->isInterposable())
- break;
- V = GA->getAliasee();
- } else {
- if (auto *Call = dyn_cast<CallBase>(V))
- if (Value *RV = Call->getReturnedArgOperand()) {
- V = RV;
- continue;
- }
- break;
- }
- assert(V->getType()->isPtrOrPtrVectorTy() && "Unexpected operand type!");
- } while (Visited.insert(V).second);
+ V = V->stripAndAccumulateConstantOffsets(DL, Offset, AllowNonInbounds);
Constant *OffsetIntPtr = ConstantInt::get(IntPtrTy, Offset);
if (V->getType()->isVectorTy())
OpenPOWER on IntegriCloud