diff --git a/lib/SPIRV/SPIRVReader.cpp b/lib/SPIRV/SPIRVReader.cpp index a7c8e9c29..81427e5df 100644 --- a/lib/SPIRV/SPIRVReader.cpp +++ b/lib/SPIRV/SPIRVReader.cpp @@ -2178,7 +2178,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 a8874c596..72a5de860 100644 --- a/test/OpCopyLogical.spvasm +++ b/test/OpCopyLogical.spvasm @@ -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