llvm / llvm-project

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

[x86_64/GlobalISel] unable to legalize instruction #112367

Open DigOrDog opened 1 month ago

DigOrDog commented 1 month ago

Description

The following code crashes X86 backend with "LLVM ERROR: unable to legalize instruction"

Minimal Reproduction

https://godbolt.org/z/v5x9jPhqd

code

define <4 x i32> @vector_select(<4 x i32> %vec1, <4 x i32> %vec2) {
entry:
  %result = shufflevector <4 x i32> %vec1, <4 x i32> %vec2, <4 x i32> <i32 0, i32 4, i32 1, i32 5> 
  ret <4 x i32> %result
}

Stack Trace


LLVM ERROR: unable to legalize instruction: %2:_(<4 x s32>) = G_SHUFFLE_VECTOR %0:_(<4 x s32>), %1:_, shufflemask(0, 4, 1, 5) (in function: vector_select)
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=x86_64 --global-isel <source>
1.  Running pass 'Function Pass Manager' on module '<source>'.
2.  Running pass 'Legalizer' on function '@vector_select'
 #0 0x00000000038be388 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/llc+0x38be388)
 #1 0x00000000038bbf6c SignalHandler(int) Signals.cpp:0:0
 #2 0x00007696d5042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007696d50969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x00007696d5042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x00007696d50287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x000000000074e7f4 llvm::UniqueStringSaver::save(llvm::Twine const&) (.cold) StringSaver.cpp:0:0
 #7 0x00000000042b4962 llvm::reportGISelFailure(llvm::MachineFunction&, llvm::TargetPassConfig const&, llvm::MachineOptimizationRemarkEmitter&, char const*, llvm::StringRef, llvm::MachineInstr const&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x42b4962)
 #8 0x0000000004244b3c llvm::Legalizer::runOnMachineFunction(llvm::MachineFunction&) (.part.0) Legalizer.cpp:0:0
 #9 0x000000000297065b llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#10 0x0000000002ebe462 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x2ebe462)
#11 0x0000000002ebe6f1 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x2ebe6f1)
#12 0x0000000002ec0096 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x2ec0096)
#13 0x0000000000871de4 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#14 0x0000000000762976 main (/opt/compiler-explorer/clang-trunk/bin/llc+0x762976)
#15 0x00007696d5029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#16 0x00007696d5029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#17 0x0000000000869b8e _start (/opt/compiler-explorer/clang-trunk/bin/llc+0x869b8e)
Program terminated with signal: SIGSEGV
Compiler returned: 139
llvmbot commented 1 month ago

@llvm/issue-subscribers-backend-x86

Author: None (DigOrDog)

# Description The following code crashes X86 backend with "LLVM ERROR: unable to legalize instruction" # Minimal Reproduction https://godbolt.org/z/v5x9jPhqd ## code ``` define <4 x i32> @vector_select(<4 x i32> %vec1, <4 x i32> %vec2) { entry: %result = shufflevector <4 x i32> %vec1, <4 x i32> %vec2, <4 x i32> <i32 0, i32 4, i32 1, i32 5> ret <4 x i32> %result } ``` ## Stack Trace ``` LLVM ERROR: unable to legalize instruction: %2:_(<4 x s32>) = G_SHUFFLE_VECTOR %0:_(<4 x s32>), %1:_, shufflemask(0, 4, 1, 5) (in function: vector_select) 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=x86_64 --global-isel <source> 1. Running pass 'Function Pass Manager' on module '<source>'. 2. Running pass 'Legalizer' on function '@vector_select' #0 0x00000000038be388 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/llc+0x38be388) #1 0x00000000038bbf6c SignalHandler(int) Signals.cpp:0:0 #2 0x00007696d5042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #3 0x00007696d50969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc) #4 0x00007696d5042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476) #5 0x00007696d50287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3) #6 0x000000000074e7f4 llvm::UniqueStringSaver::save(llvm::Twine const&) (.cold) StringSaver.cpp:0:0 #7 0x00000000042b4962 llvm::reportGISelFailure(llvm::MachineFunction&, llvm::TargetPassConfig const&, llvm::MachineOptimizationRemarkEmitter&, char const*, llvm::StringRef, llvm::MachineInstr const&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x42b4962) #8 0x0000000004244b3c llvm::Legalizer::runOnMachineFunction(llvm::MachineFunction&) (.part.0) Legalizer.cpp:0:0 #9 0x000000000297065b llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0 #10 0x0000000002ebe462 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x2ebe462) #11 0x0000000002ebe6f1 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x2ebe6f1) #12 0x0000000002ec0096 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x2ec0096) #13 0x0000000000871de4 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0 #14 0x0000000000762976 main (/opt/compiler-explorer/clang-trunk/bin/llc+0x762976) #15 0x00007696d5029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #16 0x00007696d5029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #17 0x0000000000869b8e _start (/opt/compiler-explorer/clang-trunk/bin/llc+0x869b8e) Program terminated with signal: SIGSEGV Compiler returned: 139 ```
arsenm commented 1 month ago

x86 globalisel is barely implemented. A minimally functional fix would be to add getActionDefinitionsBuilder(G_SHUFFLE_VECTOR).lower() to the legalizer rules.