[LoopVectorize] Assertion `(!Changed || !verifyFunction(F, &dbgs())) && "Invalid IR produced by LoopVectorize"' failed.
Reproducer: https://godbolt.org/z/W154n7nv6 Reduced case:
#include <stdint.h>
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 <source>
1. <eof> parser at end of file
2. Optimizer
3. Running pass "function<eager-inv>(drop-unnecessary-assumes,float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto;check-exit-count>,loop-deletion,loop-interchange),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,drop-unnecessary-assumes<drop-deref>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-arithmetic;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg;aggregate-to-vector>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,mergeicmps,expand-memcmp,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;switch-to-arithmetic;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)" on module "<source>"
4. Running pass "loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>" 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<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4758eae)
#12 0x00000000057a7cbe llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::runImpl(llvm::detail::PassConcept<llvm::Function, llvm::AnalysisManager<llvm::Function>>&, llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x57a7cbe)
#13 0x0000000003de0311 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3de0311)
#14 0x00000000012c4c6e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::runImpl(llvm::detail::PassConcept<llvm::Function, llvm::AnalysisManager<llvm::Function>>&, llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x12c4c6e)
#15 0x0000000003ddecdc llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3ddecdc)
#16 0x00000000012c4d0e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::runImpl(llvm::detail::PassConcept<llvm::Module, llvm::AnalysisManager<llvm::Module>>&, llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x12c4d0e)
#17 0x0000000003dde4ce llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3dde4ce)
#18 0x00000000048f300c (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0
#19 0x00000000048f6119 (anonymous namespace)::EmitAssemblyHelper::emitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) BackendUtil.cpp:0:0
#20 0x00000000048f715c clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, 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*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd9100c)
#28 0x0000000000d87d1a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#29 0x0000000000d87e9d int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#30 0x00000000050451c9 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#31 0x00000000043f5f34 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x43f5f34)
#32 0x0000000005045d35 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, 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<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5008ac7)
#35 0x0000000005013025 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/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
Hi! I'd be interested in working on this issue.
Another reproducer for this, still failing on 9dce18f0e (2026-11-11; also f2808fc79 and 5e457cda8d5a). It's a pure-IR one and smaller than
the C test. The verifier output has the same shape, with shl (from mul x, 2) in place of lshr:
define void @f(i64 %x, i64 %n) {
entry:
br label %loop
loop:
%iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
%r = phi i64 [ 0, %entry ], [ %inv, %loop ]
%inv = mul i64 %x, 2
store i64 %r, ptr null
%iv.next = add i64 %iv, 1
%c = icmp ult i64 %iv, %n
br i1 %c, label %loop, label %exit
exit:
ret void
}
$ opt -mtriple=x86_64-unknown-linux-gnu -passes=loop-vectorize -disable-output test.ll
Instruction does not dominate all uses!
%2 = shl <2 x i64> %broadcast.splat, splat (i64 1)
%6 = extractelement <2 x i64> %2, i64 0
PHI nodes not grouped at top of basic block!
%scalar.recur.init = phi i64 [ %6, %middle.block ], [ 0, %entry ]
label %scalar.ph
opt: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:8024: LoopVectorizeResult llvm::LoopVectorizePass::runImpl(Function &): Assertion `(!Changed || !verifyFunction(F, &dbgs())) && "Invalid IR produced by LoopVectorize"' failed.
It also fails with -mtriple=aarch64 or -force-vector-width=4 -force-vector-interleave=1. A variant with a
(0 - %n) + 1 backedge value gives sub <4 x i64> splat (i64 1), %broadcast.splat in the same position.
What I see with -vplan-print-after=materializeBroadcasts,combineRecipes: the first-order recurrence's backedge value is a
loop-invariant mul %x, 2. VPlan simplification rewrites it into a new VPInstruction shl %x, 1, which is hoisted to
vector.ph, and materializeBroadcasts turns it into shl (broadcast %x), 1. A later simplifyRecipe folds
extract-last-lane(A) → A because vputils::isSingleScalar(A) is true, since Broadcast counts as
uniformity-preserving. So the scalar resume phi in scalar.ph gets the vector value. Writing the backedge value as
shl %x, 1, add %x, 1 or mul %x, 3, or computing it in entry, does not fail. My guess, not checked: the
ExtractLastLane fold should require that A actually generates a scalar.
Found with a mutation-based IR fuzzer. Triage, test-case minimization and parts of this write-up were assisted by an LLM; verified the reproducer on 9dce18f0e.
Assisted-by: Claude (Anthropic)