Skip to content

Commit 79f41f1

Browse files
Brox Chensys-ce-bb
Brox Chen
authored andcommitted
Fix ptr.annotation generation with llvm.memcpy (#2032)
For a memcpy call, there also could be ptr.annotation generated before the src and dest pointer. Update the code to check ptr.annotation for OpCopyMemorySized and update lit test Original commit: KhronosGroup/SPIRV-LLVM-Translator@9434a72
1 parent c5f8846 commit 79f41f1

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -1821,8 +1821,14 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
18211821
bool IsVolatile = BC->SPIRVMemoryAccess::isVolatile();
18221822
IRBuilder<> Builder(BB);
18231823

1824+
// A ptr.annotation may have been generated for the destination variable.
1825+
replaceOperandWithAnnotationIntrinsicCallResult(F, Dst);
1826+
18241827
if (!CI) {
18251828
llvm::Value *Src = transValue(BC->getSource(), F, BB);
1829+
1830+
// A ptr.annotation may have been generated for the source variable.
1831+
replaceOperandWithAnnotationIntrinsicCallResult(F, Src);
18261832
CI = Builder.CreateMemCpy(Dst, Align, Src, Align, Size, IsVolatile);
18271833
}
18281834
if (isFuncNoUnwind())

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -3717,6 +3717,10 @@ bool allowDecorateWithBufferLocationOrLatencyControlINTEL(IntrinsicInst *II) {
37173717
for (auto &Inst : UserList)
37183718
if (isa<LoadInst>(Inst) || isa<StoreInst>(Inst))
37193719
return true;
3720+
else if (auto *III = dyn_cast<IntrinsicInst>(Inst)) {
3721+
if (III->getIntrinsicID() == Intrinsic::memcpy)
3722+
return true;
3723+
}
37203724

37213725
return false;
37223726
}

llvm-spirv/test/extensions/INTEL/SPV_INTEL_fpga_buffer_location/FPGABufferLocation.ll

+22
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,31 @@ entry:
9696
ret void
9797
}
9898

99+
; test3 : memcpy
100+
; Function Attrs: convergent mustprogress norecurse
101+
define spir_kernel void @test.3(ptr addrspace(1) align 4 %arg_a, ptr %arg_b) {
102+
entry:
103+
%this.addr.i = alloca ptr addrspace(4), align 8
104+
%arg_a.addr = alloca ptr addrspace(1), align 8
105+
%MyIP = alloca %struct.MyIP, align 8
106+
%arg_a.addr.ascast = addrspacecast ptr %arg_a.addr to ptr addrspace(4)
107+
%MyIP.ascast = addrspacecast ptr %MyIP to ptr addrspace(4)
108+
store ptr addrspace(1) %arg_a, ptr addrspace(4) %arg_a.addr.ascast, align 8
109+
%a = getelementptr inbounds %struct.MyIP, ptr addrspace(4) %MyIP.ascast, i32 0, i32 0
110+
%0 = call ptr addrspace(4) @llvm.ptr.annotation.p4.p0(ptr addrspace(4) %a, ptr getelementptr inbounds ([19 x i8], ptr @.str.4, i32 0, i32 0), ptr getelementptr inbounds ([9 x i8], ptr @.str.1, i32 0, i32 0), i32 7, ptr null)
111+
call void @llvm.memcpy.p4.p0(ptr addrspace(4) %0, ptr %arg_b, i64 4, i1 false)
112+
; CHECK-LLVM: %[[INTRINSIC_CALL:[[:alnum:].]+]] = call ptr addrspace(4) @llvm.ptr.annotation.p4.p0(ptr addrspace(4) %a, ptr @[[ANN_STR]], ptr undef, i32 undef, ptr undef)
113+
; CHECK-LLVM: %[[BITCAST:[[:alnum:].]+]] = bitcast ptr addrspace(4) %[[INTRINSIC_CALL]] to ptr addrspace(4)
114+
; CHECK-LLVM: llvm.memcpy.p4.p0.i64(ptr addrspace(4) %[[BITCAST]], ptr %arg_b, i64 4, i1 false)
115+
ret void
116+
}
117+
99118
; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite)
100119
declare ptr addrspace(4) @llvm.ptr.annotation.p4.p0(ptr addrspace(4), ptr, ptr, i32, ptr) #1
101120

121+
; Function Attrs: argmemonly nofree nounwind willreturn
122+
declare void @llvm.memcpy.p4.p0(ptr addrspace(4) noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2
123+
102124
!opencl.enable.FP_CONTRACT = !{}
103125
!opencl.ocl.version = !{!0}
104126
!opencl.spir.version = !{!0}

0 commit comments

Comments
 (0)