Skip to content

Commit 1317266

Browse files
bashbaugjsji
authored andcommitted
Generate load and store for OpCopyLogical (#2825)
fixes #2768 Generate an LLVM memcpy for OpCopyLogical, rather than a call to an OpCopyLogical function. Original commit: KhronosGroup/SPIRV-LLVM-Translator@1a1bf17d9e8684c
1 parent da0dce7 commit 1317266

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2181,7 +2181,22 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
21812181
}
21822182
case OpCopyLogical: {
21832183
SPIRVCopyLogical *CL = static_cast<SPIRVCopyLogical *>(BV);
2184-
return mapValue(BV, transSPIRVBuiltinFromInst(CL, BB));
2184+
2185+
auto *SrcTy = transType(CL->getOperand()->getType());
2186+
auto *DstTy = transType(CL->getType());
2187+
2188+
assert(M->getDataLayout().getTypeStoreSize(SrcTy).getFixedValue() ==
2189+
M->getDataLayout().getTypeStoreSize(DstTy).getFixedValue() &&
2190+
"Size mismatch in OpCopyLogical");
2191+
2192+
IRBuilder<> Builder(BB);
2193+
2194+
auto *SrcAI = Builder.CreateAlloca(SrcTy);
2195+
Builder.CreateAlignedStore(transValue(CL->getOperand(), F, BB), SrcAI,
2196+
SrcAI->getAlign());
2197+
2198+
auto *LI = Builder.CreateAlignedLoad(DstTy, SrcAI, SrcAI->getAlign());
2199+
return mapValue(BV, LI);
21852200
}
21862201

21872202
case OpAccessChain:

llvm-spirv/test/OpCopyLogical.spvasm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@
2222
OpReturn
2323
OpFunctionEnd
2424

25-
; CHECK-LLVM: @_Z19__spirv_CopyLogical12structtype.0(ptr sret(%structtype) %[[#]], %structtype.0 zeroinitializer)
25+
; CHECK-LLVM: [[ALLOCA:%[a-z0-9.]+]] = alloca [[SRC_TYPE:%[a-z0-9.]+]], align 8
26+
; CHECK-LLVM: store [[SRC_TYPE]] zeroinitializer, ptr [[ALLOCA]], align 8
27+
; CHECK-LLVM: [[DST:%[a-z0-9.]+]] = load [[DST_TYPE:%[a-z0-9.]+]], ptr [[ALLOCA]], align 8

0 commit comments

Comments
 (0)