Skip to content

[SROA]: Only defer trying partial sized ptr or ptr vector types #82279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/lib/Transforms/Scalar/SROA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2263,6 +2263,8 @@ static VectorType *createAndCheckVectorTypesForPromotion(
const DataLayout &DL, SmallVectorImpl<VectorType *> &CandidateTys,
bool &HaveCommonEltTy, Type *&CommonEltTy, bool &HaveVecPtrTy,
bool &HaveCommonVecPtrTy, VectorType *&CommonVecPtrTy) {
[[maybe_unused]] auto OriginalElt =
CandidateTysCopy.size() ? CandidateTysCopy[0] : nullptr;
// Consider additional vector types where the element type size is a
// multiple of load/store element size.
for (Type *Ty : OtherTys) {
Expand All @@ -2272,6 +2274,8 @@ static VectorType *createAndCheckVectorTypesForPromotion(
// Make a copy of CandidateTys and iterate through it, because we
// might append to CandidateTys in the loop.
for (VectorType *const VTy : CandidateTysCopy) {
// The elements in the copy should remain invariant throughout the loop
assert(CandidateTysCopy[0] == OriginalElt && "Different Element");
unsigned VectorSize = DL.getTypeSizeInBits(VTy).getFixedValue();
unsigned ElementSize =
DL.getTypeSizeInBits(VTy->getElementType()).getFixedValue();
Expand Down
30 changes: 30 additions & 0 deletions llvm/test/Transforms/SROA/vector-promotion.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,36 @@ entry:
ret <4 x i32> %0
}

; The following test should not crash the compiler
; (calls to CheckCandidateType from createAndCheckVectorTypesForPromotion may change the memory to hold CandidateTys.data())
define noundef zeroext i1 @CandidateTysRealloc() personality ptr null {
entry:
%alloca = alloca <4x i32>, align 16
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %alloca, align 16
br label %bb.1

bb.1:
br label %bb.1

bb.2:
%Load0 = load <4 x i32>, ptr %alloca, align 16
store <4 x i32> zeroinitializer, ptr %alloca, align 16
%Load1 = load <4 x i32>, ptr %alloca, align 16
br label %bb.3

bb.3:
br label %bb.3

bb.4:
%Load2 = load i64, ptr %alloca, align 16
%Load3 = load <4 x i32>, ptr %alloca, align 16
store <4 x i32> zeroinitializer, ptr %alloca, align 16
br label %bb.5

bb.5:
br label %bb.5
}

declare void @llvm.memcpy.p0.p0.i64(ptr, ptr, i64, i1)
declare void @llvm.lifetime.end.p0(i64, ptr)
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
Expand Down