From 2577a32954262c5e454c508fb6327ce6f2884aef Mon Sep 17 00:00:00 2001 From: Ben Ashbaugh Date: Fri, 8 Nov 2024 13:09:51 -0800 Subject: [PATCH] [Backport to 16] 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 1a1bf17d9e8684cd826e4278e78f63aa80e2e2ca) --- lib/SPIRV/SPIRVReader.cpp | 17 ++++++++++++++++- test/OpCopyLogical.spvasm | 6 ++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/SPIRV/SPIRVReader.cpp b/lib/SPIRV/SPIRVReader.cpp index 0bc451ac26..8f6e6fa669 100644 --- a/lib/SPIRV/SPIRVReader.cpp +++ b/lib/SPIRV/SPIRVReader.cpp @@ -2158,7 +2158,22 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F, } case OpCopyLogical: { SPIRVCopyLogical *CL = static_cast(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: diff --git a/test/OpCopyLogical.spvasm b/test/OpCopyLogical.spvasm index a8874c5961..7af03a1d69 100644 --- a/test/OpCopyLogical.spvasm +++ b/test/OpCopyLogical.spvasm @@ -3,7 +3,7 @@ ; REQUIRES: spirv-as ; RUN: spirv-as --target-env spv1.4 -o %t.spv %s ; RUN: spirv-val %t.spv -; RUN: llvm-spirv -r %t.spv -o %t.rev.bc +; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv -o %t.rev.bc ; RUN: llvm-dis %t.rev.bc ; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM OpCapability Addresses @@ -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