<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/106655>106655</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[SLP] Assertion `I >= 0 && I < (NumOpElts * 2) && "Out-of-bounds shuffle mask element"' failed.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm:SLPVectorizer,
crash-on-valid
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
rupprecht
</td>
</tr>
</table>
<pre>
Live link: https://godbolt.org/z/nePMscjGr
Test case:
```ll
define void @func(i32 %0) {
%2 = shl i32 %0, 0
%3 = sext i32 %2 to i64
%4 = shl i32 0, 0
%5 = sext i32 %4 to i64
%6 = or i32 0, 0
%7 = or i32 0, 0
%8 = zext i32 %6 to i64
%9 = zext i32 %7 to i64
%10 = zext i32 0 to i64
%11 = zext i32 0 to i64
%12 = zext i32 0 to i64
%13 = zext i32 0 to i64
%14 = zext i32 0 to i64
%15 = zext i32 0 to i64
%16 = zext i32 0 to i64
%17 = zext i32 0 to i64
%18 = zext i32 0 to i64
%19 = zext i32 0 to i64
%20 = zext i32 0 to i64
%21 = zext i32 0 to i64
%22 = zext i32 0 to i64
%23 = zext i32 0 to i64
%24 = zext i32 0 to i64
%25 = zext i32 0 to i64
%26 = zext i32 0 to i64
%27 = or i64 %3, 0
%28 = or i64 %3, %8
%29 = or i64 %3, %9
%30 = or i64 %3, %10
%31 = or i64 %3, %11
%32 = or i64 %3, %12
%33 = or i64 %3, %13
%34 = or i64 %3, %14
%35 = or i64 %3, %15
%36 = or i64 %3, %16
%37 = or i64 %3, %17
%38 = or i64 %3, %18
%39 = or i64 %3, %19
%40 = or i64 %3, %20
%41 = or i64 %3, %21
%42 = or i64 %3, %22
%43 = or i64 %3, %23
%44 = or i64 %3, %24
%45 = or i64 %3, %25
%46 = or i64 %3, 0
%47 = or i64 %3, 0
%48 = or i64 %3, 0
%49 = or i64 %3, 0
%50 = or i64 %3, 0
%51 = or i64 %3, 0
%52 = or i64 %3, 0
%53 = or i64 %3, 0
%54 = or i64 %3, 0
%55 = or i64 %3, 0
%56 = or i64 %3, 0
%57 = or i64 %3, 0
%58 = or i64 %3, 0
%59 = icmp slt i64 %28, 0
%60 = icmp slt i64 %29, 0
%61 = icmp slt i64 %30, 0
%62 = icmp slt i64 %31, 0
%63 = icmp slt i64 %32, 0
%64 = icmp slt i64 %33, 0
%65 = icmp slt i64 %34, 0
%66 = icmp slt i64 %35, 0
%67 = icmp slt i64 %36, 0
%68 = icmp slt i64 %37, 0
%69 = icmp slt i64 %38, 0
%70 = icmp slt i64 %39, 0
%71 = icmp slt i64 %40, 0
%72 = icmp slt i64 %41, 0
%73 = icmp slt i64 %42, 0
%74 = icmp slt i64 %43, 0
%75 = icmp slt i64 %44, 0
%76 = icmp slt i64 %45, 0
%77 = icmp slt i64 %46, 0
%78 = icmp slt i64 %47, 0
%79 = icmp slt i64 %48, 0
%80 = icmp slt i64 %49, 0
%81 = icmp slt i64 %50, 0
%82 = icmp slt i64 %51, 0
%83 = icmp slt i64 %52, 0
%84 = icmp slt i64 %53, 0
%85 = icmp slt i64 %54, 0
%86 = icmp slt i64 %55, 0
%87 = icmp slt i64 %56, 0
%88 = icmp slt i64 %57, 0
%89 = icmp slt i64 %58, 0
%90 = and i1 false, %59
%91 = and i1 false, %60
%92 = and i1 false, %61
%93 = and i1 false, %62
%94 = and i1 false, %63
%95 = and i1 false, %64
%96 = and i1 false, %65
%97 = and i1 false, %66
%98 = and i1 false, %67
%99 = and i1 false, %68
%100 = and i1 false, %69
%101 = and i1 false, %70
%102 = and i1 false, %71
%103 = and i1 false, %72
%104 = and i1 false, %73
%105 = and i1 false, %74
%106 = and i1 false, %75
%107 = and i1 false, %76
%108 = icmp eq i32 %2, 0
%109 = and i1 false, %77
%110 = and i1 false, %78
%111 = and i1 false, %79
%112 = and i1 false, %80
%113 = and i1 false, %81
%114 = and i1 false, %82
%115 = and i1 false, %83
%116 = and i1 false, %84
%117 = and i1 false, %85
%118 = and i1 false, %86
%119 = or i64 %5, %26
%120 = getelementptr float, ptr addrspace(1) null, i64 %119
%121 = icmp slt i64 %119, 0
ret void
}
```
Running via `opt --passes=slp-vectorizer -slp-vectorize-hor=false`:
```sh
opt: /root/llvm-project/llvm/lib/IR/Instructions.cpp:1853: bool isSingleSourceMaskImpl(llvm::ArrayRef<int>, int): Assertion `I >= 0 && I < (NumOpElts * 2) && "Out-of-bounds shuffle mask element"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S --passes=slp-vectorizer -slp-vectorize-hor=false <source>
1. Running pass "function(slp-vectorizer)" on module "<source>"
2. Running pass "slp-vectorizer" on function "func"
#0 0x0000000004fa4138 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fa4138)
#1 0x0000000004fa18ac SignalHandler(int) Signals.cpp:0:0
#2 0x000073f701e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#3 0x000073f701e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#4 0x000073f701e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#5 0x000073f701e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#6 0x000073f701e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#7 0x000073f701e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#8 0x0000000004d097f6 isSingleSourceMaskImpl(llvm::ArrayRef<int>, int) Instructions.cpp:0:0
#9 0x0000000004d1097a llvm::ShuffleVectorInst::isExtractSubvectorMask(llvm::ArrayRef<int>, int, int&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d1097a)
#10 0x000000000400fc53 (anonymous namespace)::BaseShuffleAnalysis::isIdentityMask(llvm::ArrayRef<int>, llvm::FixedVectorType const*, bool) SLPVectorizer.cpp:0:0
#11 0x0000000004043781 (anonymous namespace)::BaseShuffleAnalysis::peekThroughShuffles(llvm::Value*&, llvm::SmallVectorImpl<int>&, bool) SLPVectorizer.cpp:0:0
#12 0x000000000405bd21 llvm::Value* (anonymous namespace)::BaseShuffleAnalysis::createShuffle<llvm::Value*, llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::ShuffleIRBuilder>(llvm::Value*, llvm::Value*, llvm::ArrayRef<int>, llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::ShuffleIRBuilder&) SLPVectorizer.cpp:0:0
#13 0x000000000405c50a llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::createShuffle(llvm::Value*, llvm::Value*, llvm::ArrayRef<int>) (.isra.0) SLPVectorizer.cpp:0:0
#14 0x000000000405ce73 llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::finalize(llvm::ArrayRef<int>, llvm::ArrayRef<std::pair<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, unsigned int>>, unsigned int, llvm::function_ref<void (llvm::Value*&, llvm::SmallVectorImpl<int>&)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x405ce73)
#15 0x000000000405d3d9 llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool)::'lambda1'(llvm::Value*, llvm::ArrayRef<int>)::operator()(llvm::Value*, llvm::ArrayRef<int>) const SLPVectorizer.cpp:0:0
#16 0x0000000004095c0a llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4095c0a)
#17 0x0000000004097032 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4097032)
#18 0x0000000004095aa8 llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4095aa8)
#19 0x0000000004097294 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4097294)
#20 0x00000000040b31cc llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::MapVector<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u>, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int>>, llvm::SmallVector<std::pair<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u>>, 0u>> const&, llvm::SmallVectorImpl<std::pair<llvm::Value*, llvm::Value*>>&, llvm::Instruction*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40b31cc)
#21 0x00000000040b6d45 llvm::slpvectorizer::BoUpSLP::vectorizeTree() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40b6d45)
#22 0x00000000040c3b2a llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40c3b2a)
#23 0x00000000040c78a7 bool llvm::SLPVectorizerPass::vectorizeCmpInsts<std::reverse_iterator<llvm::CmpInst* const*>>(llvm::iterator_range<std::reverse_iterator<llvm::CmpInst* const*>>, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40c78a7)
#24 0x00000000040cb5d0 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40cb5d0)
#25 0x00000000040d1d49 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0
#26 0x00000000040d29fb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40d29fb)
...
```
Bisected to f3d2609af3031ddb54030548e86335f295cf49ca / https://github.com/llvm/llvm-project/pull/104144
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcW1tv2zoS_jXMC2FDIqnbQx6cJt4tkG6DJnteC0qibZ7Iopakskl__YKS7IgSWcetsbs4RXOx-HE4833Dy1AIVYpva8auQXQDotsr2uqdkNeybRrJip2-ykX5dn3PXxiseP0M8ArutG4UwCuA1gCtt6LMRaWXQm4BWv8AaF2zhy-q-PNvEgS3IFj135-Y0rCgipmOo-cgDvr_VdU_KNmG1wy-CF5CQIJNWxcApRwjCFAUAJRBkNz0UGgeIQjwLVS7Cr5jPsFgQAAU4R7AXvUBgaAWkMdkZIVYViwTpjma2SBzG3EHEtJtIvlpa9q1_hgNEM8HyGagZA4KAxsVOCDhaQg6DcE_hRgEOW0kOg2JT0OS05D0NCQ7CUGnyUU_J9cgTnOLfs5tBzlNLjpNLjpNLnrP3Jh0E2qavCh1IUxWj0GZB5SNQDjwgMLxeDj0ocIxCvlQaIzCPhQeo4gPNWYKRz5UNEbFPlQ8RjlZ73J9jPIxH46pxz7qwzH3xMc9GnNPfNyjMffExz0ac0983KMx98THPbIWcB_3aMw9cXJvxXcy24mTcwvh5NvaT5xcWwgnz6NtLXJSbJlw0mshnNRaCCetFuIkpdFJSqOTlA57Hy_2DVSVPuBQOgXGgRuYTeiLQycOz3bmGLmB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