Issue 63338
Summary Hitting `SIGSEGV` in `AMDGPULowerModuleLDS` pass
Labels new issue
Assignees
Reporter Saldivarcher
    To reproduce:
```console
$ opt --passes="amdgpu-lower-module-lds" reduced.ll
WARNING: You're attempting to print out a bitcode file.
This is inadvisable as it may cause display problems. If
you REALLY want to taste LLVM bitcode first-hand, you
can force output with the `-f' option.

PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /home/users/saldivar/css/upstream/debug/bin/opt --passes=amdgpu-lower-module-lds reduced.ll
 #0 0x000000000a023708 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/users/saldivar/workspace/random/llvm-project.git/main/llvm/lib/Support/Unix/Signals.inc:602:22
 #1 0x000000000a023b02 PrintStackTraceSignalHandler(void*) /home/users/saldivar/workspace/random/llvm-project.git/main/llvm/lib/Support/Unix/Signals.inc:676:1
 #2 0x000000000a0214d7 llvm::sys::RunSignalHandlers() /home/users/saldivar/workspace/random/llvm-project.git/main/llvm/lib/Support/Signals.cpp:104:20
 #3 0x000000000a023137 SignalHandler(int) /home/users/saldivar/workspace/random/llvm-project.git/main/llvm/lib/Support/Unix/Signals.inc:413:1
 #4 0x00007f34edea68c0 __restore_rt (/lib64/libpthread.so.0+0x168c0)
 #5 0x0000000006b0e050 llvm::GlobalValue::getValueType() const /home/users/saldivar/workspace/random/llvm-project.git/main/llvm/include/llvm/IR/GlobalValue.h:292:39
 #6 0x0000000006fee470 (anonymous namespace)::AMDGPULowerModuleLDS::markUsedByKernel(llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>&, llvm::Function*, llvm::GlobalVariable*) /home/users/saldivar/workspace/random/llvm-project.git/main/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp:237:55
 #7 0x0000000006ff28c6 (anonymous namespace)::AMDGPULowerModuleLDS::runOnModule(llvm::Module&) /home/users/saldivar/workspace/random/llvm-project.git/main/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp:1114:7
 #8 0x0000000006ff42db llvm::AMDGPULowerModuleLDSPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/users/saldivar/workspace/random/llvm-project.git/main/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp:1492:48
 #9 0x0000000006f428d8 llvm::detail::PassModel<llvm::Module, llvm::AMDGPULowerModuleLDSPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/users/saldivar/workspace/random/llvm-project.git/main/llvm/include/llvm/IR/PassManagerInternal.h:90:3
#10 0x00000000097114f8 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/users/saldivar/workspace/random/llvm-project.git/main/llvm/include/llvm/IR/PassManager.h:521:20
#11 0x0000000006703a78 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool) /home/users/saldivar/workspace/random/llvm-project.git/main/llvm/tools/opt/NewPMDriver.cpp:522:10
#12 0x000000000673090d main /home/users/saldivar/workspace/random/llvm-project.git/main/llvm/tools/opt/opt.cpp:716:27
#13 0x00007f34ed0ed24d __libc_start_main (/lib64/libc.so.6+0x3524d)
#14 0x00000000066fb9ea _start /home/abuild/rpmbuild/BUILD/glibc-2.31/csu/../sysdeps/x86_64/start.S:122:0
fish: Job 1, '~/css/upstream/debug/bin/opt --…' terminated by signal SIGSEGV (Address boundary error)

$ cat reduced.ll
; ModuleID = 'bugpoint-reduced-simplified.bc'
source_filename = "reproduce.cpp"
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-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"
target triple = "amdgcn-amd-amdhsa"

$_ZN4Impl32hip_parallel_launch_local_memoryINS_14ParallelReduceIi11RangePolicyIJ3HIPEE6MinMaxINS_16ViewDataAnalysisIiiEEEEELi0ELi0EEEvT_ = comdat any

$_ZN4Impl14ParallelReduceIi11RangePolicyIJ3HIPEE6MinMaxINS_16ViewDataAnalysisIiiEEEEclEv = comdat any

$_ZN4Impl33hip_inter_block_shuffle_reductionIN15FunctorAnalysisI23FunctorPatternInterface11RangePolicyIJ3HIPEE6MinMaxINS_16ViewDataAnalysisIiiEEEE7ReducerEEEbNT_14reference_typeESD_SC_PjNSC_12pointer_typeESE_i = comdat any

$_ZN4Impl33hip_intra_block_shuffle_reductionIiN15FunctorAnalysisI23FunctorPatternInterface11RangePolicyIJ3HIPEE6MinMaxINS_16ViewDataAnalysisIiiEEEE7ReducerEEEvT_T0_ = comdat any

$_ZN4Impl32hip_inter_warp_shuffle_reductionIiN15FunctorAnalysisI23FunctorPatternInterface11RangePolicyIJ3HIPEE6MinMaxINS_16ViewDataAnalysisIiiEEEE7ReducerEEEvT_T0_ = comdat any

$_ZN4Impl32hip_parallel_launch_local_memoryINS_12ParallelScanI7BinSortI4ViewIPiJ3HIPEEPFvvEE11RangePolicyIJS5_EEEELi0ELi0EEEvT_ = comdat any

$_ZN4Impl19ParallelScanHIPBaseI7BinSortI4ViewIPiJ3HIPEEPFvvEEJS4_EEclEv = comdat any

$_ZN4Impl19ParallelScanHIPBaseI7BinSortI4ViewIPiJ3HIPEEPFvvEEJS4_EE7initialEv = comdat any

$_Z29kokkos_impl_hip_shared_memoryIjEPT_v = comdat any

$_ZN4Impl32hip_parallel_launch_local_memoryINS_19ParallelScanHIPBaseI7BinSortI4ViewIPiJ3HIPEEPFvvEEJS5_EEELi0ELi0EEEvT_ = comdat any

$_ZN4Impl32hip_parallel_launch_local_memoryINS_14ParallelReduceIN12Experimental11DynamicViewIPiJ3HIPEEE11RangePolicyIJS5_EE6MinMaxINS_16ViewDataAnalysisIiiEEEEELi0ELi0EEEvT_ = comdat any

$_ZN4Impl14ParallelReduceIN12Experimental11DynamicViewIPiJ3HIPEEE11RangePolicyIJS4_EE6MinMaxINS_16ViewDataAnalysisIiiEEEEclEv = comdat any

@_ZZN4Impl32hip_inter_warp_shuffle_reductionIiN15FunctorAnalysisI23FunctorPatternInterface11RangePolicyIJ3HIPEE6MinMaxINS_16ViewDataAnalysisIiiEEEE7ReducerEEEvT_T0_E9sh_result = external addrspace(3) global double, align 8
@sh = external addrspace(3) global [0 x i32], align 4

declare void @__cxa_pure_virtual() #0

; Function Attrs: cold noreturn nounwind
declare void @llvm.trap() #1

declare void @__cxa_deleted_virtual() #0

define amdgpu_kernel void @_ZN4Impl32hip_parallel_launch_local_memoryINS_14ParallelReduceIi11RangePolicyIJ3HIPEE6MinMaxINS_16ViewDataAnalysisIiiEEEEELi0ELi0EEEvT_(ptr addrspace(4) %0) #2 comdat {
entry:
  call void @_ZN4Impl14ParallelReduceIi11RangePolicyIJ3HIPEE6MinMaxINS_16ViewDataAnalysisIiiEEEEclEv(ptr noundef nonnull align 8 dereferenceable(24) poison) #4
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p4.i64(ptr noalias nocapture writeonly, ptr addrspace(4) noalias nocapture readonly, i64, i1 immarg) #3

define linkonce_odr void @_ZN4Impl14ParallelReduceIi11RangePolicyIJ3HIPEE6MinMaxINS_16ViewDataAnalysisIiiEEEEclEv(ptr %this) #0 comdat align 2 {
entry:
  %call = call noundef zeroext i1 @_ZN4Impl33hip_inter_block_shuffle_reductionIN15FunctorAnalysisI23FunctorPatternInterface11RangePolicyIJ3HIPEE6MinMaxINS_16ViewDataAnalysisIiiEEEE7ReducerEEEbNT_14reference_typeESD_SC_PjNSC_12pointer_typeESE_i(i32 noundef poison, i32 noundef poison, ptr noundef poison, ptr noundef poison, ptr noundef poison, i32 noundef poison) #4
  ret void
}

declare void @_ZN15FunctorAnalysisI23FunctorPatternInterface11RangePolicyIJ3HIPEE6MinMaxIN4Impl16ViewDataAnalysisIiiEEEE7ReducerC1EPS8_(ptr, ptr) unnamed_addr #0

define linkonce_odr i1 @_ZN4Impl33hip_inter_block_shuffle_reductionIN15FunctorAnalysisI23FunctorPatternInterface11RangePolicyIJ3HIPEE6MinMaxINS_16ViewDataAnalysisIiiEEEE7ReducerEEEbNT_14reference_typeESD_SC_PjNSC_12pointer_typeESE_i(i32 %value, i32 %0, ptr %1, ptr %2, ptr %3, i32 %4) #0 comdat {
entry:
  call void @_ZN4Impl33hip_intra_block_shuffle_reductionIiN15FunctorAnalysisI23FunctorPatternInterface11RangePolicyIJ3HIPEE6MinMaxINS_16ViewDataAnalysisIiiEEEE7ReducerEEEvT_T0_(i32 noundef poison) #4
  unreachable
}

define linkonce_odr void @_ZN4Impl33hip_intra_block_shuffle_reductionIiN15FunctorAnalysisI23FunctorPatternInterface11RangePolicyIJ3HIPEE6MinMaxINS_16ViewDataAnalysisIiiEEEE7ReducerEEEvT_T0_(i32 %value) #0 comdat {
entry:
  call void @_ZN4Impl32hip_inter_warp_shuffle_reductionIiN15FunctorAnalysisI23FunctorPatternInterface11RangePolicyIJ3HIPEE6MinMaxINS_16ViewDataAnalysisIiiEEEE7ReducerEEEvT_T0_(i32 noundef poison) #4
  ret void
}

define linkonce_odr void @_ZN4Impl32hip_inter_warp_shuffle_reductionIiN15FunctorAnalysisI23FunctorPatternInterface11RangePolicyIJ3HIPEE6MinMaxINS_16ViewDataAnalysisIiiEEEE7ReducerEEEvT_T0_(i32 %0) #0 comdat {
entry:
  store ptr addrspacecast (ptr addrspace(3) @_ZZN4Impl32hip_inter_warp_shuffle_reductionIiN15FunctorAnalysisI23FunctorPatternInterface11RangePolicyIJ3HIPEE6MinMaxINS_16ViewDataAnalysisIiiEEEE7ReducerEEEvT_T0_E9sh_result to ptr), ptr poison, align 8
  ret void
}

define amdgpu_kernel void @_ZN4Impl32hip_parallel_launch_local_memoryINS_12ParallelScanI7BinSortI4ViewIPiJ3HIPEEPFvvEE11RangePolicyIJS5_EEEELi0ELi0EEEvT_(ptr addrspace(4) %0) #2 comdat {
entry:
  call void @_ZN4Impl19ParallelScanHIPBaseI7BinSortI4ViewIPiJ3HIPEEPFvvEEJS4_EEclEv(ptr noundef nonnull align 1 dereferenceable(1) poison) #4
  ret void
}

define linkonce_odr void @_ZN4Impl19ParallelScanHIPBaseI7BinSortI4ViewIPiJ3HIPEEPFvvEEJS4_EEclEv(ptr %this) #0 comdat align 2 {
entry:
  call void @_ZN4Impl19ParallelScanHIPBaseI7BinSortI4ViewIPiJ3HIPEEPFvvEEJS4_EE7initialEv(ptr noundef nonnull align 1 dereferenceable(1) poison) #4
  ret void
}

define linkonce_odr void @_ZN4Impl19ParallelScanHIPBaseI7BinSortI4ViewIPiJ3HIPEEPFvvEEJS4_EE7initialEv(ptr %this) #0 comdat align 2 {
entry:
  %call = call noundef ptr @_Z29kokkos_impl_hip_shared_memoryIjEPT_v() #4
  ret void
}

define linkonce_odr ptr @_Z29kokkos_impl_hip_shared_memoryIjEPT_v() #0 comdat {
entry:
  ret ptr addrspacecast (ptr addrspace(3) @sh to ptr)
}

define amdgpu_kernel void @_ZN4Impl32hip_parallel_launch_local_memoryINS_19ParallelScanHIPBaseI7BinSortI4ViewIPiJ3HIPEEPFvvEEJS5_EEELi0ELi0EEEvT_(ptr addrspace(4) %0) #2 comdat {
entry:
  call void @_ZN4Impl19ParallelScanHIPBaseI7BinSortI4ViewIPiJ3HIPEEPFvvEEJS4_EEclEv(ptr noundef nonnull align 1 dereferenceable(1) poison) #4
  ret void
}

define amdgpu_kernel void @_ZN4Impl32hip_parallel_launch_local_memoryINS_14ParallelReduceIN12Experimental11DynamicViewIPiJ3HIPEEE11RangePolicyIJS5_EE6MinMaxINS_16ViewDataAnalysisIiiEEEEELi0ELi0EEEvT_(ptr addrspace(4) %0) #2 comdat {
entry:
  call void @_ZN4Impl14ParallelReduceIN12Experimental11DynamicViewIPiJ3HIPEEE11RangePolicyIJS4_EE6MinMaxINS_16ViewDataAnalysisIiiEEEEclEv(ptr noundef nonnull align 8 dereferenceable(24) poison) #4
  ret void
}

define linkonce_odr void @_ZN4Impl14ParallelReduceIN12Experimental11DynamicViewIPiJ3HIPEEE11RangePolicyIJS4_EE6MinMaxINS_16ViewDataAnalysisIiiEEEEclEv(ptr %this) #0 comdat align 2 {
entry:
  %call = call noundef zeroext i1 @_ZN4Impl33hip_inter_block_shuffle_reductionIN15FunctorAnalysisI23FunctorPatternInterface11RangePolicyIJ3HIPEE6MinMaxINS_16ViewDataAnalysisIiiEEEE7ReducerEEEbNT_14reference_typeESD_SC_PjNSC_12pointer_typeESE_i(i32 noundef poison, i32 noundef poison, ptr noundef poison, ptr noundef poison, ptr noundef poison, i32 noundef poison) #4
  ret void
}

attributes #0 = { "target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64" }
attributes #1 = { cold noreturn nounwind }
attributes #2 = { "uniform-work-group-size"="true" }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { convergent nounwind }
```

Issue stems from this line: https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp#L1177

`KernelToReplacement` only holds 2 functions in the structure, while `OrderedKernels` holds 4. This causes an issue here, `KernelToReplacement[OrderedKernels[i]].SGV`, since `KernelToReplacement` doesn't have the two other functions one is constructed. The new constructed object then holds a `null` pointer, `SGV`. 

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to