diff options
author | Krzysztof Drewniak <Krzysztof.Drewniak@amd.com> | 2023-02-23 21:47:48 +0000 |
---|---|---|
committer | Krzysztof Drewniak <Krzysztof.Drewniak@amd.com> | 2023-03-28 16:41:02 +0000 |
commit | 916425b2d1644cad3dc96c52d27a78f523472bb7 (patch) | |
tree | 925d8b008308913cad4abb69f8cbe8fe983bb79f /llvm/lib/Analysis/MemoryBuiltins.cpp | |
parent | 51dd8a20c1c32c60d03719e0e40bbc8e6c125477 (diff) | |
download | llvm-916425b2d1644cad3dc96c52d27a78f523472bb7.zip llvm-916425b2d1644cad3dc96c52d27a78f523472bb7.tar.gz llvm-916425b2d1644cad3dc96c52d27a78f523472bb7.tar.bz2 |
[llvm] Use pointer index type for more GEP offsets (pre-codegen)
Many uses of getIntPtrType() were using that type to calculate the
neened type for GEP offset arguments. However, some time ago,
DataLayout was extended to support pointers where the size of the
pointer is not equal to the size of the values used to index it.
Much code was already migrated to, for example, use getIndexSizeInBits
instead of getPtrSizeInBits, but some rewrites still used
getIntPtrType() to get the type for GEP offsets.
This commit changes uses of getIntPtrType() to getIndexType() where
they are involved in a GEP-related calculation.
In at least one case (bounds check insertion) this resolves a compiler
crash that the new test added here would previously trigger.
This commit does not impact
- C library-related rewriting (memcpy()), which are operating under
the assumption that intptr_t == size_t. While all the mechanisms for
breaking this assumption now exist, doing so is outside the scope of
this commit.
- Code generation and below. Note that the use of getIntPtrType() in
CodeGenPrepare will be changed in a future commit.
- Usage of getIntPtrType() in any backend
Depends on D143435
Reviewed By: arichardson
Differential Revision: https://reviews.llvm.org/D143437
Diffstat (limited to 'llvm/lib/Analysis/MemoryBuiltins.cpp')
-rw-r--r-- | llvm/lib/Analysis/MemoryBuiltins.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp index 0edad05..4d818bb 100644 --- a/llvm/lib/Analysis/MemoryBuiltins.cpp +++ b/llvm/lib/Analysis/MemoryBuiltins.cpp @@ -1099,12 +1099,13 @@ SizeOffsetEvalType ObjectSizeOffsetEvaluator::visitAllocaInst(AllocaInst &I) { // must be a VLA assert(I.isArrayAllocation()); - // If needed, adjust the alloca's operand size to match the pointer size. - // Subsequent math operations expect the types to match. + // If needed, adjust the alloca's operand size to match the pointer indexing + // size. Subsequent math operations expect the types to match. Value *ArraySize = Builder.CreateZExtOrTrunc( - I.getArraySize(), DL.getIntPtrType(I.getContext())); + I.getArraySize(), + DL.getIndexType(I.getContext(), DL.getAllocaAddrSpace())); assert(ArraySize->getType() == Zero->getType() && - "Expected zero constant to have pointer type"); + "Expected zero constant to have pointer index type"); Value *Size = ConstantInt::get(ArraySize->getType(), DL.getTypeAllocSize(I.getAllocatedType())); |