Skip to content

Commit 14ce485

Browse files
committed
Add test for 0 byte copy and copy one element. Fix 0 byte copy implementation
1 parent 6ab934d commit 14ce485

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

llvm/lib/Target/DirectX/DXILCBufferAccess.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ static void replaceLoad(LoadInst *LI, CBufferResource &CBR,
199199
/// itself. Assumes the cbuffer global is an array, and the length of bytes to
200200
/// copy is divisible by array element allocation size.
201201
/// The memcpy source must also be a direct cbuffer global reference, not a GEP.
202-
static void replaceMemCpy(MemCpyInst *MCI, CBufferResource &CBR,
203-
SmallVectorImpl<WeakTrackingVH> &DeadInsts) {
202+
static void replaceMemCpy(MemCpyInst *MCI, CBufferResource &CBR) {
204203

205204
ArrayType *ArrTy = dyn_cast<ArrayType>(CBR.getValueType());
206205
assert(ArrTy && "MemCpy lowering is only supported for array types");
@@ -219,7 +218,7 @@ static void replaceMemCpy(MemCpyInst *MCI, CBufferResource &CBR,
219218

220219
// If length to copy is zero, no memcpy is needed
221220
if (ByteLength == 0) {
222-
DeadInsts.push_back(MCI);
221+
MCI->eraseFromParent();
223222
return;
224223
}
225224

@@ -290,7 +289,7 @@ static void replaceAccessesWithHandle(CBufferResource &CBR) {
290289
// If we have a memcpy instruction, replace it with multiple accesses and
291290
// subsequent stores to the destination
292291
if (auto *MCI = dyn_cast<MemCpyInst>(Cur)) {
293-
replaceMemCpy(MCI, CBR, DeadInsts);
292+
replaceMemCpy(MCI, CBR);
294293
continue;
295294
}
296295

llvm/test/CodeGen/DirectX/CBufferAccess/memcpy.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ entry:
3737
%a7.copy = alloca [2 x i64], align 8
3838
%a8.copy = alloca [4 x i32], align 4
3939

40+
; Try copying no elements
41+
; CHECK-NOT: memcpy
42+
call void @llvm.memcpy.p0.p2.i32(ptr align 4 %a1.copy, ptr addrspace(2) align 4 @a1, i32 0, i1 false)
43+
44+
; Try copying only the first element
45+
; CHECK: [[CB:%.*]] = load target("dx.CBuffer", {{.*}})), ptr @CB.cb, align 4
46+
; CHECK: [[LOAD:%.*]] = call { float, float, float, float } @llvm.dx.resource.load.cbufferrow.4.{{.*}}(target("dx.CBuffer", {{.*}})) [[CB]], i32 0)
47+
; CHECK: [[X:%.*]] = extractvalue { float, float, float, float } [[LOAD]], 0
48+
; CHECK: [[DEST:%.*]] = getelementptr inbounds i8, ptr [[A1_COPY:%.*]], i32 0
49+
; CHECK: store float [[X]], ptr [[DEST]], align 4
50+
call void @llvm.memcpy.p0.p2.i32(ptr align 4 %a1.copy, ptr addrspace(2) align 4 @a1, i32 4, i1 false)
51+
4052
; CHECK: [[CB:%.*]] = load target("dx.CBuffer", {{.*}})), ptr @CB.cb, align 4
4153
; CHECK: [[LOAD:%.*]] = call { float, float, float, float } @llvm.dx.resource.load.cbufferrow.4.{{.*}}(target("dx.CBuffer", {{.*}})) [[CB]], i32 0)
4254
; CHECK: [[X:%.*]] = extractvalue { float, float, float, float } [[LOAD]], 0

0 commit comments

Comments
 (0)