Skip to content

Commit 9da6c4e

Browse files
committed
review
1 parent 244e3c9 commit 9da6c4e

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,10 +1140,11 @@ bool MemCpyOptPass::processMemCpyMemCpyDependence(MemCpyInst *M,
11401140
if (MForwardOffset != 0 || MDep->getLength() != CopyLength) {
11411141
auto *MDepLen = dyn_cast<ConstantInt>(MDep->getLength());
11421142
auto *MLen = dyn_cast<ConstantInt>(CopyLength);
1143-
if (!MDepLen || !MLen)
1144-
return false; // This could be converted to a runtime test (%CopyLength =
1143+
// This could be converted to a runtime test (%CopyLength =
11451144
// min(max(0, MDepLen - MForwardOffset), MLen)), but it is
11461145
// unclear if that is useful
1146+
if (!MDepLen || !MLen)
1147+
return false;
11471148
if (MDepLen->getZExtValue() < MLen->getZExtValue() + MForwardOffset) {
11481149
if (!overreadUndefContents(MSSA, M, MDep, BAA))
11491150
return false;
@@ -1172,7 +1173,7 @@ bool MemCpyOptPass::processMemCpyMemCpyDependence(MemCpyInst *M,
11721173
auto MCopyLoc = MemoryLocation::getForSource(MDep);
11731174
// Truncate the size of the MDep access to just the bytes read
11741175
if (MDep->getLength() != CopyLength) {
1175-
auto ConstLength = cast<ConstantInt>(CopyLength);
1176+
auto *ConstLength = cast<ConstantInt>(CopyLength);
11761177
MCopyLoc = MCopyLoc.getWithNewSize(
11771178
LocationSize::precise(ConstLength->getZExtValue()));
11781179
}

llvm/test/Transforms/MemCpyOpt/memcpy-memcpy-offset.ll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ define void @forward_offset_memcpy_inline(ptr %src, ptr %dest) {
134134
ret void
135135
}
136136

137-
; We cannot forward `memcpy` because it exceeds the size of `memcpy` it depends on.
137+
; We can forward `memcpy` by shrinking it to the size of the `memcpy` it depends on.
138138
define void @forward_oversize_offset(ptr %src, ptr %dest) {
139139
; CHECK-LABEL: define void @forward_oversize_offset(
140140
; CHECK-SAME: ptr [[SRC:%.*]], ptr [[DEST:%.*]]) {
@@ -218,14 +218,14 @@ define void @pr98675(ptr noalias %p1, ptr noalias %p2) {
218218
define void @over_offset_cpy(ptr %src) {
219219
; CHECK-LABEL: define void @over_offset_cpy(
220220
; CHECK-SAME: ptr [[SRC:%.*]]) {
221-
; CHECK-NEXT: [[TMP:%.*]] = alloca i8, i64 2, align 1
222-
; CHECK-NEXT: [[DST:%.*]] = alloca i8, i64 1, align 1
221+
; CHECK-NEXT: [[TMP:%.*]] = alloca [2 x i8], align 1
222+
; CHECK-NEXT: [[DST:%.*]] = alloca i8, align 1
223223
; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[TMP]], ptr align 8 [[SRC]], i64 1, i1 false)
224224
; CHECK-NEXT: [[TMP_OFFSET:%.*]] = getelementptr inbounds i8, ptr [[TMP]], i64 1
225225
; CHECK-NEXT: ret void
226226
;
227-
%tmp = alloca i8, i64 2
228-
%dst = alloca i8, i64 1
227+
%tmp = alloca [2 x i8]
228+
%dst = alloca i8
229229
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %tmp, ptr align 8 %src, i64 1, i1 false)
230230
%tmp_offset = getelementptr inbounds i8, ptr %tmp, i64 1
231231
call void @llvm.memcpy.p0.p0.i64(ptr align 8 %dst, ptr align 8 %tmp_offset, i64 1, i1 false)

0 commit comments

Comments
 (0)