Skip to content

AArch64 with SDAG crashes when compiling #97870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DigOrDog opened this issue Jul 6, 2024 · 2 comments
Closed

AArch64 with SDAG crashes when compiling #97870

DigOrDog opened this issue Jul 6, 2024 · 2 comments

Comments

@DigOrDog
Copy link

DigOrDog commented Jul 6, 2024

Description

The following code crashes aarch64 backend with SDAG.
However, it's interesting to note that it compiles successfully when using -global-isel on AArch64, or on x86_64 and ARM architectures.

Minimal Reproduction

https://godbolt.org/z/7WeaTdrhe

Code

define i32 @f(ptr %A, ptr %G3) {
BB:
  %G2 = getelementptr i8, ptr %G3, i64 168
  %0 = ptrtoint ptr %G2 to i64
  %CastPtrToI2 = trunc i64 %0 to i1
  store bfloat 0xR0000, ptr %G2, align 2
  store i1 %CastPtrToI2, ptr %A, align 1
  ret i32 0
}

Stack Trace

LLVM ERROR: Cannot select: 0x9687300: i64,ch = store<(store (s16) into %ir.G2), <pre-inc>> 0x9602f28, ConstantFP:bf16<APFloat(0)>, 0x96871b0, Constant:i64<168>
  0x9687370: bf16 = ConstantFP<APFloat(0)>
  0x96871b0: i64,ch = CopyFromReg 0x9602f28, Register:i64 %1
    0x9687140: i64 = Register %1
  0x9687220: i64 = Constant<168>
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=aarch64 <source>
1.	Running pass 'Function Pass Manager' on module '<source>'.
2.	Running pass 'AArch64 Instruction Selection' on function '@f'
 #0 0x0000000003749078 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/llc+0x3749078)
 #1 0x0000000003746a1c SignalHandler(int) Signals.cpp:0:0
 #2 0x00007aa282042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007aa2820969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x00007aa282042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x00007aa2820287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x000000000072d846 llvm::UniqueStringSaver::save(llvm::StringRef) (.cold) StringSaver.cpp:0:0
 #7 0x000000000350c47c llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*) (/opt/compiler-explorer/clang-trunk/bin/llc+0x350c47c)
 #8 0x00000000035138a5 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) (/opt/compiler-explorer/clang-trunk/bin/llc+0x35138a5)
 #9 0x0000000000ad925b (anonymous namespace)::AArch64DAGToDAGISel::Select(llvm::SDNode*) AArch64ISelDAGToDAG.cpp:0:0
#10 0x00000000035099e4 llvm::SelectionDAGISel::DoInstructionSelection() (/opt/compiler-explorer/clang-trunk/bin/llc+0x35099e4)
#11 0x0000000003518bf1 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-trunk/bin/llc+0x3518bf1)
#12 0x000000000351b649 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x351b649)
#13 0x000000000351d5b4 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x351d5b4)
#14 0x000000000350d291 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x350d291)
#15 0x000000000284919b llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#16 0x0000000002d83d22 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x2d83d22)
#17 0x0000000002d83ea1 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x2d83ea1)
#18 0x0000000002d85b50 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x2d85b50)
#19 0x000000000084a9c4 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#20 0x00000000007403c6 main (/opt/compiler-explorer/clang-trunk/bin/llc+0x7403c6)
#21 0x00007aa282029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#22 0x00007aa282029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#23 0x000000000084260e _start (/opt/compiler-explorer/clang-trunk/bin/llc+0x84260e)
Program terminated with signal: SIGSEGV
Compiler returned: 139
@llvmbot
Copy link
Member

llvmbot commented Jul 6, 2024

@llvm/issue-subscribers-backend-aarch64

Author: None (DigOrDog)

# Description The following code crashes aarch64 backend with SDAG. However, it's interesting to note that it compiles successfully when using -global-isel on AArch64, or on x86_64 and ARM architectures.

Minimal Reproduction

https://godbolt.org/z/7WeaTdrhe

Code

define i32 @<!-- -->f(ptr %A, ptr %G3) {
BB:
  %G2 = getelementptr i8, ptr %G3, i64 168
  %0 = ptrtoint ptr %G2 to i64
  %CastPtrToI2 = trunc i64 %0 to i1
  store bfloat 0xR0000, ptr %G2, align 2
  store i1 %CastPtrToI2, ptr %A, align 1
  ret i32 0
}

Stack Trace

LLVM ERROR: Cannot select: 0x9687300: i64,ch = store&lt;(store (s16) into %ir.G2), &lt;pre-inc&gt;&gt; 0x9602f28, ConstantFP:bf16&lt;APFloat(0)&gt;, 0x96871b0, Constant:i64&lt;168&gt;
  0x9687370: bf16 = ConstantFP&lt;APFloat(0)&gt;
  0x96871b0: i64,ch = CopyFromReg 0x9602f28, Register:i64 %1
    0x9687140: i64 = Register %1
  0x9687220: i64 = Constant&lt;168&gt;
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=aarch64 &lt;source&gt;
1.	Running pass 'Function Pass Manager' on module '&lt;source&gt;'.
2.	Running pass 'AArch64 Instruction Selection' on function '@<!-- -->f'
 #<!-- -->0 0x0000000003749078 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/opt/compiler-explorer/clang-trunk/bin/llc+0x3749078)
 #<!-- -->1 0x0000000003746a1c SignalHandler(int) Signals.cpp:0:0
 #<!-- -->2 0x00007aa282042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #<!-- -->3 0x00007aa2820969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #<!-- -->4 0x00007aa282042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #<!-- -->5 0x00007aa2820287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #<!-- -->6 0x000000000072d846 llvm::UniqueStringSaver::save(llvm::StringRef) (.cold) StringSaver.cpp:0:0
 #<!-- -->7 0x000000000350c47c llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*) (/opt/compiler-explorer/clang-trunk/bin/llc+0x350c47c)
 #<!-- -->8 0x00000000035138a5 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) (/opt/compiler-explorer/clang-trunk/bin/llc+0x35138a5)
 #<!-- -->9 0x0000000000ad925b (anonymous namespace)::AArch64DAGToDAGISel::Select(llvm::SDNode*) AArch64ISelDAGToDAG.cpp:0:0
#<!-- -->10 0x00000000035099e4 llvm::SelectionDAGISel::DoInstructionSelection() (/opt/compiler-explorer/clang-trunk/bin/llc+0x35099e4)
#<!-- -->11 0x0000000003518bf1 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-trunk/bin/llc+0x3518bf1)
#<!-- -->12 0x000000000351b649 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&amp;) (/opt/compiler-explorer/clang-trunk/bin/llc+0x351b649)
#<!-- -->13 0x000000000351d5b4 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&amp;) (/opt/compiler-explorer/clang-trunk/bin/llc+0x351d5b4)
#<!-- -->14 0x000000000350d291 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&amp;) (/opt/compiler-explorer/clang-trunk/bin/llc+0x350d291)
#<!-- -->15 0x000000000284919b llvm::MachineFunctionPass::runOnFunction(llvm::Function&amp;) (.part.0) MachineFunctionPass.cpp:0:0
#<!-- -->16 0x0000000002d83d22 llvm::FPPassManager::runOnFunction(llvm::Function&amp;) (/opt/compiler-explorer/clang-trunk/bin/llc+0x2d83d22)
#<!-- -->17 0x0000000002d83ea1 llvm::FPPassManager::runOnModule(llvm::Module&amp;) (/opt/compiler-explorer/clang-trunk/bin/llc+0x2d83ea1)
#<!-- -->18 0x0000000002d85b50 llvm::legacy::PassManagerImpl::run(llvm::Module&amp;) (/opt/compiler-explorer/clang-trunk/bin/llc+0x2d85b50)
#<!-- -->19 0x000000000084a9c4 compileModule(char**, llvm::LLVMContext&amp;) llc.cpp:0:0
#<!-- -->20 0x00000000007403c6 main (/opt/compiler-explorer/clang-trunk/bin/llc+0x7403c6)
#<!-- -->21 0x00007aa282029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#<!-- -->22 0x00007aa282029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#<!-- -->23 0x000000000084260e _start (/opt/compiler-explorer/clang-trunk/bin/llc+0x84260e)
Program terminated with signal: SIGSEGV
Compiler returned: 139

@inclyc inclyc self-assigned this Jul 6, 2024
@davemgreen
Copy link
Collaborator

Thanks for the report. There is a slightly shorter example here: https://godbolt.org/z/9Ybs89Ken. We probably need extra patterns for bf16 pre-inc store, similar to the ones for pre-inc fp16 stores.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants