Skip to content

Commit

Permalink
Generate load and store for OpCopyLogical (#2825)
Browse files Browse the repository at this point in the history
fixes #2768

Generate an LLVM memcpy for OpCopyLogical, rather than a call to an OpCopyLogical function.
  • Loading branch information
bashbaug authored Nov 8, 2024
1 parent 69f65ef commit 1a1bf17
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 16 additions & 1 deletion lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2178,7 +2178,22 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
}
case OpCopyLogical: {
SPIRVCopyLogical *CL = static_cast<SPIRVCopyLogical *>(BV);
return mapValue(BV, transSPIRVBuiltinFromInst(CL, BB));

auto *SrcTy = transType(CL->getOperand()->getType());
auto *DstTy = transType(CL->getType());

assert(M->getDataLayout().getTypeStoreSize(SrcTy).getFixedValue() ==
M->getDataLayout().getTypeStoreSize(DstTy).getFixedValue() &&
"Size mismatch in OpCopyLogical");

IRBuilder<> Builder(BB);

auto *SrcAI = Builder.CreateAlloca(SrcTy);
Builder.CreateAlignedStore(transValue(CL->getOperand(), F, BB), SrcAI,
SrcAI->getAlign());

auto *LI = Builder.CreateAlignedLoad(DstTy, SrcAI, SrcAI->getAlign());
return mapValue(BV, LI);
}

case OpAccessChain:
Expand Down
4 changes: 3 additions & 1 deletion test/OpCopyLogical.spvasm
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@
OpReturn
OpFunctionEnd

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

0 comments on commit 1a1bf17

Please sign in to comment.