<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/89187>89187</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [SLPVectorizer] opt crashed and triggered assertion " `Mask[Idx] == PoisonMaskElem && "InsertElementInstruction used already.""
        </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>
          XChy
      </td>
    </tr>
</table>

<pre>
    Reproducible on godbolt: https://godbolt.org/z/da1rdM4K6

Reduced:
```llvm
define void @_ZN6duckdb14BinaryExecutor11ExecuteFlatIaabNS_35BinarySingleArgumentOperatorWrapperENS_9NotEqualsEbLb0ELb1EEEvRNS_6VectorES5_S5_mT4_(i8 %0, i8 %1) {
entry:
  %wide.load.i8 = load i8, ptr getelementptr (i8, ptr null, i32 8), align 1
  %wide.load.i9163 = load i8, ptr getelementptr (i8, ptr null, i32 9), align 1
  %wide.load.i10 = load i8, ptr getelementptr (i8, ptr null, i32 10), align 1
  %wide.load.i11164 = load i8, ptr getelementptr (i8, ptr null, i32 11), align 1
  %wide.load.i12 = load i8, ptr getelementptr (i8, ptr null, i32 12), align 1
 %wide.load.i13 = load i8, ptr getelementptr (i8, ptr null, i32 13), align 1
  %wide.load.i14 = load i8, ptr getelementptr (i8, ptr null, i32 14), align 1
  %wide.load.i15165 = load i8, ptr getelementptr (i8, ptr null, i32 15), align 1
  %wide.load.upto8237 = insertelement <16 x i8> zeroinitializer, i8 %wide.load.i8, i64 8
  %wide.load.upto9238 = insertelement <16 x i8> %wide.load.upto8237, i8 %wide.load.i9163, i64 9
 %wide.load.upto10239 = insertelement <16 x i8> %wide.load.upto9238, i8 %wide.load.i10, i64 10
  %wide.load.upto11240 = insertelement <16 x i8> %wide.load.upto10239, i8 %wide.load.i11164, i64 11
  %wide.load.upto12241 = insertelement <16 x i8> %wide.load.upto11240, i8 %wide.load.i12, i64 12
 %wide.load.upto13242 = insertelement <16 x i8> %wide.load.upto12241, i8 %wide.load.i13, i64 13
  %wide.load.upto14243 = insertelement <16 x i8> %wide.load.upto13242, i8 %wide.load.i14, i64 1
  %wide.load = insertelement <16 x i8> %wide.load.upto14243, i8 %wide.load.i15165, i64 0
 %wide.load.i15 = extractelement <16 x i8> %wide.load, i64 15
  %2 = icmp ne i8 %0, 0
  %3 = icmp ne i8 %1, 0
  %4 = icmp ne i8 %0, 0
  %.i3 = icmp ne i8 %0, 0
  %.i4 = icmp ne i8 %0, 0
  %5 = icmp ne i8 %0, 0
 %6 = icmp ne i8 %0, 0
  %7 = icmp ne i8 0, 0
  %8 = icmp ne i8 %0, 0
  %.i9 = icmp ne i8 %wide.load.i9163, 0
  %9 = icmp ne i8 %0, 0
 %10 = icmp ne i8 %0, 0
  %11 = icmp ne i8 %0, 0
  %12 = icmp ne i8 %0, 0
  %13 = icmp ne i8 %0, 0
  %.i15 = icmp ne i8 %wide.load.i15, 0
 %.upto0244 = insertelement <16 x i1> zeroinitializer, i1 %2, i64 0
 %.upto1245 = insertelement <16 x i1> %.upto0244, i1 %3, i64 1
  %.upto2246 = insertelement <16 x i1> %.upto1245, i1 %4, i64 2
  %.upto3247 = insertelement <16 x i1> %.upto2246, i1 %.i3, i64 3
  %.upto4248 = insertelement <16 x i1> %.upto3247, i1 %.i4, i64 4
  %.upto5249 = insertelement <16 x i1> %.upto4248, i1 %5, i64 5
  %.upto6250 = insertelement <16 x i1> %.upto5249, i1 %6, i64 6
  %.upto7251 = insertelement <16 x i1> %.upto6250, i1 %7, i64 7
  %.upto8252 = insertelement <16 x i1> %.upto7251, i1 %8, i64 8
  %.upto9253 = insertelement <16 x i1> %.upto8252, i1 %.i9, i64 9
  %.upto10254 = insertelement <16 x i1> %.upto9253, i1 %9, i64 10
  %.upto11255 = insertelement <16 x i1> %.upto10254, i1 %10, i64 11
  %.upto12256 = insertelement <16 x i1> %.upto11255, i1 %11, i64 12
  %.upto13257 = insertelement <16 x i1> %.upto12256, i1 %12, i64 13
  %.upto14 = insertelement <16 x i1> %.upto13257, i1 %13, i64 14
  %14 = insertelement <16 x i1> %.upto14, i1 %.i15, i64 15
  ret void
}
```

Output:
```
opt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:13365: llvm::Value* llvm::slpvectorizer::BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap&, llvm::SmallVectorImpl<std::pair<llvm::Value*, llvm::Value*> >&, llvm::Instruction*): Assertion `Mask[Idx] == PoisonMaskElem && "InsertElementInstruction used already."' 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>
 #0 0x0000000004d1f298 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d1f298)
 #1 0x0000000004d1c9ec SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f1dcca42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007f1dcca969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x00007f1dcca42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x00007f1dcca287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x00007f1dcca2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #7 0x00007f1dcca39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #8 0x0000000003eacfa3 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+0x3eacfa3)
 #9 0x0000000003ead245 llvm::slpvectorizer::BoUpSLP::vectorizeTree() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3ead245)
#10 0x0000000003eba06e llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3eba06e)
#11 0x0000000003ebc01e llvm::SLPVectorizerPass::vectorizeInsertElementInst(llvm::InsertElementInst*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3ebc01e)
#12 0x0000000003ebc9cb llvm::SLPVectorizerPass::vectorizeInserts(llvm::SmallSetVector<llvm::Instruction*, 8u>&, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3ebc9cb)
#13 0x0000000003ebd648 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&)::'lambda2'(bool)::operator()(bool) const SLPVectorizer.cpp:0:0
#14 0x0000000003ebfce3 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3ebfce3)
#15 0x0000000003ec3e17 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
#16 0x0000000003ec48f3 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3ec48f3)
#17 0x0000000002d719ce 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+0x2d719ce)
#18 0x0000000000db6eb4 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+0xdb6eb4)
#19 0x0000000004b2f4de llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4b2f4de)
#20 0x0000000000d9b55e 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+0xd9b55e)
#21 0x0000000004b2d3ec llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4b2d3ec)
#22 0x00000000008c8aa2 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+0x8c8aa2)
#23 0x00000000008bc2f5 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8bc2f5)
#24 0x00007f1dcca29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#25 0x00007f1dcca29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#26 0x00000000008b309e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8b309e)
Program terminated with signal: SIGSEGV
```

cc @alexey-bataev 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWt1yozjavhpyorILSYDhIAdOYs-XmqQn1c7Xu7UnLgGyo42MWCEySV_9liSMESYJTjK1XTOV6QCSnuf91ysIqSq2LSg998ILL7w6I7V6EPL8n5cPL2epyF_Ov9NSirzOWMopEAXYijwVXHl4Dh6UKisPzz209NCyGZgKufXQ8qeHljmBMr8Nfo88_8rz5_bf7zSvM5rrZfZp5Nsfzp929lFON6yg4EmwHHiBv_7Xtyivs8c8hcEFK4h8WTzTrFZCQmiv6JITdU1I-m21xqGds2LFltO53NY7Wqg_SiqJEvIfkpQllYtvq3XyTajFf2rCq0V6k_qLmxQuFoun799W6-gHzZSQi1W4XoXr3X2w9lDMYuCh0PfQJbCX0EMJ8GYXVmhaKPnSagX0hD9ZTqdckHyqF-AroK8BizVEqSTYUkU51eLpO0OxHypqzg0TRiD2UKKvCWfbAsBhggRG-BMcyRgO6H-CAfqjKCCMgs-wwFEs6DMUaJCix_AZZ0A8SolP2SkYRRHCKPwMSziCpS6ViBGeGR5WVFTusYGHL2EEnjUxXoCfVApWMMUIZz-pPCRiN8_M0ygA8atcCcLxu1yDEg4y6sTbkyZDsaBXQx_h5HRSLeogKfT3lNB_VVEIUeCfTmpkHWbVydkSv-5NiFAAP0Cs5R0mRi0retXEGAXoA6Ra1mHS1q0Qv65qgAL8AVYt7DDrwcBDpB-g0hIOU-ns3rP5w2XM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