[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
Tue Feb 1 12:42:05 PST 2022
jdoerfert updated this revision to Diff 405065.
jdoerfert added a comment.
Fix comments
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
@@ -573,10 +573,34 @@
}
SizeOffsetType ObjectSizeOffsetVisitor::compute(Value *V) {
+ unsigned InitialIntTyBits = DL.getIndexTypeSizeInBits(V->getType());
+
+ // Stripping pointer casts can strip address space casts which can change the
+ // index type size. The invariant is that we use the value type to determine
+ // the index type size. If we stripped address space casts we "repair" the
+ // APInt as we pass it upwards. For the caller, the APInt matches the type of
+ // the argument value V (or better the type of it).
+ V = V->stripPointerCasts();
+
+ // Later we use the index type size and zero but it will match the type of the
+ // value that is passed to computeImpl.
IntTyBits = DL.getIndexTypeSizeInBits(V->getType());
Zero = APInt::getZero(IntTyBits);
- V = V->stripPointerCasts();
+ if (InitialIntTyBits == IntTyBits)
+ return computeImpl(V);
+
+ // We stripped an address space cast that changed the index type size.
+ // Readjust it to match the argument's index type size.
+ SizeOffsetType SOT = computeImpl(V);
+ if (knownSize(SOT) && !::CheckedZextOrTrunc(SOT.first, InitialIntTyBits))
+ return unknown();
+ if (knownOffset(SOT) && !::CheckedZextOrTrunc(SOT.second, InitialIntTyBits))
+ return unknown();
+ return SOT;
+}
+
+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.
Index: llvm/include/llvm/Analysis/MemoryBuiltins.h
===================================================================
--- llvm/include/llvm/Analysis/MemoryBuiltins.h
+++ llvm/include/llvm/Analysis/MemoryBuiltins.h
@@ -221,6 +221,7 @@
SizeOffsetType visitInstruction(Instruction &I);
private:
+ SizeOffsetType computeImpl(Value *V);
bool CheckedZextOrTrunc(APInt &I);
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118727.405065.patch
Type: text/x-patch
Size: 2114 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220201/db542cf6/attachment.bin>
More information about the llvm-commits
mailing list