Skip to content

Commit 715592b

Browse files
bashbaugsvenvh
authored andcommitted
[Backport to 17] Generate load and store for OpCopyLogical (#2825)
fixes #2768 Generate an LLVM memcpy for OpCopyLogical, rather than a call to an OpCopyLogical function. (cherry picked from commit 1a1bf17)
1 parent ac9403c commit 715592b

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/SPIRV/SPIRVReader.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2232,7 +2232,22 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
22322232
}
22332233
case OpCopyLogical: {
22342234
SPIRVCopyLogical *CL = static_cast<SPIRVCopyLogical *>(BV);
2235-
return mapValue(BV, transSPIRVBuiltinFromInst(CL, BB));
2235+
2236+
auto *SrcTy = transType(CL->getOperand()->getType());
2237+
auto *DstTy = transType(CL->getType());
2238+
2239+
assert(M->getDataLayout().getTypeStoreSize(SrcTy).getFixedValue() ==
2240+
M->getDataLayout().getTypeStoreSize(DstTy).getFixedValue() &&
2241+
"Size mismatch in OpCopyLogical");
2242+
2243+
IRBuilder<> Builder(BB);
2244+
2245+
auto *SrcAI = Builder.CreateAlloca(SrcTy);
2246+
Builder.CreateAlignedStore(transValue(CL->getOperand(), F, BB), SrcAI,
2247+
SrcAI->getAlign());
2248+
2249+
auto *LI = Builder.CreateAlignedLoad(DstTy, SrcAI, SrcAI->getAlign());
2250+
return mapValue(BV, LI);
22362251
}
22372252

22382253
case OpAccessChain:

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)