Skip to content

Commit 0ae6145

Browse files
maarquitos14jsji
authored andcommitted
Set required alignment to CopyMemorySized newly created source var (#2725)
llvm.memset intrinsic is translated to OpCopyMemorySized using a newly created global variable with the required value as a source operand. This PR sets proper alignment to this newly created global variable. Signed-off-by: Marcos Maronas <[email protected]> Original commit: KhronosGroup/SPIRV-LLVM-Translator@b0690c16c3247e7
1 parent 064052a commit 0ae6145

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4604,15 +4604,16 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
46044604
SPIRVValue *Var = BM->addVariable(VarTy, nullptr, /*isConstant*/ true,
46054605
spv::internal::LinkageTypeInternal, Init,
46064606
"", StorageClassUniformConstant, nullptr);
4607+
std::vector<SPIRVWord> MemAccess = GetMemoryAccess(
4608+
MSI, BM->isAllowedToUseVersion(VersionNumber::SPIRV_1_4));
4609+
if (!MemAccess.empty() && MemAccess[0] == MemoryAccessAlignedMask)
4610+
Var->setAlignment(MemAccess[1]);
46074611
SPIRVType *SourceTy =
46084612
transPointerType(Val->getType(), SPIRV::SPIRAS_Constant);
46094613
SPIRVValue *Source = BM->addUnaryInst(OpBitcast, SourceTy, Var, BB);
46104614
SPIRVValue *Target = transValue(MSI->getRawDest(), BB);
4611-
return BM->addCopyMemorySizedInst(
4612-
Target, Source, CompositeTy->getLength(),
4613-
GetMemoryAccess(MSI,
4614-
BM->isAllowedToUseVersion(VersionNumber::SPIRV_1_4)),
4615-
BB);
4615+
return BM->addCopyMemorySizedInst(Target, Source, CompositeTy->getLength(),
4616+
MemAccess, BB);
46164617
} break;
46174618
case Intrinsic::memcpy:
46184619
return BM->addCopyMemorySizedInst(
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -spirv-text -o %t.txt
3+
; RUN: FileCheck < %t.txt %s --check-prefix=CHECK-SPIRV
4+
; RUN: llvm-spirv %t.bc -o %t.spv
5+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
6+
; RUN: llvm-dis %t.rev.bc
7+
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM
8+
9+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64-G1"
10+
target triple = "spir64-unknown-unknown"
11+
12+
define internal spir_func void @_ZN4sycl3_V16detail26builtin_delegate_to_scalarIZNS0_8upsampleINS0_3vecIiLi2EEENS4_IjLi2EEEEENSt9enable_ifIXsr6detailE17enable_upsample_vIT_T0_EENS1_15change_elementsINS1_8map_typeIJNS1_13get_elem_typeIS8_E4typeEashtsitjiljmEE4typeES8_E4typeEE4typeES8_S9_EUlDpT_E_JS5_S6_EEEDaS8_DpRKT0_() {
13+
entry:
14+
%r.sroa.0 = alloca [2 x i64], i32 1, align 16
15+
%r.sroa.0.0.r.ascast.sroa_cast1 = addrspacecast ptr %r.sroa.0 to ptr addrspace(4)
16+
17+
; CHECK-SPIRV: Decorate [[#]] Alignment 16
18+
; CHECK-SPIRV: Decorate [[#SrcVar:]] Alignment [[#SrcAlignment:]]
19+
; CHECK-SPIRV: Bitcast [[#]] [[#]] [[#]]
20+
; CHECK-SPIRV: Bitcast [[#]] [[#Src:]] [[#SrcVar]]
21+
; CHECK-SPIRV: CopyMemorySized [[#]] [[#Src]] [[#]] 2 [[#SrcAlignment]]
22+
; CHECK-LLVM: [[SrcVar:@[0-9]+]] = internal unnamed_addr addrspace(2) constant [16 x i8] zeroinitializer, align [[#SrcAlignment:]]
23+
; CHECK-LLVM: [[SrcOp:%[0-9]+]] = bitcast ptr addrspace(2) [[SrcVar]] to ptr addrspace(2)
24+
; CHECK-LLVM: call void @llvm.memcpy.p4.p2.i64(ptr addrspace(4) align 16 %0, ptr addrspace(2) align [[#SrcAlignment]] [[SrcOp]], i64 16, i1 false)
25+
call void @llvm.memset.p4.i64(ptr addrspace(4) align 16 %r.sroa.0.0.r.ascast.sroa_cast1, i8 0, i64 16, i1 false)
26+
ret void
27+
}
28+
29+
define spir_func void @_ZN4sycl3_V18upsampleINS0_3vecIiLi2EEENS2_IjLi2EEEEENSt9enable_ifIXsr6detailE17enable_upsample_vIT_T0_EENS0_6detail15change_elementsINS8_8map_typeIJNS8_13get_elem_typeIS6_E4typeEashtsitjiljmEE4typeES6_E4typeEE4typeES6_S7_() {
30+
entry:
31+
call spir_func void @_ZN4sycl3_V16detail26builtin_delegate_to_scalarIZNS0_8upsampleINS0_3vecIiLi2EEENS4_IjLi2EEEEENSt9enable_ifIXsr6detailE17enable_upsample_vIT_T0_EENS1_15change_elementsINS1_8map_typeIJNS1_13get_elem_typeIS8_E4typeEashtsitjiljmEE4typeES8_E4typeEE4typeES8_S9_EUlDpT_E_JS5_S6_EEEDaS8_DpRKT0_()
32+
ret void
33+
}
34+
35+
; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
36+
declare void @llvm.memset.p4.i64(ptr addrspace(4) nocapture writeonly, i8, i64, i1 immarg) #0
37+
38+
attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }

0 commit comments

Comments
 (0)