Skip to content

Commit 5202e9c

Browse files
MrSidimsAlexeySotkin
authored andcommitted
Fix type mapping for pointers with Device/HostOnlyINTEL storage classes
a7b763b265d introduces a bug, when it could be possible to map a single pointer type in LLVM IR to two different pointer types in SPIR-V (when SPV_INTEL_usm_storage_classes extension is not allowed). This patch fixes this bug. Signed-off-by: Dmitry Sidorov <[email protected]>
1 parent 70a3c5f commit 5202e9c

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,11 @@ SPIRVType *LLVMToSPIRV::transType(Type *T) {
304304
// extension
305305
if (!BM->isAllowedToUseExtension(
306306
ExtensionID::SPV_INTEL_usm_storage_classes) &&
307-
((AddrSpc == SPIRAS_GlobalDevice) || (AddrSpc == SPIRAS_GlobalHost)))
308-
AddrSpc = SPIRAS_Global;
307+
((AddrSpc == SPIRAS_GlobalDevice) || (AddrSpc == SPIRAS_GlobalHost))) {
308+
auto NewType =
309+
PointerType::get(T->getPointerElementType(), SPIRAS_Global);
310+
return mapType(T, transType(NewType));
311+
}
309312
if (ST && !ST->isSized()) {
310313
Op OpCode;
311314
StringRef STName = ST->getName();

lib/SPIRV/libSPIRV/SPIRVInstruction.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -538,15 +538,9 @@ class SPIRVStore : public SPIRVInstruction, public SPIRVMemoryAccess {
538538
SPIRVInstruction::validate();
539539
if (getSrc()->isForward() || getDst()->isForward())
540540
return;
541-
#ifndef NDEBUG
542-
if (getValueType(PtrId)->getPointerElementType() != getValueType(ValId)) {
543-
assert(getValueType(PtrId)
544-
->getPointerElementType()
545-
->getPointerStorageClass() ==
546-
getValueType(ValId)->getPointerStorageClass() &&
547-
"Inconsistent operand types");
548-
}
549-
#endif // NDEBUG
541+
assert(getValueType(PtrId)->getPointerElementType() ==
542+
getValueType(ValId) &&
543+
"Inconsistent operand types");
550544
}
551545

552546
private:

test/transcoding/intel_usm_addrspaces.ll

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
; CHECK-SPIRV: Name [[HOST_ARG2:[0-9]+]] "arg_host.addr"
2424
; CHECK-SPIRV-EXT: TypePointer [[DEVICE_TY:[0-9]+]] 5936 {{[0-9]+}}
2525
; CHECK-SPIRV-EXT: TypePointer [[HOST_TY:[0-9]+]] 5937 {{[0-9]+}}
26-
; CHECK-SPIRV-NO-EXT: TypePointer [[DEVICE_TY:[0-9]+]] 5 {{[0-9]+}}
27-
; CHECK-SPIRV-NO-EXT: TypePointer [[HOST_TY:[0-9]+]] 5 {{[0-9]+}}
28-
; CHECK-SPIRV: Load [[DEVICE_TY]] {{[0-9]+}} [[DEVICE]] {{[0-9]+}} {{[0-9]+}}
29-
; CHECK-SPIRV: Load [[HOST_TY]] {{[0-9]+}} [[HOST]] {{[0-9]+}} {{[0-9]+}}
26+
; CHECK-SPIRV-NO-EXT: TypePointer [[GLOB_TY:[0-9]+]] 5 {{[0-9]+}}
27+
; CHECK-SPIRV-EXT: Load [[DEVICE_TY]] {{[0-9]+}} [[DEVICE]] {{[0-9]+}} {{[0-9]+}}
28+
; CHECK-SPIRV-EXT: Load [[HOST_TY]] {{[0-9]+}} [[HOST]] {{[0-9]+}} {{[0-9]+}}
29+
; CHECK-SPIRV-NO-EXT: Load [[GLOB_TY]] {{[0-9]+}} [[DEVICE]] {{[0-9]+}} {{[0-9]+}}
30+
; CHECK-SPIRV-NO-EXT: Load [[GLOB_TY]] {{[0-9]+}} [[HOST]] {{[0-9]+}} {{[0-9]+}}
3031

3132
; ModuleID = 'intel_usm_addrspaces.cpp'
3233
source_filename = "intel_usm_addrspaces.cpp"

0 commit comments

Comments
 (0)