Skip to content

Commit 42d6eb5

Browse files
authored
[MemCpyOpt] Handle scalable aggregate types in memmove/memset formation (#80487)
Without this change, the included test cases crash the compiler. I believe this is fallout from the homogenous scalable struct work from a while back; I think we just forgot to update this case. Likely to fix #80463.
1 parent 0da2104 commit 42d6eb5

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,9 +677,9 @@ bool MemCpyOptPass::processStoreOfLoad(StoreInst *SI, LoadInst *LI,
677677
if (isModSet(AA->getModRefInfo(SI, LoadLoc)))
678678
UseMemMove = true;
679679

680-
uint64_t Size = DL.getTypeStoreSize(T);
681-
682680
IRBuilder<> Builder(P);
681+
Value *Size = Builder.CreateTypeSize(Builder.getInt64Ty(),
682+
DL.getTypeStoreSize(T));
683683
Instruction *M;
684684
if (UseMemMove)
685685
M = Builder.CreateMemMove(

llvm/test/Transforms/MemCpyOpt/vscale-crashes.ll

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,43 @@ define void @callslotoptzn(<vscale x 4 x float> %val, ptr %out) {
8585
ret void
8686
}
8787

88+
%0 = type { <vscale x 8 x i8> }
89+
%1 = type { <vscale x 8 x i8>, <vscale x 8 x i8> }
90+
91+
define void @memmove_vector(ptr %a, ptr %b) {
92+
; CHECK-LABEL: @memmove_vector(
93+
; CHECK-NEXT: [[V:%.*]] = load <vscale x 8 x i8>, ptr [[A:%.*]], align 1
94+
; CHECK-NEXT: store <vscale x 8 x i8> [[V]], ptr [[B:%.*]], align 1
95+
; CHECK-NEXT: ret void
96+
;
97+
%v = load <vscale x 8 x i8>, ptr %a, align 1
98+
store <vscale x 8 x i8> %v, ptr %b, align 1
99+
ret void
100+
}
101+
102+
define void @memmove_agg1(ptr %a, ptr %b) {
103+
; CHECK-LABEL: @memmove_agg1(
104+
; CHECK-NEXT: [[TMP1:%.*]] = call i64 @llvm.vscale.i64()
105+
; CHECK-NEXT: [[TMP2:%.*]] = mul i64 [[TMP1]], 8
106+
; CHECK-NEXT: call void @llvm.memmove.p0.p0.i64(ptr align 1 [[B:%.*]], ptr align 1 [[A:%.*]], i64 [[TMP2]], i1 false)
107+
; CHECK-NEXT: ret void
108+
;
109+
%v = load %0, ptr %a, align 1
110+
store %0 %v, ptr %b, align 1
111+
ret void
112+
}
113+
114+
define void @memmove_agg2(ptr %a, ptr %b) {
115+
; CHECK-LABEL: @memmove_agg2(
116+
; CHECK-NEXT: [[TMP1:%.*]] = call i64 @llvm.vscale.i64()
117+
; CHECK-NEXT: [[TMP2:%.*]] = mul i64 [[TMP1]], 16
118+
; CHECK-NEXT: call void @llvm.memmove.p0.p0.i64(ptr align 1 [[B:%.*]], ptr align 1 [[A:%.*]], i64 [[TMP2]], i1 false)
119+
; CHECK-NEXT: ret void
120+
;
121+
%v = load %1, ptr %a, align 1
122+
store %1 %v, ptr %b, align 1
123+
ret void
124+
}
125+
88126
declare <vscale x 4 x i32> @llvm.experimental.stepvector.nxv4i32()
89127
declare void @llvm.masked.scatter.nxv4f32.nxv4p0f32(<vscale x 4 x float> , <vscale x 4 x ptr> , i32, <vscale x 4 x i1>)

0 commit comments

Comments
 (0)