diff options
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 3f2ee99..c25f02b 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -8224,74 +8224,3 @@ ConstantRange llvm::computeConstantRange(const Value *V, bool ForSigned, return CR; } - -static std::optional<int64_t> -getOffsetFromIndex(const GEPOperator *GEP, unsigned Idx, const DataLayout &DL) { - // Skip over the first indices. - gep_type_iterator GTI = gep_type_begin(GEP); - for (unsigned i = 1; i != Idx; ++i, ++GTI) - /*skip along*/; - - // Compute the offset implied by the rest of the indices. - int64_t Offset = 0; - for (unsigned i = Idx, e = GEP->getNumOperands(); i != e; ++i, ++GTI) { - ConstantInt *OpC = dyn_cast<ConstantInt>(GEP->getOperand(i)); - if (!OpC) - return std::nullopt; - if (OpC->isZero()) - continue; // No offset. - - // Handle struct indices, which add their field offset to the pointer. - if (StructType *STy = GTI.getStructTypeOrNull()) { - Offset += DL.getStructLayout(STy)->getElementOffset(OpC->getZExtValue()); - continue; - } - - // Otherwise, we have a sequential type like an array or fixed-length - // vector. Multiply the index by the ElementSize. - TypeSize Size = DL.getTypeAllocSize(GTI.getIndexedType()); - if (Size.isScalable()) - return std::nullopt; - Offset += Size.getFixedValue() * OpC->getSExtValue(); - } - - return Offset; -} - -std::optional<int64_t> llvm::isPointerOffset(const Value *Ptr1, - const Value *Ptr2, - const DataLayout &DL) { - APInt Offset1(DL.getIndexTypeSizeInBits(Ptr1->getType()), 0); - APInt Offset2(DL.getIndexTypeSizeInBits(Ptr2->getType()), 0); - Ptr1 = Ptr1->stripAndAccumulateConstantOffsets(DL, Offset1, true); - Ptr2 = Ptr2->stripAndAccumulateConstantOffsets(DL, Offset2, true); - - // Handle the trivial case first. - if (Ptr1 == Ptr2) - return Offset2.getSExtValue() - Offset1.getSExtValue(); - - const GEPOperator *GEP1 = dyn_cast<GEPOperator>(Ptr1); - const GEPOperator *GEP2 = dyn_cast<GEPOperator>(Ptr2); - - // Right now we handle the case when Ptr1/Ptr2 are both GEPs with an identical - // base. After that base, they may have some number of common (and - // potentially variable) indices. After that they handle some constant - // offset, which determines their offset from each other. At this point, we - // handle no other case. - if (!GEP1 || !GEP2 || GEP1->getOperand(0) != GEP2->getOperand(0) || - GEP1->getSourceElementType() != GEP2->getSourceElementType()) - return std::nullopt; - - // Skip any common indices and track the GEP types. - unsigned Idx = 1; - for (; Idx != GEP1->getNumOperands() && Idx != GEP2->getNumOperands(); ++Idx) - if (GEP1->getOperand(Idx) != GEP2->getOperand(Idx)) - break; - - auto IOffset1 = getOffsetFromIndex(GEP1, Idx, DL); - auto IOffset2 = getOffsetFromIndex(GEP2, Idx, DL); - if (!IOffset1 || !IOffset2) - return std::nullopt; - return *IOffset2 - *IOffset1 + Offset2.getSExtValue() - - Offset1.getSExtValue(); -} |