Skip to content

Commit

Permalink
Fix llvm.frexp intrinsic translation with SPV_KHR_untyped_pointers (#…
Browse files Browse the repository at this point in the history
…2818)
  • Loading branch information
vmaksimo authored Oct 30, 2024
1 parent 8dc0349 commit e3b9ba3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
18 changes: 16 additions & 2 deletions lib/SPIRV/SPIRVWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2243,7 +2243,15 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
auto *FrexpResult = transValue(RV, BB);
SPIRVValue *IntFromFrexpResult =
static_cast<SPIRVExtInst *>(FrexpResult)->getArgValues()[1];
IntFromFrexpResult = BM->addLoadInst(IntFromFrexpResult, {}, BB);
SPIRVType *LoadTy = nullptr;

if (IntFromFrexpResult->isUntypedVariable()) {
auto *BV =
static_cast<SPIRVUntypedVariableKHR *>(IntFromFrexpResult);
LoadTy = BV->getDataType();
}
IntFromFrexpResult =
BM->addLoadInst(IntFromFrexpResult, {}, BB, LoadTy);

std::vector<SPIRVId> Operands = {FrexpResult->getId(),
IntFromFrexpResult->getId()};
Expand Down Expand Up @@ -2462,7 +2470,13 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
// Idx = 1
SPIRVValue *IntFromFrexpResult =
static_cast<SPIRVExtInst *>(Val)->getArgValues()[1];
IntFromFrexpResult = BM->addLoadInst(IntFromFrexpResult, {}, BB);
SPIRVType *LoadTy = nullptr;
if (IntFromFrexpResult->isUntypedVariable()) {
auto *BV = static_cast<SPIRVUntypedVariableKHR *>(IntFromFrexpResult);
LoadTy = BV->getDataType();
}
IntFromFrexpResult =
BM->addLoadInst(IntFromFrexpResult, {}, BB, LoadTy);
return mapValue(V, IntFromFrexpResult);
}
}
Expand Down
15 changes: 12 additions & 3 deletions test/llvm-intrinsics/frexp.ll
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
; RUN: llvm-as %s -o %t.bc
; RUN: llvm-spirv %t.bc -spirv-text
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
; RUN: FileCheck < %t.spt %s --check-prefixes=CHECK-SPIRV,CHECK-SPIRV-TYPED-PTR
; RUN: llvm-spirv %t.bc -o %t.spv
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
; RUN: llvm-dis %t.rev.bc
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM

; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_KHR_untyped_pointers -spirv-text -o %t.spt
; RUN: FileCheck < %t.spt %s --check-prefixes=CHECK-SPIRV,CHECK-SPIRV-UNTYPED-PTR
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_KHR_untyped_pointers -o %t.spv
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
; RUN: llvm-dis %t.rev.bc
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir64-unknown-unknown"

Expand All @@ -14,7 +21,8 @@ target triple = "spir64-unknown-unknown"
; CHECK-SPIRV: TypeInt [[#TypeInt:]] 32
; CHECK-SPIRV: TypeFloat [[#TypeFloat:]] 32
; CHECK-SPIRV: TypeStruct [[#TypeStrFloatInt:]] [[#TypeFloat]] [[#TypeInt]]
; CHECK-SPIRV: TypePointer [[#TypeIntPtr:]] 7 [[#TypeInt]]
; CHECK-SPIRV-TYPED-PTR: TypePointer [[#TypeIntPtr:]] 7 [[#TypeInt]]
; CHECK-SPIRV-UNTYPED-PTR: TypeUntypedPointerKHR [[#TypePtr:]] 7

; CHECK-SPIRV: TypeFloat [[#TypeDouble:]] 64
; CHECK-SPIRV: TypeStruct [[#TypeStrDoubleInt:]] [[#TypeDouble]] [[#TypeInt]]
Expand Down Expand Up @@ -49,7 +57,8 @@ declare { <4 x float>, <4 x i32> } @llvm.frexp.v4f32.v4i32(<4 x float>)
declare { <2 x double>, <2 x i32> } @llvm.frexp.v2f64.v2i32(<2 x double>)

; CHECK-SPIRV: Function [[#TypeStrFloatInt:]]
; CHECK-SPIRV: Variable [[#TypeIntPtr]] [[#IntVar:]] 7
; CHECK-SPIRV-TYPED-PTR: Variable [[#TypeIntPtr]] [[#IntVar:]] 7
; CHECK-SPIRV-UNTYPED-PTR: UntypedVariableKHR [[#TypePtr]] [[#IntVar:]] 7 [[#TypeInt]]
; CHECK-SPIRV: ExtInst [[#TypeFloat]] [[#FrexpId:]] [[#ExtInstSetId]] frexp [[#NegatedZeroConst]] [[#IntVar]]
; CHECK-SPIRV: Load [[#]] [[#LoadId:]] [[#]]
; CHECK-SPIRV: CompositeConstruct [[#TypeStrFloatInt]] [[#ComposConstr:]] [[#FrexpId]] [[#LoadId]]
Expand Down

0 comments on commit e3b9ba3

Please sign in to comment.