Skip to content

Commit 326f12d

Browse files
MrSidimsvladimirlaz
authored andcommitted
Fix type mapping for pointers with Device/HostOnlyINTEL storage classes
a7b763b 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 a2d863f commit 326f12d

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,11 @@ SPIRVType *LLVMToSPIRV::transType(Type *T) {
308308
// extension
309309
if (!BM->isAllowedToUseExtension(
310310
ExtensionID::SPV_INTEL_usm_storage_classes) &&
311-
((AddrSpc == SPIRAS_GlobalDevice) || (AddrSpc == SPIRAS_GlobalHost)))
312-
AddrSpc = SPIRAS_Global;
311+
((AddrSpc == SPIRAS_GlobalDevice) || (AddrSpc == SPIRAS_GlobalHost))) {
312+
auto NewType =
313+
PointerType::get(T->getPointerElementType(), SPIRAS_Global);
314+
return mapType(T, transType(NewType));
315+
}
313316
if (ST && !ST->isSized()) {
314317
Op OpCode;
315318
StringRef STName = ST->getName();

llvm-spirv/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:

llvm-spirv/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)