Issue 234176
Summary [SLPVectorizer] Crash in getStoreMinimumVF on stores of small literal struct types such as { i1, i16 }
Labels new issue
Assignees
Reporter vekazt
    The SLP vectorizer crashes on two adjacent stores of a small literal struct value.

Reproducer (`opt -passes=slp-vectorizer`):

```llvm
target triple = "x86_64-unknown-linux-gnu"

define void @f(ptr %p, { i1, i16 } %x, { i1, i16 } %y) {
  store { i1, i16 } %x, ptr %p, align 4
  %q = getelementptr i8, ptr %p, i64 4
  store { i1, i16 } %y, ptr %q, align 4
  ret void
}
```

With assertions (trunk on Compiler Explorer, 2026-10-21):

```
opt: llvm/lib/IR/Type.cpp:845: static llvm::FixedVectorType* llvm::FixedVectorType::get(llvm::Type*, unsigned int): Assertion `isValidElementType(ElementType) && "Element type of a VectorType must " "be an integer, floating point, " "pointer type, or a valid target " "extension type."' failed.
Stack dump:
0.	Program arguments: opt -S -passes=slp-vectorizer <source>
1.	Running pass "function(slp-vectorizer)" on module "<source>"
2.	Running pass "slp-vectorizer" on function "f"
 #9 llvm::FixedVectorType::get(llvm::Type*, unsigned int)
#10 llvm::X86TTIImpl::getStoreMinimumVF(unsigned int, llvm::Type*, llvm::Type*, llvm::Align, unsigned int) const
#11 llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet<...>&, bool)
#12 llvm::SLPVectorizerPass::vectorizeStoreChains(llvm::slpvectorizer::BoUpSLP&)::'lambda3'(...)
#13 llvm::SLPVectorizerPass::vectorizeStoreChains(llvm::slpvectorizer::BoUpSLP&)
#14 llvm::SLPVectorizerPass::runImpl(...)
#15 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&)
```

Without assertions, opt crashes in `llvm::VectorType::get` on the same path. `clang -O3` crashes the same way on modules that contain such stores.

Versions:

- 22.1.0: no crash; the stores are left unchanged.
- 23.1.0, 23.1.3 (Arch Linux package) and trunk: crash.

Notes:

- With `-passes=slp-vectorizer` alone, structs of 4 bytes or less crash: `{ i1, i8 }`, `{ i1, i16 }`, `{ i8, i16 }`, `{ i16, i16 }`. Eight-byte structs such as `{ i1, i32 }` and `{ i32, i32 }` do not, presumably because the base `getStoreMinimumVF` only builds a vector type while `VF > 2`.
- In the full `-O3` pipeline, InstCombine first splits stores of padding-free structs such as `{ i1, i8 }` into per-field stores. Padded structs such as `{ i1, i16 }` stay whole and reach SLP, so they crash `clang -O3`.
- Likely cause (not bisected): #199433 (074b6beca94b) changed `isValidElementType` in SLPVectorizer.cpp from `VectorType::isValidElementType(Ty)` to `canVectorizeTy(Ty)`, which accepts unpacked literal structs of scalars. `collectSeedInstructions` uses `isValidElementType` to filter store seeds, so struct-typed stores now reach `vectorizeStores` and `getStoreMinimumVF`. The comment on `canVectorizeTy` in VectorTypeUtils.h says a vectorized struct can't be used for vectorizing loads/stores.
- Related: #221715 (struct-typed scalars in `canBuildSplitNode`). This reproducer still crashes on trunk.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to