Skip to content

Commit

Permalink
[Backport to 16] 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.

(cherry picked from commit 1a1bf17)
  • Loading branch information
bashbaug authored and svenvh committed Nov 25, 2024
1 parent e8c6a83 commit 2577a32
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
17 changes: 16 additions & 1 deletion lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2158,7 +2158,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
6 changes: 4 additions & 2 deletions test/OpCopyLogical.spvasm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 2577a32

Please sign in to comment.