llvm / llvm-project

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

[AMDGPU] crash when compiling ir since llc 18 #97906

Open DigOrDog opened 3 months ago

DigOrDog commented 3 months ago

Description

Interestingly, compiling IR with llc 18 results in a crash, but versions prior to llc 17 do not.

Minimal Reproduction

https://llvm.godbolt.org/z/TqPhzqzYY

Code

@G = global i64 0

define double @f() {
BB:
  %A = alloca i64, align 8
  store i64 0, ptr %A, align 4
  ret double 0.000000e+00
}

define i32 @main() {
    call double @f()
    ret i32 0
}

Stack

LLVM ERROR: Cannot select: 0x9319330: ch = store<(store (s32) into %ir.A + 4, basealign 8)> 0x923a748, Constant:i32<0>, 0x9319640, undef:i64
  0x9318e60: i32 = Constant<0>
  0x9319640: i64 = bitcast 0x93195d0
    0x93195d0: v2i32 = BUILD_VECTOR 0x9319560, 0x9319480
      0x9319560: i32 = or 0x9319410, Constant:i32<4>
        0x9319410: i32 = extract_vector_elt 0x93192c0, Constant:i32<0>
          0x93192c0: v2i32 = bitcast FrameIndex:i64<0>
            0x9318c30: i64 = FrameIndex<0>
          0x9318e60: i32 = Constant<0>
        0x93194f0: i32 = Constant<4>
      0x9319480: i32 = extract_vector_elt 0x93192c0, Constant:i32<1>
        0x93192c0: v2i32 = bitcast FrameIndex:i64<0>
          0x9318c30: i64 = FrameIndex<0>
        0x9319170: i32 = Constant<1>
  0x9318ca0: i64 = undef
In function: f
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.  Program arguments: /opt/compiler-explorer/clang-trunk/bin/llc -o /app/output.s -x86-asm-syntax=intel -mtriple=amdgcn <source>
1.  Running pass 'CallGraph Pass Manager' on module '<source>'.
2.  Running pass 'AMDGPU DAG->DAG Pattern Instruction Selection' on function '@f'
 #0 0x0000000003749208 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/llc+0x3749208)
 #1 0x0000000003746bac SignalHandler(int) Signals.cpp:0:0
 #2 0x0000754fa2642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x0000754fa26969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x0000754fa2642476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x0000754fa26287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x000000000072d7c4 llvm::UniqueStringSaver::save(llvm::StringRef) (.cold) StringSaver.cpp:0:0
 #7 0x000000000350c98c llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*) (/opt/compiler-explorer/clang-trunk/bin/llc+0x350c98c)
 #8 0x0000000003513db5 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) (/opt/compiler-explorer/clang-trunk/bin/llc+0x3513db5)
 #9 0x0000000000f6818a AMDGPUDAGToDAGISel::Select(llvm::SDNode*) (/opt/compiler-explorer/clang-trunk/bin/llc+0xf6818a)
#10 0x0000000003509ef4 llvm::SelectionDAGISel::DoInstructionSelection() (/opt/compiler-explorer/clang-trunk/bin/llc+0x3509ef4)
#11 0x0000000003519101 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-trunk/bin/llc+0x3519101)
#12 0x000000000351bb59 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x351bb59)
#13 0x000000000351dac4 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x351dac4)
#14 0x0000000000f70295 AMDGPUDAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-trunk/bin/llc+0xf70295)
#15 0x000000000350d7a1 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x350d7a1)
#16 0x0000000002848c0b llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#17 0x0000000002d83cc2 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x2d83cc2)
#18 0x0000000002356e20 (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) CallGraphSCCPass.cpp:0:0
#19 0x0000000002d85af0 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x2d85af0)
#20 0x000000000084a924 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#21 0x0000000000740326 main (/opt/compiler-explorer/clang-trunk/bin/llc+0x740326)
#22 0x0000754fa2629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#23 0x0000754fa2629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#24 0x000000000084256e _start (/opt/compiler-explorer/clang-trunk/bin/llc+0x84256e)
Program terminated with signal: SIGSEGV
Compiler returned: 139
llvmbot commented 3 months ago

@llvm/issue-subscribers-backend-amdgpu

Author: None (DigOrDog)

# Description Interestingly, compiling IR with llc 18 results in a crash, but versions prior to llc 17 do not. # Minimal Reproduction https://llvm.godbolt.org/z/TqPhzqzYY ## Code ``` @G = global i64 0 define double @f() { BB: %A = alloca i64, align 8 store i64 0, ptr %A, align 4 ret double 0.000000e+00 } define i32 @main() { call double @f() ret i32 0 } ``` ## Stack ``` LLVM ERROR: Cannot select: 0x9319330: ch = store<(store (s32) into %ir.A + 4, basealign 8)> 0x923a748, Constant:i32<0>, 0x9319640, undef:i64 0x9318e60: i32 = Constant<0> 0x9319640: i64 = bitcast 0x93195d0 0x93195d0: v2i32 = BUILD_VECTOR 0x9319560, 0x9319480 0x9319560: i32 = or 0x9319410, Constant:i32<4> 0x9319410: i32 = extract_vector_elt 0x93192c0, Constant:i32<0> 0x93192c0: v2i32 = bitcast FrameIndex:i64<0> 0x9318c30: i64 = FrameIndex<0> 0x9318e60: i32 = Constant<0> 0x93194f0: i32 = Constant<4> 0x9319480: i32 = extract_vector_elt 0x93192c0, Constant:i32<1> 0x93192c0: v2i32 = bitcast FrameIndex:i64<0> 0x9318c30: i64 = FrameIndex<0> 0x9319170: i32 = Constant<1> 0x9318ca0: i64 = undef In function: f PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: /opt/compiler-explorer/clang-trunk/bin/llc -o /app/output.s -x86-asm-syntax=intel -mtriple=amdgcn <source> 1. Running pass 'CallGraph Pass Manager' on module '<source>'. 2. Running pass 'AMDGPU DAG->DAG Pattern Instruction Selection' on function '@f' #0 0x0000000003749208 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/llc+0x3749208) #1 0x0000000003746bac SignalHandler(int) Signals.cpp:0:0 #2 0x0000754fa2642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #3 0x0000754fa26969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc) #4 0x0000754fa2642476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476) #5 0x0000754fa26287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3) #6 0x000000000072d7c4 llvm::UniqueStringSaver::save(llvm::StringRef) (.cold) StringSaver.cpp:0:0 #7 0x000000000350c98c llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*) (/opt/compiler-explorer/clang-trunk/bin/llc+0x350c98c) #8 0x0000000003513db5 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) (/opt/compiler-explorer/clang-trunk/bin/llc+0x3513db5) #9 0x0000000000f6818a AMDGPUDAGToDAGISel::Select(llvm::SDNode*) (/opt/compiler-explorer/clang-trunk/bin/llc+0xf6818a) #10 0x0000000003509ef4 llvm::SelectionDAGISel::DoInstructionSelection() (/opt/compiler-explorer/clang-trunk/bin/llc+0x3509ef4) #11 0x0000000003519101 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-trunk/bin/llc+0x3519101) #12 0x000000000351bb59 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x351bb59) #13 0x000000000351dac4 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x351dac4) #14 0x0000000000f70295 AMDGPUDAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-trunk/bin/llc+0xf70295) #15 0x000000000350d7a1 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x350d7a1) #16 0x0000000002848c0b llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0 #17 0x0000000002d83cc2 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x2d83cc2) #18 0x0000000002356e20 (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) CallGraphSCCPass.cpp:0:0 #19 0x0000000002d85af0 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x2d85af0) #20 0x000000000084a924 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0 #21 0x0000000000740326 main (/opt/compiler-explorer/clang-trunk/bin/llc+0x740326) #22 0x0000754fa2629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #23 0x0000754fa2629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #24 0x000000000084256e _start (/opt/compiler-explorer/clang-trunk/bin/llc+0x84256e) Program terminated with signal: SIGSEGV Compiler returned: 139 ```
arsenm commented 3 months ago

The default amdgcn subtarget does not support flat addressing and isn't meaningful to codegen. You need to always supply a -mcpu

DigOrDog commented 3 months ago

The default amdgcn subtarget does not support flat addressing and isn't meaningful to codegen. You need to always supply a -mcpu

Thank you for your explanation. I referred to this document and tried the options -mtriple=amdgcn -mcpu=gfx700 and -mtriple=amdgcn -mcpu=gfx940, but neither worked. I believe my understanding of flat addressing is flawed. Could you please inform me which mcpu supports it?

arsenm commented 2 months ago

The default amdgcn subtarget does not support flat addressing and isn't meaningful to codegen. You need to always supply a -mcpu

Thank you for your explanation. I referred to this document and tried the options -mtriple=amdgcn -mcpu=gfx700 and -mtriple=amdgcn -mcpu=gfx940, but neither worked. I believe my understanding of flat addressing is flawed. Could you please inform me which mcpu supports it?

gfx700 and gfx940 both support flat addressing. It's only gfx6* that do not. Your IR has a secondary problem after the initial selection failure on the flat store. The alloca is using the wrong address space. We do not support using alloca with the default address space, it needs to use addrspace(5). Here is the corrected IR . Alternatively, you could directly access the pointer as addrspace(5) instead of using the addrspacecast to the flat pointer.