[llvm] Use pointer index type for more GEP offsets (pre-codegen)
authorKrzysztof Drewniak <Krzysztof.Drewniak@amd.com>
Thu, 23 Feb 2023 21:47:48 +0000 (21:47 +0000)
committerKrzysztof Drewniak <Krzysztof.Drewniak@amd.com>
Tue, 28 Mar 2023 16:41:02 +0000 (16:41 +0000)
commit916425b2d1644cad3dc96c52d27a78f523472bb7
tree925d8b008308913cad4abb69f8cbe8fe983bb79f
parent51dd8a20c1c32c60d03719e0e40bbc8e6c125477
[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
26 files changed:
llvm/docs/LangRef.rst
llvm/include/llvm/IR/DataLayout.h
llvm/include/llvm/IR/IRBuilder.h
llvm/lib/Analysis/MemoryBuiltins.cpp
llvm/lib/IR/DataLayout.cpp
llvm/lib/Transforms/IPO/LowerTypeTests.cpp
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp
llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
llvm/lib/Transforms/Scalar/MergeICmps.cpp
llvm/lib/Transforms/Scalar/NaryReassociate.cpp
llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
llvm/lib/Transforms/Utils/FunctionComparator.cpp
llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
llvm/test/Instrumentation/BoundsChecking/simple.ll
llvm/test/Transforms/InstCombine/alloca-intptr-not-sizet.ll
llvm/test/Transforms/InstCombine/load-cmp.ll
llvm/test/Transforms/LoadStoreVectorizer/AMDGPU/merge-vectors.ll
llvm/test/Transforms/LowerTypeTests/distinct-index-width-crash.ll [new file with mode: 0644]
llvm/test/Transforms/MergeFunc/different-index-width-gep-crash.ll [new file with mode: 0644]
llvm/test/Transforms/MergeICmps/X86/distinct-index-width-crash.ll [new file with mode: 0644]
llvm/test/Transforms/NaryReassociate/nary-gep.ll [new file with mode: 0644]
llvm/test/Transforms/SeparateConstOffsetFromGEP/pointer-type-not-offset-type.ll
llvm/test/Transforms/StraightLineStrengthReduce/slsr-gep.ll