[GlobalISel] legalizer aborts on a plain vector ctpop
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
### Reproducer
```llvm
define <4 x i32> @f(<4 x i32> %x) {
%r = call <4 x i32> @llvm.ctpop.v4i32(<4 x i32> %x)
ret <4 x i32> %r
}
declare <4 x i32> @llvm.ctpop.v4i32(<4 x i32>)
```
```console
$ llc repro.ll
$ echo @?
0
$ llc repro.ll -global-isel
llc: /root/llvm-project/llvm/lib/CodeGen/GlobalISel/LegalizerInfo.cpp:203: llvm::LegalizeActionStep llvm::LegalizeRuleSet::apply(const llvm::LegalityQuery&) const: Assertion `mutationIsSane(Rule, Query, Mutation) && "legality mutation invalid for match"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/llc -o /app/output.s -global-isel
1. Running pass 'Function Pass Manager' on module ''.
2. Running pass 'Legalizer' on function '@f'
#0 0x0000000004498598 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x4498598)
#1 0x00000000044957d4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x44957d4)
#2 0x000000000449594e SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007e09a1645330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#4 0x00007e09a169ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
#5 0x00007e09a164527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#6 0x00007e09a16288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#7 0x00007e09a162881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#8 0x00007e09a163b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#9 0x0000000004f4197c llvm::LegalizeRuleSet::apply(llvm::LegalityQuery const&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x4f4197c)
#10 0x0000000004f42f23 llvm::LegalizerInfo::getAction(llvm::MachineInstr const&, llvm::MachineRegisterInfo const&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x4f42f23)
#11 0x0000000004f3dc55 llvm::LegalizerHelper::legalizeInstrStep(llvm::MachineInstr&, llvm::LostDebugLocObserver&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x4f3dc55)
#12 0x0000000004ee2e55 llvm::legalizeMachineFunction(llvm::MachineFunction&, llvm::LegalizerInfo const&, llvm::ArrayRef, llvm::LostDebugLocObserver&, llvm::MachineIRBuilder&, llvm::LibcallLoweringInfo const*, llvm::GISelValueTracking*) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x4ee2e55)
#13 0x0000000004ee4d47 runLegalizerOnMachineFunction(llvm::MachineFunction&, llvm::function_ref, llvm::function_ref, llvm::LibcallLoweringInfo const*) Legalizer.cpp:0:0
#14 0x0000000004ee56d7 llvm::LegalizerLegacy::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x4ee56d7)
#15 0x000000000321a5cd llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#16 0x00000000038629a1 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x38629a1)
#17 0x0000000003862ed1 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3862ed1)
#18 0x0000000003863891 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3863891)
#19 0x000000000086e9ad compileModule(char**, llvm::SmallVectorImpl&, llvm::LLVMContext&, std::__cxx11::basic_string, std::allocator>&) llc.cpp:0:0
#20 0x00000000007c73bc main (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x7c73bc)
#21 0x00007e09a162a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#22 0x00007e09a162a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#23 0x0000000000863c05 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x863c05)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```
godbolt: https://godbolt.org/z/Mhxb45cWj
### Additional note
This case is reproduced on 17.0.0 ~ trunk.
Without the assertion, the compiler hangs locally and is SIGKILLed on godbolt.
Contributor guide
Research direction
Start with the reproducer and compare `llc repro.ll` with `llc repro.ll -global-isel`. Read `llvm/lib/CodeGen/GlobalISel/LegalizerInfo.cpp` around the failing assertion and follow the Legalizer pass entry point shown in the stack trace. Done means the plain vector `ctpop` case no longer aborts or hangs under GlobalISel.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100