[PATCH] D118727: [MemoryBuiltins][FIX] Adjust index type size properly wrt. AS casts
Johannes Doerfert via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 2 10:09:47 PST 2022
jdoerfert updated this revision to Diff 405330.
jdoerfert added a comment.
Use existing strip and accumulate
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D118727/new/
https://reviews.llvm.org/D118727
Files:
llvm/include/llvm/Analysis/MemoryBuiltins.h
llvm/lib/Analysis/MemoryBuiltins.cpp
Index: llvm/lib/Analysis/MemoryBuiltins.cpp
===================================================================
--- llvm/lib/Analysis/MemoryBuiltins.cpp
+++ llvm/lib/Analysis/MemoryBuiltins.cpp
@@ -576,15 +576,23 @@
IntTyBits = DL.getIndexTypeSizeInBits(V->getType());
Zero = APInt::getZero(IntTyBits);
- V = V->stripPointerCasts();
+ APInt Offset(IntTyBits, 0);
+ V = V->stripAndAccumulateConstantOffsets(DL, Offset, /* AllowNonInbounds */ true, /* AllowInvariantGroup */ true);
+ if (Offset.isZero())
+ return computeImpl(V);
+
+ SizeOffsetType SOT = computeImpl(V);
+ return {SOT.first, SOT.second + Offset};
+}
+
+SizeOffsetType ObjectSizeOffsetVisitor::computeImpl(Value *V) {
if (Instruction *I = dyn_cast<Instruction>(V)) {
// If we have already seen this instruction, bail out. Cycles can happen in
// unreachable code after constant propagation.
if (!SeenInsts.insert(I).second)
return unknown();
- if (GEPOperator *GEP = dyn_cast<GEPOperator>(V))
- return visitGEPOperator(*GEP);
+ assert(!isa<GEPOperator>(V) && "GEPs should have been stripped already");
return visit(*I);
}
if (Argument *A = dyn_cast<Argument>(V))
@@ -600,8 +608,7 @@
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
if (CE->getOpcode() == Instruction::IntToPtr)
return unknown(); // clueless
- if (CE->getOpcode() == Instruction::GetElementPtr)
- return visitGEPOperator(cast<GEPOperator>(*CE));
+ assert(!isa<GEPOperator>(CE) && "GEPs should have been stripped already");
}
LLVM_DEBUG(dbgs() << "ObjectSizeOffsetVisitor::compute() unhandled value: "
@@ -682,15 +689,6 @@
return unknown();
}
-SizeOffsetType ObjectSizeOffsetVisitor::visitGEPOperator(GEPOperator &GEP) {
- SizeOffsetType PtrData = compute(GEP.getPointerOperand());
- APInt Offset(DL.getIndexTypeSizeInBits(GEP.getPointerOperand()->getType()), 0);
- if (!bothKnown(PtrData) || !GEP.accumulateConstantOffset(DL, Offset))
- return unknown();
-
- return std::make_pair(PtrData.first, PtrData.second + Offset);
-}
-
SizeOffsetType ObjectSizeOffsetVisitor::visitGlobalAlias(GlobalAlias &GA) {
if (GA.isInterposable())
return unknown();
Index: llvm/include/llvm/Analysis/MemoryBuiltins.h
===================================================================
--- llvm/include/llvm/Analysis/MemoryBuiltins.h
+++ llvm/include/llvm/Analysis/MemoryBuiltins.h
@@ -210,7 +210,6 @@
SizeOffsetType visitConstantPointerNull(ConstantPointerNull&);
SizeOffsetType visitExtractElementInst(ExtractElementInst &I);
SizeOffsetType visitExtractValueInst(ExtractValueInst &I);
- SizeOffsetType visitGEPOperator(GEPOperator &GEP);
SizeOffsetType visitGlobalAlias(GlobalAlias &GA);
SizeOffsetType visitGlobalVariable(GlobalVariable &GV);
SizeOffsetType visitIntToPtrInst(IntToPtrInst&);
@@ -221,6 +220,7 @@
SizeOffsetType visitInstruction(Instruction &I);
private:
+ SizeOffsetType computeImpl(Value *V);
bool CheckedZextOrTrunc(APInt &I);
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118727.405330.patch
Type: text/x-patch
Size: 3017 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220202/359bffb8/attachment.bin>
More information about the llvm-commits
mailing list