llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.84k stars 11.47k forks source link

[SPIRV] LLVM 18 regression: Assertion failed: ((MI->getOpcode() == SPIRV::OpVariable && i == 3) || Reg2Entry.count(RegOp)) #87315

Closed thewilsonator closed 3 weeks ago

thewilsonator commented 5 months ago

Works with LLVM17, using --print-after-all confirms that the passes done are different

$llc  ./addrspace_new_ocl220_64.ll
Assertion failed: ((MI->getOpcode() == SPIRV::OpVariable && i == 3) || Reg2Entry.count(RegOp)), function buildDepsGraph, file SPIRVDuplicatesTracker.cpp, line 59.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.  Program arguments: ../../../llvm/llvm-build/bin/llc ./addrspace_new_ocl220_64.ll
1.  Running pass 'SPIRV module analysis' on module './addrspace_new_ocl220_64.ll'.
 #0 0x0000000105027984 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/Users/nicholaswilson/d/llvm/llvm-build/bin/llc+0x102cab984)
 #1 0x0000000105027f34 PrintStackTraceSignalHandler(void*) (/Users/nicholaswilson/d/llvm/llvm-build/bin/llc+0x102cabf34)
 #2 0x0000000105025bfc llvm::sys::RunSignalHandlers() (/Users/nicholaswilson/d/llvm/llvm-build/bin/llc+0x102ca9bfc)
 #3 0x0000000105029050 SignalHandler(int) (/Users/nicholaswilson/d/llvm/llvm-build/bin/llc+0x102cad050)
 #4 0x000000018fa1aa24 (/usr/lib/system/libsystem_platform.dylib+0x18042ea24)
 #5 0x000000018f9ebc28 (/usr/lib/system/libsystem_pthread.dylib+0x1803ffc28)
 #6 0x000000018f8f9ae8 (/usr/lib/system/libsystem_c.dylib+0x18030dae8)
 #7 0x000000018f8f8e44 (/usr/lib/system/libsystem_c.dylib+0x18030ce44)
 #8 0x0000000102ae2b9c llvm::SPIRVGeneralDuplicatesTracker::buildDepsGraph(std::__1::vector<llvm::SPIRV::DTSortableEntry*, std::__1::allocator<llvm::SPIRV::DTSortableEntry*>>&, llvm::MachineModuleInfo*) (/Users/nicholaswilson/d/llvm/llvm-build/bin/llc+0x100766b9c)
 #9 0x0000000102b3100c llvm::SPIRVGlobalRegistry::buildDepsGraph(std::__1::vector<llvm::SPIRV::DTSortableEntry*, std::__1::allocator<llvm::SPIRV::DTSortableEntry*>>&, llvm::MachineModuleInfo*) (/Users/nicholaswilson/d/llvm/llvm-build/bin/llc+0x1007b500c)
#10 0x0000000102b30d3c llvm::SPIRVModuleAnalysis::processDefInstrs(llvm::Module const&) (/Users/nicholaswilson/d/llvm/llvm-build/bin/llc+0x1007b4d3c)
#11 0x0000000102b34eec llvm::SPIRVModuleAnalysis::runOnModule(llvm::Module&) (/Users/nicholaswilson/d/llvm/llvm-build/bin/llc+0x1007b8eec)
#12 0x00000001041c5930 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) (/Users/nicholaswilson/d/llvm/llvm-build/bin/llc+0x101e49930)
#13 0x00000001041c54ac llvm::legacy::PassManagerImpl::run(llvm::Module&) (/Users/nicholaswilson/d/llvm/llvm-build/bin/llc+0x101e494ac)
#14 0x00000001041cc4b0 llvm::legacy::PassManager::run(llvm::Module&) (/Users/nicholaswilson/d/llvm/llvm-build/bin/llc+0x101e504b0)
#15 0x000000010238468c compileModule(char**, llvm::LLVMContext&) (/Users/nicholaswilson/d/llvm/llvm-build/bin/llc+0x10000868c)
#16 0x000000010238293c main (/Users/nicholaswilson/d/llvm/llvm-build/bin/llc+0x10000693c)
#17 0x000000018f693f28
zsh: abort      ../../../llvm/llvm-build/bin/llc ./addrspace_new_ocl220_64.ll

The file in question:

; ModuleID = 'dcomputeTargetOCL'
[llvm18.txt](https://github.com/llvm/llvm-project/files/14831992/llvm18.txt)

source_filename = "dcomputeTargetOCL"
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024"
target triple = "spirv64-unknown-unknown"

%"ldc.dcompute.Pointer!(AddrSpace.Global, float).Pointer" = type { ptr addrspace(1) }

; [#uses = 0]
define spir_func void @_D26dcompute_cl_addrspaces_new3fooFS3ldc8dcompute__T7PointerVEQBaQz9AddrSpacei1TfZQBeZv(ptr addrspace(1) %f_arg) {
  %f = alloca %"ldc.dcompute.Pointer!(AddrSpace.Global, float).Pointer", align 8 ; [#uses = 2, size/byte = 8]
  %g = alloca float, align 4                      ; [#uses = 1, size/byte = 4]
  %1 = getelementptr inbounds %"ldc.dcompute.Pointer!(AddrSpace.Global, float).Pointer", ptr %f, i32 0, i32 0 ; [#uses = 1, type = ptr]
  store ptr addrspace(1) %f_arg, ptr %1, align 8
  %2 = getelementptr inbounds %"ldc.dcompute.Pointer!(AddrSpace.Global, float).Pointer", ptr %f, i32 0, i32 0 ; [#uses = 1, type = ptr]
  %3 = load ptr addrspace(1), ptr %2, align 8     ; [#uses = 1]
  %4 = load float, ptr addrspace(1) %3, align 4   ; [#uses = 1]
  store float %4, ptr %g, align 4
  ret void
}

!opencl.spir.version = !{!0}
!opencl.ocl.version = !{!1}

!0 = !{i32 1, i32 2}
!1 = !{i32 2, i32 2}

Attached is the output of llc -O0 --print-after-all ./addrspace_new_ocl220_64.ll llvm18.txt

Please let me know if there is any thing else I need to do, thanks!

thewilsonator commented 3 months ago

Git bisect shows ec7baca17e78d47c1571d1c06b95f920562293da as the regressing commit Differential Revision: https://reviews.llvm.org/D156049

cc @michalpaszkowski as the author of that commit

michalpaszkowski commented 3 weeks ago

Hi @thewilsonator! Thanks for submitting the issue and sorry for taking so long to respond, I must have overlooked this one! Please do not hesitate to send me an email in urgent cases!

I have tried to reproduce the issue with the top of the main branch build of the SPIR-V backend (7c4c72b5), but it seems to be compiling just fine now and the output SPIR-V passes validation with the Khronos' spirv-val. Would you be able to confirm this? Please reopen if the issue still persists.

thewilsonator commented 3 weeks ago

Thanks, no problem. It only showed up under debug builds and the generated SPIRV seemed to be valid then.

I can confirm that with the tip of main with Debug build of LLVM, this no longer asserts.