<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/108700>108700</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[SLPVectorizer] Assertion `OpIdx < Operands.size() && "Off bounds"' 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>
dtcxzyw
</td>
</tr>
</table>
<pre>
Reproducer: https://godbolt.org/z/8Es17cqcW
```
; bin/opt -passes=slp-vectorizer reduced.ll -S
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
define i16 @main() {
entry:
%conv73.i.peel.i.i.i.i.i = xor i64 0, 0
%and.i.i.peel.i.i.i.i.i = and i64 0, 0
%xor2.i.i.peel.i.i.i.i.i = or i64 %and.i.i.peel.i.i.i.i.i, 0
%sub.i.i.peel.i.i.i.i.i = or i64 %xor2.i.i.peel.i.i.i.i.i, 0
%xor3.i.i.peel.i.i.i.i.i = xor i64 %sub.i.i.peel.i.i.i.i.i, %conv73.i.peel.i.i.i.i.i
%and4.i.i.peel.i.i.i.i.i = and i64 %xor3.i.i.peel.i.i.i.i.i, 0
%cmp.i.i.peel.i.i.i.i.i = icmp slt i64 %and4.i.i.peel.i.i.i.i.i, 0
%0 = trunc i64 %conv73.i.peel.i.i.i.i.i to i16
%1 = or i16 0, %0
%conv73.i.i.i.i.i.i = xor i64 0, 0
%and.i.i.i.i.i.i.i = and i64 0, 0
%xor2.i.i.i.i.i.i.i = or i64 %and.i.i.i.i.i.i.i, 0
%sub.i.i.i.i.i.i.i = or i64 %xor2.i.i.i.i.i.i.i, 0
%xor3.i.i.i.i.i.i.i = xor i64 %sub.i.i.i.i.i.i.i, %conv73.i.i.i.i.i.i
%and4.i.i.i.i.i.i.i = and i64 %xor3.i.i.i.i.i.i.i, 0
%cmp.i.i.i.i.i.i.i = icmp slt i64 %and4.i.i.i.i.i.i.i, 0
%2 = trunc i64 %conv73.i.i.i.i.i.i to i16
%3 = or i16 0, %2
%4 = select i1 %cmp.i.i.i.i.i.i.i, i16 0, i16 %3
%5 = select i1 %cmp.i.i.peel.i.i.i.i.i, i16 0, i16 %1
%6 = zext i32 0 to i64
%add.i.i.peel.i369.i.i.i.i = or i64 %6, 0
%or.i.peel.i371.i.i.i.i = or i64 %add.i.i.peel.i369.i.i.i.i, 0
%conv72.i.peel.i372.i.i.i.i = shl i64 %or.i.peel.i371.i.i.i.i, 0
%sext.i.peel.i373.i.i.i.i = ashr i64 %conv72.i.peel.i372.i.i.i.i, 0
%conv73.i.peel.i374.i.i.i.i = xor i64 %sext.i.peel.i373.i.i.i.i, 0
%and.i.i.peel.i376.i.i.i.i = and i64 0, 0
%xor2.i.i.peel.i377.i.i.i.i = or i64 %and.i.i.peel.i376.i.i.i.i, 0
%sub.i.i.peel.i378.i.i.i.i = or i64 %xor2.i.i.peel.i377.i.i.i.i, 0
%xor3.i.i.peel.i379.i.i.i.i = xor i64 %sub.i.i.peel.i378.i.i.i.i, %conv73.i.peel.i374.i.i.i.i
%and4.i.i.peel.i380.i.i.i.i = and i64 %xor3.i.i.peel.i379.i.i.i.i, 0
%cmp.i.i.peel.i381.i.i.i.i = icmp slt i64 %and4.i.i.peel.i380.i.i.i.i, 0
%7 = trunc i64 %conv73.i.peel.i374.i.i.i.i to i16
%8 = or i16 0, %7
%9 = select i1 %cmp.i.i.peel.i381.i.i.i.i, i16 0, i16 %8
%conv76.i.i.i.i.i.i = and i16 %4, %5
%conv76.i.peel.i384.i.i.i.i = and i16 %conv76.i.i.i.i.i.i, %9
%10 = zext i32 0 to i64
%add.i.i.peel.i417.i.i.i.i = or i64 %10, 0
%or.i.peel.i419.i.i.i.i = or i64 %add.i.i.peel.i417.i.i.i.i, 0
%conv72.i.peel.i420.i.i.i.i = shl i64 %or.i.peel.i419.i.i.i.i, 0
%sext.i.peel.i421.i.i.i.i = ashr i64 %conv72.i.peel.i420.i.i.i.i, 0
%conv73.i.peel.i422.i.i.i.i = xor i64 %sext.i.peel.i421.i.i.i.i, 0
%and.i.i.peel.i424.i.i.i.i = and i64 0, 0
%xor2.i.i.peel.i425.i.i.i.i = or i64 %and.i.i.peel.i424.i.i.i.i, 0
%sub.i.i.peel.i426.i.i.i.i = or i64 %xor2.i.i.peel.i425.i.i.i.i, 0
%xor3.i.i.peel.i427.i.i.i.i = xor i64 %sub.i.i.peel.i426.i.i.i.i, %conv73.i.peel.i422.i.i.i.i
%and4.i.i.peel.i428.i.i.i.i = and i64 %xor3.i.i.peel.i427.i.i.i.i, 0
%cmp.i.i.peel.i429.i.i.i.i = icmp slt i64 %and4.i.i.peel.i428.i.i.i.i, 0
%11 = trunc i64 %conv73.i.peel.i422.i.i.i.i to i16
%12 = or i16 0, %11
%13 = select i1 %cmp.i.i.peel.i429.i.i.i.i, i16 0, i16 %12
%conv76.i.peel.i432.i.i.i.i = and i16 %conv76.i.peel.i384.i.i.i.i, %13
ret i16 %conv76.i.peel.i432.i.i.i.i
}
```
```
opt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:3180: llvm::slpvectorizer::BoUpSLP::ValueList& llvm::slpvectorizer::BoUpSLP::TreeEntry::getOperand(unsigned int): Assertion `OpIdx < Operands.size() && "Off bounds"' 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 <source>
1. Running pass "function(slp-vectorizer)" on module "<source>"
2. Running pass "slp-vectorizer" on function "main"
#0 0x0000000005016bb8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5016bb8)
#1 0x00000000050142fc SignalHandler(int) Signals.cpp:0:0
#2 0x00007955e2242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#3 0x00007955e22969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#4 0x00007955e2242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#5 0x00007955e22287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#6 0x00007955e222871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#7 0x00007955e2239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#8 0x000000000406f2b8 llvm::slpvectorizer::BoUpSLP::TreeEntry::getOperand(unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x406f2b8)
#9 0x00000000040f675e llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&)::'lambda0'(llvm::function_ref<llvm::InstructionCost (unsigned int)>, llvm::function_ref<llvm::InstructionCost (llvm::InstructionCost)>)::operator()(llvm::function_ref<llvm::InstructionCost (unsigned int)>, llvm::function_ref<llvm::InstructionCost (llvm::InstructionCost)>) const SLPVectorizer.cpp:0:0
#10 0x00000000040f74aa llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40f74aa)
#11 0x0000000004114641 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4114641)
#12 0x00000000041198c8 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0
#13 0x000000000411bfe1 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x411bfe1)
#14 0x0000000004120876 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (.constprop.0) SLPVectorizer.cpp:0:0
#15 0x0000000004124e16 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4124e16)
#16 0x000000000412b2e1 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
#17 0x000000000412bf6b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x412bf6b)
#18 0x0000000002f0034e llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2f0034e)
#19 0x0000000004e18ff8 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e18ff8)
#20 0x0000000000e06a0e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe06a0e)
#21 0x0000000004e17a1e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e17a1e)
#22 0x0000000000e0621e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe0621e)
#23 0x0000000004e17450 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e17450)
#24 0x00000000008fce52 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8fce52)
#25 0x00000000008efcdc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8efcdc)
#26 0x00007955e2229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#27 0x00007955e2229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#28 0x00000000008e77ae _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8e77ae)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcW1tz2zjS_TX0C0oqEqB4efCDfNEk9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