Issue 139942
Summary [AMDGPU] LLD LTO triggers assertion in “SI Fix SGPR copies” when -O2 or higher is specified
Labels backend:AMDGPU
Assignees
Reporter chichunchen
    Command:
```
lld -flavor gnu --no-undefined -shared -plugin-opt=mcpu=gfx908  -plugin-opt=O2 -o result.amdgpu reduced.bc
```

Reduced.ll:
```
; ModuleID = '<stdin>'
source_filename = "llvm-link"
target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128-p9:192:256:256:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8:9"
target triple = "amdgcn-amd-amdhsa"

; Function Attrs: nofree noinline nosync nounwind memory(write, inaccessiblemem: none)
define amdgpu_kernel void @"e_53_2_$ck_L6_1"(i64 %"$$arg_ptr_acc_x_t9_t201") #0 {
", bb23":
  %"$dev_runtime_t35" = alloca i64, align 8, addrspace(5)
  %"$$ipa_tmp_1_t19" = alloca i32, align 4, addrspace(5)
  %r = addrspacecast ptr addrspace(5) %"$dev_runtime_t35" to ptr
  store i32 25, ptr addrspace(5) %"$$ipa_tmp_1_t19", align 4
  %r4 = addrspacecast ptr addrspace(5) %"$$ipa_tmp_1_t19" to ptr
  %r6 = call i32 @fib_(ptr %r4)
  %r8 = inttoptr i64 %"$$arg_ptr_acc_x_t9_t201" to ptr addrspace(1)
  store i32 %r6, ptr addrspace(1) %r8, align 4
  ret void
}

; Function Attrs: alwaysinline nofree nosync nounwind memory(argmem: read)
define i32 @fib_(ptr noalias nocapture readonly %n) #1 {
", bb1":
  %"t$5" = alloca i32, align 4, addrspace(5)
  %"t$3" = alloca i32, align 4, addrspace(5)
  %r3 = load i32, ptr %n, align 4
  %r5 = icmp sgt i32 %r3, 0
  %r9.not = icmp eq i32 %r3, 1
  br i1 %r9.not, label %"l$00002", label %"l$00003"

"l$00003":                                        ; preds = %", bb1"
  %r13 = add nsw i32 %r3, -1
  store i32 %r13, ptr addrspace(5) %"t$3", align 4
  %r14 = addrspacecast ptr addrspace(5) %"t$3" to ptr
  %r15 = call i32 @fib_(ptr %r14)
  %r17 = add nsw i32 %r3, -2
  store i32 %r17, ptr addrspace(5) %"t$5", align 4
  %r18 = addrspacecast ptr addrspace(5) %"t$5" to ptr
  %r19 = call i32 @fib_(ptr %r18)
  %r22 = add i32 %r15, %r19
  br label %"l$00002"

"l$00002":                                        ; preds = %"l$00003", %", bb1"
  %"$f_s3.0" = phi i32 [ %r22, %"l$00003" ], [ 1, %", bb1" ]
  ret i32 %"$f_s3.0"
}

attributes #0 = { nofree noinline nosync nounwind memory(write, inaccessiblemem: none) "amdgpu-flat-work-group-size"="1,1" "amdgpu-no-completion-action" "target-cpu"="gfx908" "uniform-work-group-size"="true" }
attributes #1 = { alwaysinline nofree nosync nounwind memory(argmem: read) "target-cpu"="gfx908" }

!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 4, !"Dwarf Version", i32 5}
!2 = !{i32 1, !"amdhsa_code_object_version", i32 500}
!3 = !{i32 1, !"wchar_size", i32 4}
!4 = !{i32 8, !"PIC Level", i32 0}
!5 = !{i32 7, !"openmp", i32 51}
!6 = !{i32 7, !"openmp-device", i32 51}
!7 = !{i32 1, !"ThinLTO", i32 0}
!8 = !{i32 1, !"EnableSplitLTOUnit", i32 1}
!9 = !{i32 1, !"amdgpu_printf_kind", !"hostcall"}
```

Error message:
```
lld: /ptmp2/cchen/hpc-pe-cce-cce/llvm/include/llvm/ADT/ilist_iterator.h:168: llvm::ilist_iterator<OptionsT, IsReverse, IsConst>::reference llvm::ilist_iterator<OptionsT, IsReverse, IsConst>::operator*() const [with OptionsT = llvm::ilist_detail::node_options<llvm::MachineInstr, true, true, void, false, void>; bool IsReverse = false; bool IsConst = false; reference = llvm::MachineInstr&]: Assertion `!NodePtr->isKnownSentinel()' failed.
PLEASE submit a bug report to HPE at https://support.hpe.com/ and include the crash backtrace.
Stack dump:
0.      Program arguments: lld -flavor gnu --no-undefined -shared -plugin-opt=mcpu=gfx908 -plugin-opt=O2 -o result.amdgpu reduced.bc
1.      Running pass 'CallGraph Pass Manager' on module 'ld-temp.o'.
2.      Running pass 'SI Fix SGPR copies' on function '@fib_.internalized'
 #0 0x00007f46e38d8735 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /ptmp2/cchen/hpc-pe-cce-cce/llvm/lib/Support/Unix/Signals.inc:798:22
 #1 0x00007f46e38d8b7d PrintStackTraceSignalHandler(void*) /ptmp2/cchen/hpc-pe-cce-cce/llvm/lib/Support/Unix/Signals.inc:873:23
 #2 0x00007f46e38d6299 llvm::sys::RunSignalHandlers() /ptmp2/cchen/hpc-pe-cce-cce/llvm/lib/Support/Signals.cpp:104:22
 #3 0x00007f46e38d810a SignalHandler(int) /ptmp2/cchen/hpc-pe-cce-cce/llvm/lib/Support/Unix/Signals.inc:405:31
 #4 0x00007f46e2e578ff (/lib64/libc.so.6+0x578ff)
 #5 0x00007f46e2ea8dfb __pthread_kill_implementation (/lib64/libc.so.6+0xa8dfb)
 #6 0x00007f46e2e57841 gsignal (/lib64/libc.so.6+0x57841)
 #7 0x00007f46e2e3f5ce abort (/lib64/libc.so.6+0x3f5ce)
 #8 0x00007f46e2e3f4e6 __assert_fail_base.cold (/lib64/libc.so.6+0x3f4e6)
 #9 0x00007f46e2e4fb31 __assert_fail (/lib64/libc.so.6+0x4fb31)
#10 0x00007f46e0e39031 llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::MachineInstr, true, true, void, false, void>, false, false>::operator*() const /ptmp2/cchen/hpc-pe-cce-cce/llvm/include/llvm/ADT/ilist_iterator.h:168:5
#11 0x00007f46e0e376f1 llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>::operator*() const /ptmp2/cchen/hpc-pe-cce-cce/llvm/include/llvm/CodeGen/MachineInstrBundleIterator.h:178:40
#12 0x00007f46e0e7be11 llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>::operator->() const /ptmp2/cchen/hpc-pe-cce-cce/llvm/include/llvm/CodeGen/MachineInstrBundleIterator.h:179:49
#13 0x00007f46e1489981 (anonymous namespace)::SIFixSGPRCopies::run(llvm::MachineFunction&) /ptmp2/cchen/hpc-pe-cce-cce/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp:685:0
#14 0x00007f46e14871b5 (anonymous namespace)::SIFixSGPRCopiesLegacy::runOnMachineFunction(llvm::MachineFunction&) /ptmp2/cchen/hpc-pe-cce-cce/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp:171:0
#15 0x00007f46d8b925d2 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /ptmp2/cchen/hpc-pe-cce-cce/llvm/lib/CodeGen/MachineFunctionPass.cpp:100:33
#16 0x00007f46dac72f7c llvm::FPPassManager::runOnFunction(llvm::Function&) /ptmp2/cchen/hpc-pe-cce-cce/llvm/lib/IR/LegacyPassManager.cpp:1481:40
#17 0x00007f46d485d0b8 (anonymous namespace)::CGPassManager::RunPassOnSCC(llvm::Pass*, llvm::CallGraphSCC&, llvm::CallGraph&, bool&, bool&) /ptmp2/cchen/hpc-pe-cce-cce/llvm/lib/Analysis/CallGraphSCCPass.cpp:182:38
#18 0x00007f46d485e0af (anonymous namespace)::CGPassManager::RunAllPassesOnSCC(llvm::CallGraphSCC&, llvm::CallGraph&, bool&) /ptmp2/cchen/hpc-pe-cce-cce/llvm/lib/Analysis/CallGraphSCCPass.cpp:471:21
#19 0x00007f46d485e3a8 (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) /ptmp2/cchen/hpc-pe-cce-cce/llvm/lib/Analysis/CallGraphSCCPass.cpp:536:35
#20 0x00007f46dac735f4 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /ptmp2/cchen/hpc-pe-cce-cce/llvm/lib/IR/LegacyPassManager.cpp:1596:38
#21 0x00007f46dac6e4ea llvm::legacy::PassManagerImpl::run(llvm::Module&) /ptmp2/cchen/hpc-pe-cce-cce/llvm/lib/IR/LegacyPassManager.cpp:562:55
#22 0x00007f46dac73e1e llvm::legacy::PassManager::run(llvm::Module&) /ptmp2/cchen/hpc-pe-cce-cce/llvm/lib/IR/LegacyPassManager.cpp:1723:17
#23 0x00007f46de0e5656 codegen(llvm::lto::Config const&, llvm::TargetMachine*, std::function<llvm::Expected<std::unique_ptr<llvm::CachedFileStream, std::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>, unsigned int, llvm::Module&, llvm::ModuleSummaryIndex const&) /ptmp2/cchen/hpc-pe-cce-cce/llvm/lib/LTO/LTOBackend.cpp:476:20
#24 0x00007f46de0e610c llvm::lto::backend(llvm::lto::Config const&, std::function<llvm::Expected<std::unique_ptr<llvm::CachedFileStream, std::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>, unsigned int, llvm::Module&, llvm::ModuleSummaryIndex&) /ptmp2/cchen/hpc-pe-cce-cce/llvm/lib/LTO/LTOBackend.cpp:580:12
#25 0x00007f46de076b5b llvm::lto::LTO::runRegularLTO(std::function<llvm::Expected<std::unique_ptr<llvm::CachedFileStream, std::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>) /ptmp2/cchen/hpc-pe-cce-cce/llvm/lib/LTO/LTO.cpp:1420:70
#26 0x00007f46de075b77 llvm::lto::LTO::run(std::function<llvm::Expected<std::unique_ptr<llvm::CachedFileStream, std::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>, llvm::FileCache) /ptmp2/cchen/hpc-pe-cce-cce/llvm/lib/LTO/LTO.cpp:1252:41
#27 0x00007f46e485f452 lld::elf::BitcodeCompiler::compile() /ptmp2/cchen/hpc-pe-cce-cce/lld/ELF/LTO.cpp:335:34
#28 0x00007f46e477bba6 void lld::elf::LinkerDriver::compileBitcodeFiles<llvm::object::ELFType<(llvm::endianness)1, true>>(bool) /ptmp2/cchen/hpc-pe-cce-cce/lld/ELF/Driver.cpp:2590:18
#29 0x00007f46e476c813 void lld::elf::LinkerDriver::link<llvm::object::ELFType<(llvm::endianness)1, true>>(llvm::opt::InputArgList&) /ptmp2/cchen/hpc-pe-cce-cce/lld/ELF/Driver.cpp:3082:28
#30 0x00007f46e473d8e4 lld::elf::LinkerDriver::linkerMain(llvm::ArrayRef<char const*>) /ptmp2/cchen/hpc-pe-cce-cce/lld/ELF/Driver.cpp:672:5
#31 0x00007f46e4738df3 lld::elf::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool) /ptmp2/cchen/hpc-pe-cce-cce/lld/ELF/Driver.cpp:142:24
#32 0x00007f46e4d96f09 lld::unsafeLldMain(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, llvm::ArrayRef<lld::DriverDef>, bool) /ptmp2/cchen/hpc-pe-cce-cce/lld/Common/DriverDispatcher.cpp:163:13
#33 0x00000000004030b4 lld_main(int, char**, llvm::ToolContext const&) /ptmp2/cchen/hpc-pe-cce-cce/lld/tools/lld/lld.cpp:90:27
#34 0x000000000040601c main /ptmp2/cchen/hpc-pe-cce-cce/build/20/cmake/tools/lld/tools/lld/lld-driver.cpp:17:18
#35 0x00007f46e2e40e6b __libc_start_call_main (/lib64/libc.so.6+0x40e6b)
#36 0x00007f46e2e40f34 __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x40f34)
#37 0x0000000000402e00 _start /home/abuild/rpmbuild/BUILD/glibc-2.38/csu/../sysdeps/x86_64/start.S:115:0
Aborted (core dumped)
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to