[LoopVectorize] Assertion `(!Changed || !verifyFunction(F, &dbgs())) && "Invalid IR produced by LoopVectorize"' failed.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Reproducer: https://godbolt.org/z/W154n7nv6
Reduced case:
```c
#include
uintptr_t g2, g29, g14, g13;
_Bool g19, f8_repair19, f8_a2;
uint32_t g20;
uint64_t f8()
{
int a0;
void *p6;
uintptr_t as11;
uint32_t v17;
uint32_t bb18;
_Bool repair20;
if (f8_a2)
lbl_f8_b4:
goto lbl_f8_b9;
lbl_f8_b6:
lbl_f8_b9:
lbl_f8_b10:
g2 = (uintptr_t)p6;
v17 = __builtin_ffsll(g13);
g13 = as11 - g2;
as11 = (uintptr_t)p6;
g19 = 0 > a0;
a0 = g20 / v17;
if (f8_repair19) goto lbl_f8_b4;
repair20 = g29;
if (repair20) goto lbl_f8_b12;
goto lbl_f8_b13;
lbl_f8_b12:
as11 = as11 + 2;
g29 = -g14;
g14 = g14 - g13;
goto lbl_f8_b10;
lbl_f8_b13:
p6 = &bb18;
goto lbl_f8_b6;
}
```
Dump at -O2:
```
Instruction does not dominate all uses!
%16 = lshr <2 x i32> %broadcast.splat, splat (i32 1), !dbg !110
%23 = extractelement <2 x i32> %16, i64 0
PHI nodes not grouped at top of basic block!
%scalar.recur.init = phi i32 [ %23, %middle.block ], [ %div2737, %lbl_f8_b12.lr.ph ], [ %div2737, %vector.scevcheck ]
label %scalar.ph
clang: /root/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:8305: llvm::LoopVectorizeResult llvm::LoopVectorizePass::runImpl(llvm::Function&): Assertion `(!Changed || !verifyFunction(F, &dbgs())) && "Invalid IR produced by LoopVectorize"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O2
1. parser at end of file
2. Optimizer
3. Running pass "function(drop-unnecessary-assumes,float2int,lower-constant-intrinsics,loop(loop-rotate,loop-deletion,loop-interchange),loop-distribute,inject-tli-mappings,loop-vectorize,drop-unnecessary-assumes,infer-alignment,loop-load-elim,instcombine,simplifycfg,slp-vectorizer,vector-combine,instcombine,loop-unroll,transform-warning,sroa,infer-alignment,instcombine,loop-mssa(licm),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,mergeicmps,expand-memcmp,tailcallelim,simplifycfg)" on module ""
4. Running pass "loop-vectorize" on function "f8"
#0 0x00000000044bbd48 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44bbd48)
#1 0x00000000044b8fa4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44b8fa4)
#2 0x00000000044b95dc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44b95dc)
#3 0x00000000043f5b38 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x0000706879245330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x000070687929ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
#6 0x000070687924527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x00007068792288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x000070687922881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x000070687923b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x00000000047586c9 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47586c9)
#11 0x0000000004758eae llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4758eae)
#12 0x00000000057a7cbe llvm::detail::PassModel>::runImpl(llvm::detail::PassConcept>&, llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x57a7cbe)
#13 0x0000000003de0311 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3de0311)
#14 0x00000000012c4c6e llvm::detail::PassModel>, llvm::AnalysisManager>::runImpl(llvm::detail::PassConcept>&, llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x12c4c6e)
#15 0x0000000003ddecdc llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3ddecdc)
#16 0x00000000012c4d0e llvm::detail::PassModel>::runImpl(llvm::detail::PassConcept>&, llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x12c4d0e)
#17 0x0000000003dde4ce llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3dde4ce)
#18 0x00000000048f300c (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr>&, std::unique_ptr>&, clang::BackendConsumer*) BackendUtil.cpp:0:0
#19 0x00000000048f6119 (anonymous namespace)::EmitAssemblyHelper::emitAssembly(clang::BackendAction, std::unique_ptr>, clang::BackendConsumer*) BackendUtil.cpp:0:0
#20 0x00000000048f715c clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr, std::unique_ptr>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48f715c)
#21 0x0000000004fd0ac7 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4fd0ac7)
#22 0x0000000006e12c0c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6e12c0c)
#23 0x0000000004fd0ef8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4fd0ef8)
#24 0x00000000052f2568 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x52f2568)
#25 0x000000000528017d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x528017d)
#26 0x00000000053c6d8d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x53c6d8d)
#27 0x0000000000d9100c cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd9100c)
#28 0x0000000000d87d1a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#29 0x0000000000d87e9d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#30 0x00000000050451c9 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#31 0x00000000043f5f34 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x43f5f34)
#32 0x0000000005045d35 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#33 0x0000000005004162 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5004162)
#34 0x0000000005008ac7 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5008ac7)
#35 0x0000000005013025 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5013025)
#36 0x0000000000d8d50a clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd8d50a)
#37 0x0000000000ccb0ea main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xccb0ea)
#38 0x000070687922a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#39 0x000070687922a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#40 0x0000000000d876c5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd876c5)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
Program terminated with signal SIGABRT (6)
Compiler returned: 134
```
Contributor guide
Research direction
Reproduce the reduced C case with the assertion-enabled clang command at -O2, then inspect the LoopVectorize pass, especially LoopVectorizePass::runImpl, alongside the verifier diagnostics. Trace how vectorization creates the invalid dominance and PHI placement shown in the dump. Done means the reproducer no longer triggers the invalid-IR assertion and the behavior is covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100