# Why is LoopVectorization deprecated?

**URL:** <https://discourse.julialang.org/t/why-is-loopvectorization-deprecated/109547>\
**Category:** Performance\
**Tags:** loopvectorization\
**Created:** [February 1, 2024, 2:13am UTC](https://discourse.julialang.org/t/why-is-loopvectorization-deprecated/109547 "2024-02-01T02:13:46Z")\
**Posts on this page:** 1\
**Showing post:** 121

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [July 25, 2024, 8:45pm UTC](https://discourse.julialang.org/t/why-is-loopvectorization-deprecated/109547/121 "2024-07-25T20:45:49Z")

</div>

> <https://github.com/JuliaSIMD/LoopVectorization.jl/issues/525#issue-2074438380>
>
> LoopVectorization.jl's generated IR seems to cause segfaults on 1.11, as observe…d on PkgEval with at least 6 packages (MCPhylo,jl, LocalPoly.jl, VectorizedReduction.jl, NaNStatistics.jl, TimeSeriesClassification.jl, PlmDCA.jl). See this report for details: https://s3.amazonaws.com/julialang-reports/nanosoldier/pkgeval/by\_hash/2cbecf4\_vs\_18b4f3f/report.html
> 
> @chriselrod I'm opening a new issue because https://github.com/JuliaSIMD/LoopVectorization.jl/issues/518 was closed, and to list all issues in case somebody wants to tackle this.
> 
> \---
> 
> Some of the errors that I've encountered:
> 
> An LLVM assertion, as seen with MCPhylo.jl (requires assertions build of Julia):
> 
> \`\`\`
> julia: /workspace/srcdir/llvm-project/llvm/lib/IR/Instructions.cpp:2561: void llvm::InsertValueInst::init(llvm::Value\*, llvm::Value\*, llvm::ArrayRef\<unsigned int\>, const llvm::Twine&): Assertion \`ExtractValueInst::getIndexedType(Agg-\>getType(), Idxs) == Val-\>getType() && "Inserted value must match indexed type!"' failed.
> 
> \[177\] signal 6 (-6): Aborted
> in expression starting at /home/pkgeval/.julia/packages/MCPhylo/KWPlY/test/distributions/phylodist.jl:1
> gsignal at /lib/x86\_64-linux-gnu/libc.so.6 (unknown line)
> abort at /lib/x86\_64-linux-gnu/libc.so.6 (unknown line)
> unknown function (ip: 0x7fbeac0f040e)
> \_\_assert\_fail at /lib/x86\_64-linux-gnu/libc.so.6 (unknown line)
> \_ZN4llvm15InsertValueInst4initEPNS\_5ValueES2\_NS\_8ArrayRefIjEERKNS\_5TwineE at /opt/julia/bin/../lib/julia/libLLVM-15jl.so (unknown line)
> InsertValueInst at /source/usr/include/llvm/IR/Instructions.h:2640 \[inlined\]
> Create at /source/usr/include/llvm/IR/Instructions.h:2565 \[inlined\]
> CreateInsertValue at /source/usr/include/llvm/IR/IRBuilder.h:2343
> emit\_new\_struct at /source/src/cgutils.cpp:3870
> emit\_new\_struct at /source/src/julia.h:1704
> emit\_expr at /source/src/codegen.cpp:5945
> emit\_ssaval\_assign at /source/src/codegen.cpp:5367
> emit\_stmtpos at /source/src/codegen.cpp:5642 \[inlined\]
> emit\_function at /source/src/codegen.cpp:8810
> jl\_emit\_code at /source/src/codegen.cpp:9144
> jl\_emit\_codeinst at /source/src/codegen.cpp:9227
> \_jl\_compile\_codeinst at /source/src/jitlayers.cpp:220
> jl\_generate\_fptr\_impl at /source/src/jitlayers.cpp:525
> jl\_compile\_method\_internal at /source/src/gf.c:2509 \[inlined\]
> jl\_compile\_method\_internal at /source/src/gf.c:2397
> \_jl\_invoke at /source/src/gf.c:2912 \[inlined\]
> ijl\_apply\_generic at /source/src/gf.c:3097
> logpdf at /home/pkgeval/.julia/packages/MCPhylo/KWPlY/src/distributions/Phylodist.jl:118
> \`\`\`
> 
> A segfault during \`vload\`, as seen with NaNStatistics.jl and PlmDCA.jl:
> 
> \`\`\`
> \[60\] signal 11 (2): Segmentation fault
> in expression starting at /home/pkgeval/.julia/packages/NaNStatistics/oBRaH/test/testArrayStats.jl:80
> macro expansion at /home/pkgeval/.julia/packages/VectorizationBase/0dXyA/src/llvm\_intrin/memory\_addr.jl:987 \[inlined\]
> \_\_vload at /home/pkgeval/.julia/packages/VectorizationBase/0dXyA/src/llvm\_intrin/memory\_addr.jl:987 \[inlined\]
> \_vload at /home/pkgeval/.julia/packages/VectorizationBase/0dXyA/src/strided\_pointers/stridedpointers.jl:95 \[inlined\]
> macro expansion at /home/pkgeval/.julia/packages/VectorizationBase/0dXyA/src/vecunroll/memory.jl:60 \[inlined\]
> \_vload\_unroll at /home/pkgeval/.julia/packages/VectorizationBase/0dXyA/src/vecunroll/memory.jl:535 \[inlined\]
> \_vload at /home/pkgeval/.julia/packages/VectorizationBase/0dXyA/src/vecunroll/memory.jl:771 \[inlined\]
> macro expansion at /home/pkgeval/.julia/packages/LoopVectorization/7iB2K/src/reconstruct\_loopset.jl:1107 \[inlined\]
> \_turbo\_! at /home/pkgeval/.julia/packages/LoopVectorization/7iB2K/src/reconstruct\_loopset.jl:1107 \[inlined\]
> \_nanmean at /home/pkgeval/.julia/packages/NaNStatistics/oBRaH/src/ArrayStats/ArrayStats.jl:344
> \_\_nanmean at /home/pkgeval/.julia/packages/NaNStatistics/oBRaH/src/ArrayStats/ArrayStats.jl:308 \[inlined\]
> \#nanmean#5 at /home/pkgeval/.julia/packages/NaNStatistics/oBRaH/src/ArrayStats/ArrayStats.jl:307 \[inlined\]
> nanmean at /home/pkgeval/.julia/packages/NaNStatistics/oBRaH/src/ArrayStats/ArrayStats.jl:307
> \`\`\`
> 
> A segfault during \`vadd\_fast\` as seen with VectorizedReductions.jl:
> 
> \`\`\`
> \[12\] signal 11 (2): Segmentation fault
> in expression starting at /home/pkgeval/.julia/packages/VectorizedReduction/bsnWJ/test/reduce.jl:4
> macro expansion at /home/pkgeval/.julia/packages/VectorizationBase/xE5Tx/src/llvm\_intrin/binary\_ops.jl:31 \[inlined\]
> vadd\_fast at /home/pkgeval/.julia/packages/VectorizationBase/xE5Tx/src/llvm\_intrin/binary\_ops.jl:31 \[inlined\]
> fmap at /home/pkgeval/.julia/packages/VectorizationBase/xE5Tx/src/vecunroll/fmap.jl:11 \[inlined\]
> fmap at /home/pkgeval/.julia/packages/VectorizationBase/xE5Tx/src/vecunroll/fmap.jl:11 \[inlined\]
> fmap at /home/pkgeval/.julia/packages/VectorizationBase/xE5Tx/src/vecunroll/fmap.jl:11 \[inlined\]
> fmap at /home/pkgeval/.julia/packages/VectorizationBase/xE5Tx/src/vecunroll/fmap.jl:11 \[inlined\]
> fmap at /home/pkgeval/.julia/packages/VectorizationBase/xE5Tx/src/vecunroll/fmap.jl:11 \[inlined\]
> fmap at /home/pkgeval/.julia/packages/VectorizationBase/xE5Tx/src/vecunroll/fmap.jl:11 \[inlined\]
> fmap at /home/pkgeval/.julia/packages/VectorizationBase/xE5Tx/src/vecunroll/fmap.jl:11 \[inlined\]
> vadd\_fast at /home/pkgeval/.julia/packages/VectorizationBase/xE5Tx/src/vecunroll/fmap.jl:111 \[inlined\]
> add\_fast at /home/pkgeval/.julia/packages/VectorizationBase/xE5Tx/src/base\_defs.jl:91 \[inlined\]
> macro expansion at /home/pkgeval/.julia/packages/LoopVectorization/7iB2K/src/reconstruct\_loopset.jl:1107 \[inlined\]
> \_turbo\_! at /home/pkgeval/.julia/packages/LoopVectorization/7iB2K/src/reconstruct\_loopset.jl:1107 \[inlined\]
> macro expansion at /home/pkgeval/.julia/packages/VectorizedReduction/bsnWJ/src/vmapreduce.jl:236 \[inlined\]
> vvmapreduce at /home/pkgeval/.julia/packages/VectorizedReduction/bsnWJ/src/vmapreduce.jl:231
> vvreduce at /home/pkgeval/.julia/packages/VectorizedReduction/bsnWJ/src/vmapreduce.jl:147
> \`\`\`
> 
> The source of bad IR hasn't been fully determined yet, but it seems to be the \`Expr(:new)\` that's generated to pass structs by value instead of by reference: https://github.com/JuliaLang/julia/issues/52702#issuecomment-1874492883.
> 
> \---
> 
> Deprecating LoopVectorization.jl isn't possible, because:
> 
> \- some packages, e.g. RecursiveFactorizations.jl, inspect LoopVectorization.jl internals: https://github.com/JuliaSIMD/LoopVectorization.jl/issues/520
> \- the transformation of \`@turbo\` changes semantics, https://github.com/JuliaSIMD/LoopVectorization.jl/pull/523#issuecomment-1884883071
> 
> So the only solution forwards seems fixing LoopVectorization.jl. I've taken a first attempt at it in https://github.com/JuliaSIMD/LoopVectorization.jl/pull/523, but just removing the \`Expr(:new)\` optimization isn't sufficient, and there's other issues (see above).

> `check_empty=true/false` didn’t change between early Julia versions and 1.10.  
> We could make `check_empty=true` the default.

> Closing this because tests pass on 1.11, while `check_empty=false` should’ve also caused segfaults in older Julia versions. [Test cleanup · JuliaSIMD/LoopVectorization.jl@eeaa0b2 · GitHub](https://github.com/JuliaSIMD/LoopVectorization.jl/actions/runs/8946228352)

But if anyone wants to contribute towards v1.12, the SciML Small Grants outlines that project and we’d be happy to up the ante. Maintenance never ends, so it’ll need v1.13 updates too!

---

_[View the full topic](https://discourse.julialang.org/t/why-is-loopvectorization-deprecated/109547)._
