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

    <tr>
        <th>Summary</th>
        <td>
            [SLPVectorizer] opt crashed and triggered assertion "Expected only 1 or 2 vectors shuffle."
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          XChy
      </td>
    </tr>
</table>

<pre>
    Reproducible with godbolt: https://godbolt.org/z/9eTfKGbb5

```llvm
; opt --passes=slp-vectorizer -S
define i32 @dgemm_small_kernel_tn() {
  br label %1

1:                                                ; preds = %1, %0
  %.i489 = phi double [ 0.000000e+00, %0 ], [ 0.000000e+00, %1 ]
  %.i1102 = phi double [ 0.000000e+00, %0 ], [ %.i1110, %1 ]
 %.i4105 = phi double [ 0.000000e+00, %0 ], [ %.i4113, %1 ]
  %.i14525 = call double @llvm.fma.f64(double 0.000000e+00, double 0.000000e+00, double %.i1102)
  %.i24526 = call double @llvm.fma.f64(double 0.000000e+00, double 0.000000e+00, double %.i489)
  %.i44529 = call double @llvm.fma.f64(double 0.000000e+00, double 0.000000e+00, double %.i4105)
 %.upto16034 = insertelement <8 x double> zeroinitializer, double %.i14525, i64 1
  %.upto26035 = insertelement <8 x double> %.upto16034, double %.i24526, i64 2
  %.upto36036 = insertelement <8 x double> %.upto26035, double %.i14525, i64 3
  %.upto46037 = insertelement <8 x double> %.upto36036, double %.i44529, i64 0
  %.i1110 = extractelement <8 x double> %.upto46037, i64 0
  %.i4113 = extractelement <8 x double> zeroinitializer, i64 0
  br label %1
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fma.f64(double, double, double) #0

; uselistorder directives
uselistorder ptr @llvm.fma.f64, { 2, 1, 0 }

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
```

Output:
```
opt: /home/xchy/Projects/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:11732: ResTy llvm::slpvectorizer::BoUpSLP::processBuildVector(const llvm::slpvectorizer::BoUpSLP::TreeEntry*, Args& ...) [with BVTy = llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder; ResTy = llvm::Value*; Args = {llvm::IRBuilder<llvm::TargetFolder, llvm::IRBuilderDefaultInserter>, llvm::slpvectorizer::BoUpSLP}]: Assertion `(!Vec2 || Vec2 == EI->getVectorOperand()) && "Expected only 1 or 2 vectors shuffle."' 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 --passes=slp-vectorizer -S crash.ll
 #0 0x0000622f62e29c00 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/local/bin/opt+0x3ea1c00)
 #1 0x0000622f62e26c3f llvm::sys::RunSignalHandlers() (/usr/local/bin/opt+0x3e9ec3f)
 #2 0x0000622f62e26d95 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007bc29b242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007bc29b2969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007bc29b2969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007bc29b2969fc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007bc29b242476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007bc29b2287f3 abort ./stdlib/abort.c:81:7
 #9 0x00007bc29b22871b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007bc29b239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x0000622f65447f08 (/usr/local/bin/opt+0x64bff08)
#12 0x0000622f65448359 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/usr/local/bin/opt+0x64c0359)
#13 0x0000622f6544cef0 llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/usr/local/bin/opt+0x64c4ef0)
#14 0x0000622f65448ad0 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/usr/local/bin/opt+0x64c0ad0)
#15 0x0000622f65450ab5 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*) (/usr/local/bin/opt+0x64c8ab5)
#16 0x0000622f65453f29 llvm::slpvectorizer::BoUpSLP::vectorizeTree() (/usr/local/bin/opt+0x64cbf29)
#17 0x0000622f65460411 llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/usr/local/bin/opt+0x64d8411)
#18 0x0000622f6546275e llvm::SLPVectorizerPass::vectorizeInsertElementInst(llvm::InsertElementInst*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/usr/local/bin/opt+0x64da75e)
#19 0x0000622f65463588 llvm::SLPVectorizerPass::vectorizeInserts(llvm::SmallSetVector<llvm::Instruction*, 8u>&, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/usr/local/bin/opt+0x64db588)
#20 0x0000622f65464366 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&)::'lambda2'(bool)::operator()(bool) const SLPVectorizer.cpp:0:0
#21 0x0000622f654669ee llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/usr/local/bin/opt+0x64de9ee)
#22 0x0000622f6546a190 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
#23 0x0000622f6546ab8b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/usr/local/bin/opt+0x64e2b8b)
#24 0x0000622f64de8b96 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) PassBuilder.cpp:0:0
#25 0x0000622f6448c52a llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) AMDGPUTargetMachine.cpp:0:0
#26 0x0000622f630e227b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/usr/local/bin/opt+0x415a27b)
#27 0x0000622f6446efa6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) AMDGPUTargetMachine.cpp:0:0
#28 0x0000622f630e00b1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/usr/local/bin/opt+0x41580b1)
#29 0x0000622f66836015 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) (/usr/local/bin/opt+0x78ae015)
#30 0x0000622f62e01a2d optMain (/usr/local/bin/opt+0x3e79a2d)
#31 0x00007bc29b229d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#32 0x00007bc29b229e40 call_init ./csu/../csu/libc-start.c:128:20
#33 0x00007bc29b229e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#34 0x0000622f62df28a5 _start (/usr/local/bin/opt+0x3e6a8a5)
zsh: IOT instruction (core dumped) opt --passes=slp-vectorizer -S crash.ll
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWttz26qf_2vICxMPQveHPNhxfDZzmmkmyensmwdJyGaLQAOojfvX7wC-SVYSO6fd_WXSRhbw-d4vgInWbCUovQHxDMTzK9KZtVQ3_3273lwVstrcPNFWyaorWcEp_MnMGq5kVUhuQDiFa2NaDcIpwAuAF9uBiVQrgBe_AF7k9KX--6-iiAGaAzTd_p8g_8v5j2b7KpxB2Rp4fd0SrakG4Vzz9voHLY1U7BdV8PrZz6xozQSFLMQQRKha0aZZ6oZwvvxOlaB8aQTAGcA5BOnML4GwUJCTgnIIcBwcsxJYIS78sby2ilYagnDuEfGt_Yt25ACOJyzKcjehXTNYyc5qD8QziCbI_VCAZwjtVkIQz93zWzMCN-MYPwgQ_hyB7fJgDNuzHqD4X0BHQRC-zXYUYw9eEs736JFzhkndkEmdRABn24FTkh8N7JUDcN6jjKMYJ3-ccpTlQ8JRFOP8zxMOUHygbF91rZFBgsLI0WZCU2Uopw0VBoLwNoOvWwAQ3sFfVEkmmGGE23g7Uag1m33JkggGx-JZKjhBYXwOlR5bQxrOQDsaeEgjTFCYXELDMfWuHOGQRpSgML2EhmPqxBLW3jsaaBC0AXL49NUoUn5MwHE0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