llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-backend-spir-v Author: Alex Voicu (AlexVlx) <details> <summary>Changes</summary> As part of the target specific lowering finalisation steps we sometimes might create a new type, for bitcasting. A consequence of this is that for certain cases (e.g. for an array) we currently emit generic MIR (e.g. a G_CONSTANT for the array size). This is invalid, as at this point lowering is assumed to have completed, and thus no generic constructs should be left. This change addresses that issue by setting `EmitIR` to `false` where relevant - this required extending the existing pointer creation interface. In the long run we want to move these steps to pre-lowering (as an ominous pre-existing `TODO` states). --- Full diff: https://github.com/llvm/llvm-project/pull/245051.diff 4 Files Affected: - (modified) llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp (+5-5) - (modified) llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h (+4-2) - (modified) llvm/lib/Target/SPIRV/SPIRVISelLowering.cpp (+2-2) - (added) llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_untyped_pointers/do-not-emit-ir-after-lowering.ll (+36) ``````````diff diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp index 019b43f09e1278..099cfc3cd56d00 100644 --- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp +++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp @@ -2064,7 +2064,7 @@ SPIRVTypeInst SPIRVGlobalRegistry::getOrCreateSPIRVPointerType( SPIRVTypeInst SPIRVGlobalRegistry::getOrCreateSPIRVPointerType( const Type *BaseType, MachineIRBuilder &MIRBuilder, - SPIRV::StorageClass::StorageClass SC, bool ForceTyped) { + SPIRV::StorageClass::StorageClass SC, bool ForceTyped, bool EmitIR) { if (BaseType->isFunctionTy() && !cast<SPIRVSubtarget>(MIRBuilder.getMF().getSubtarget()) .canUseExtension(SPIRV::Extension::SPV_INTEL_function_pointers)) { @@ -2075,10 +2075,9 @@ SPIRVTypeInst SPIRVGlobalRegistry::getOrCreateSPIRVPointerType( "SPV_INTEL_function_pointers extension", DebugLoc(), DS_Error)); } - // TODO: Need to check if EmitIr should always be true. SPIRVTypeInst SpirvBaseType = getOrCreateSPIRVType( BaseType, MIRBuilder, SPIRV::AccessQualifier::ReadWrite, - storageClassRequiresExplictLayout(SC), true); + storageClassRequiresExplictLayout(SC), EmitIR); assert(SpirvBaseType); return getOrCreateSPIRVPointerTypeInternal(SpirvBaseType, MIRBuilder, SC, ForceTyped); @@ -2099,10 +2098,11 @@ SPIRVTypeInst SPIRVGlobalRegistry::changePointerStorageClass( SPIRVTypeInst SPIRVGlobalRegistry::getOrCreateSPIRVPointerType( SPIRVTypeInst BaseType, MachineIRBuilder &MIRBuilder, - SPIRV::StorageClass::StorageClass SC) { + SPIRV::StorageClass::StorageClass SC, bool EmitIR) { const Type *LLVMType = getTypeForSPIRVType(BaseType); assert(!storageClassRequiresExplictLayout(SC)); - SPIRVTypeInst R = getOrCreateSPIRVPointerType(LLVMType, MIRBuilder, SC); + SPIRVTypeInst R = getOrCreateSPIRVPointerType(LLVMType, MIRBuilder, SC, false, + EmitIR); assert( (R->getOpcode() == SPIRV::OpTypeUntypedPointerKHR || getPointeeType(R) == BaseType) && diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h index c5dffbf85a0b0e..123e2b029b3622 100644 --- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h +++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h @@ -650,7 +650,8 @@ class SPIRVGlobalRegistry : public SPIRVIRMapping { // See getOrCreateSPIRVPointerTypeInternal for ForceTyped. SPIRVTypeInst getOrCreateSPIRVPointerType( const Type *BaseType, MachineIRBuilder &MIRBuilder, - SPIRV::StorageClass::StorageClass SC, bool ForceTyped = false); + SPIRV::StorageClass::StorageClass SC, bool ForceTyped = false, + bool EmitIR = true); SPIRVTypeInst getOrCreateSPIRVPointerType(const Type *BaseType, MachineInstr &I, SPIRV::StorageClass::StorageClass SC, @@ -674,7 +675,8 @@ class SPIRVGlobalRegistry : public SPIRVIRMapping { SPIRVTypeInst getOrCreateSPIRVPointerType(SPIRVTypeInst BaseType, MachineIRBuilder &MIRBuilder, - SPIRV::StorageClass::StorageClass SC); + SPIRV::StorageClass::StorageClass SC, + bool EmitIR = true); // Returns a pointer to a SPIR-V pointer type that is the same as `PtrType` // except the stroage class has been changed to `SC`. It is the responsibility diff --git a/llvm/lib/Target/SPIRV/SPIRVISelLowering.cpp b/llvm/lib/Target/SPIRV/SPIRVISelLowering.cpp index 322deefada12d7..435d5f318723c0 100644 --- a/llvm/lib/Target/SPIRV/SPIRVISelLowering.cpp +++ b/llvm/lib/Target/SPIRV/SPIRVISelLowering.cpp @@ -226,7 +226,7 @@ static SPIRVTypeInst createNewPtrType(SPIRVGlobalRegistry &GR, MachineInstr &I, ReuseType ? ResType : GR.getOrCreateSPIRVType( ResTy, MIB, SPIRV::AccessQualifier::ReadWrite, false); - return GR.getOrCreateSPIRVPointerType(NewBaseType, MIB, SC); + return GR.getOrCreateSPIRVPointerType(NewBaseType, MIB, SC, false); } // Insert a bitcast before the instruction to keep SPIR-V code valid @@ -337,7 +337,7 @@ static void validatePtrUnwrapStructField(const SPIRVSubtarget &STI, OpType->getOperand(1).getImm()); MachineIRBuilder MIB(I); SPIRVTypeInst NewPtrType = - GR.getOrCreateSPIRVPointerType(MemberType, MIB, SC); + GR.getOrCreateSPIRVPointerType(MemberType, MIB, SC, false); doInsertBitcast(STI, MRI, GR, I, OpReg, OpIdx, NewPtrType); } diff --git a/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_untyped_pointers/do-not-emit-ir-after-lowering.ll b/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_untyped_pointers/do-not-emit-ir-after-lowering.ll new file mode 100644 index 00000000000000..45dcaffea993ab --- /dev/null +++ b/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_untyped_pointers/do-not-emit-ir-after-lowering.ll @@ -0,0 +1,36 @@ +; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv32-unknown-unknown --spirv-ext=+SPV_KHR_untyped_pointers %s -o - | FileCheck %s +; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_KHR_untyped_pointers %s -o - | FileCheck %s +; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown --spirv-ext=+SPV_KHR_untyped_pointers %s -o - -filetype=obj | spirv-val %} +; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_KHR_untyped_pointers %s -o - -filetype=obj | spirv-val %} + +; CHECK: %[[#GenericUntypedPtrTy:]] = OpTypeUntypedPointerKHR Generic +; CHECK-NEXT: %[[#UnionTy:]] = OpTypeStruct %[[#GenericUntypedPtrTy]] +; CHECK-NEXT: %[[#StructTy:]] = OpTypeStruct %[[#UnionTy]] +; CHECK-NEXT: %[[#ConstantStructPtrTy:]] = OpTypePointer UniformConstant %[[#StructTy]] +; CHECK: %[[#ConstantUntypedStructPtrTy:]] = OpTypeUntypedPointerKHR UniformConstant +; CHECK: %[[#PtrToStruct:]] = OpFunctionParameter %[[#ConstantStructPtrTy]] +; CHECK: %[[#BC:]] = OpBitcast %[[#ConstantUntypedStructPtrTy]] %[[#PtrToStruct]] +; CHECK: %[[#]] = OpLoad %[[#GenericUntypedPtrTy]] %[[#BC]] + +%struct.s = type { %union.u } +%union.u = type { ptr addrspace(4) } + +define spir_kernel void @k(ptr addrspace(2) byval(%struct.s) %0) { +entry: + %1 = load ptr addrspace(4), ptr addrspace(2) %0, align 8 + br i1 false, label %cond.true, label %cond.false + +cond.true: + store ptr addrspace(4) %1, ptr addrspace(4) null, align 4 + ret void + +cond.false: + %call5 = call spir_func [2 x i32] @f(ptr addrspace(4) %1) + ret void +} + +define spir_func [2 x i32] @f(ptr addrspace(4) %x) { +entry: + %0 = getelementptr [8 x i8], ptr addrspace(4) %x, i64 0 + ret [2 x i32] zeroinitializer +} `````````` </details> https://github.com/llvm/llvm-project/pull/245051 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
