llvm / llvm/llvm-project

[CodeGenPrepare] hit unreachable on scalable non-splat constant promotion

Open
#222,427 0 comments 0 reactions 0 assignees View on GitHub
confirmed crash-on-valid llvm:codegen
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

### Reproducer
```llvm
target triple = "x86_64-unknown-linux-gnu"
define void @f(ptr %p) {
entry:
%v = insertelement poison, i32 1, i64 0
%e = extractelement %v, i64 0
%a = add i32 %e, 7
store i32 %a, ptr %p
ret void
}
```
```console
$ opt -codegenprepare -stress-cgp-store-extract repro.ll
Generate scalable vector for non-splat is unimplemented
UNREACHABLE executed at /root/llvm-project/llvm/lib/CodeGen/CodeGenPrepare.cpp:8370!
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/opt -o /app/output.s -S -codegenprepare -stress-cgp-store-extract
1. Running pass 'Function Pass Manager' on module ''.
2. Running pass 'CodeGen Prepare' on function '@f'
#0 0x0000000005c8cfd8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5c8cfd8)
#1 0x0000000005c8a234 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5c8a234)
#2 0x0000000005c8a3ae SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007bd322645330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#4 0x00007bd32269ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
#5 0x00007bd32264527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#6 0x00007bd3226288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#7 0x0000000005bb62ba (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5bb62ba)
#8 0x00000000041b696c (anonymous namespace)::CodeGenPrepare::optimizeExtractElementInst(llvm::Instruction*) CodeGenPrepare.cpp:0:0
#9 0x00000000041dceb4 (anonymous namespace)::CodeGenPrepare::optimizeInst(llvm::Instruction*, (anonymous namespace)::ModifyDT&) CodeGenPrepare.cpp:0:0
#10 0x00000000041dd6c7 (anonymous namespace)::CodeGenPrepare::_run(llvm::Function&) CodeGenPrepare.cpp:0:0
#11 0x00000000041e033b (anonymous namespace)::CodeGenPrepareLegacyPass::runOnFunction(llvm::Function&) (.part.0) CodeGenPrepare.cpp:0:0
#12 0x00000000059b3964 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x59b3964)
#13 0x00000000059b3e61 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x59b3e61)
#14 0x00000000059b4829 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x59b4829)
#15 0x00000000008e7c36 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8e7c36)
#16 0x00007bd32262a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#17 0x00007bd32262a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#18 0x00000000008dd095 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8dd095)
Program terminated with signal SIGABRT (6)
Compiler returned: 134
```
Without assertions, it reports the broken IR from opt 16.0.0 to trunk (reproduced on godbolt).
godbolt: https://godbolt.org/z/ve4qhbxbv

Contributor guide

Open the contributing guide

Research direction

Start in llvm/lib/CodeGen/CodeGenPrepare.cpp, especially optimizeExtractElementInst around the reported line, and run opt with -codegenprepare -stress-cgp-store-extract on the provided LLVM IR. Investigate the scalable non-splat constant-promotion path. Done means the reproducer no longer hits unreachable and opt does not emit broken IR.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.