aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/DataLayout.cpp
diff options
context:
space:
mode:
authorJannik Silvanus <jannik.silvanus@amd.com>2023-01-19 16:04:45 +0100
committerJannik Silvanus <jannik.silvanus@amd.com>2023-01-23 13:25:39 +0100
commita4753f5dc0a9bccf3706a82cacbd046c272eb814 (patch)
tree0ebc018c669e66b3fcc8a3b8f50be51412294ba0 /llvm/lib/IR/DataLayout.cpp
parenteb197e3ea670ee0c573d95a0033327a213656357 (diff)
downloadllvm-a4753f5dc0a9bccf3706a82cacbd046c272eb814.zip
llvm-a4753f5dc0a9bccf3706a82cacbd046c272eb814.tar.gz
llvm-a4753f5dc0a9bccf3706a82cacbd046c272eb814.tar.bz2
[IR] Avoid creation of GEPs into vectors (in one place)
The method DataLayout::getGEPIndexForOffset(Type *&ElemTy, APInt &Offset) allows to generate GEP indices for a given byte-based offset. This allows to generate "natural" GEPs using the given type structure if the byte offset happens to match a nested element object. With opaque pointers and a general move towards byte-based GEPs [1], this function may be questionable in the future. This patch avoids creation of GEPs into vectors in routines that use DataLayout::getGEPIndexForOffset by not returning indices in that case. The reason is that A) GEPs into vectors have been discouraged for a long time [2], and B) that GEPs into vectors are currently broken if the element type is overaligned [1]. This is also demonstrated by a lit test where previously InstCombine replaced valid loads by poison. Note that the result of InstCombine on that test is *still* invalid, because padding bytes are assumed. Moreover, GEPs into vectors may be outright forbidden in the future [1]. [1]: https://discourse.llvm.org/t/67497 [2]: https://llvm.org/docs/GetElementPtr.html The test case is new. It will be precommitted if this patch is accepted. Differential Revision: https://reviews.llvm.org/D142146
Diffstat (limited to 'llvm/lib/IR/DataLayout.cpp')
-rw-r--r--llvm/lib/IR/DataLayout.cpp11
1 files changed, 4 insertions, 7 deletions
diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp
index b4d40e6..289d525 100644
--- a/llvm/lib/IR/DataLayout.cpp
+++ b/llvm/lib/IR/DataLayout.cpp
@@ -940,13 +940,10 @@ std::optional<APInt> DataLayout::getGEPIndexForOffset(Type *&ElemTy,
}
if (auto *VecTy = dyn_cast<VectorType>(ElemTy)) {
- ElemTy = VecTy->getElementType();
- unsigned ElemSizeInBits = getTypeSizeInBits(ElemTy).getFixedValue();
- // GEPs over non-multiple of 8 size vector elements are invalid.
- if (ElemSizeInBits % 8 != 0)
- return std::nullopt;
-
- return getElementIndex(TypeSize::Fixed(ElemSizeInBits / 8), Offset);
+ // Vector GEPs are partially broken (e.g. for overaligned element types),
+ // and may be forbidden in the future, so avoid generating GEPs into
+ // vectors. See https://discourse.llvm.org/t/67497
+ return std::nullopt;
}
if (auto *STy = dyn_cast<StructType>(ElemTy)) {