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

    <tr>
        <th>Summary</th>
        <td>
            [SLPVectorizer] Assertion `I->use_empty() && "trying to erase instruction with users."' failed.
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          max-quazan
      </td>
    </tr>
</table>

<pre>
    Run opt -passes=slp-vectorizer -S on the following test:
```
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2"
target triple = "x86_64-unknown-linux-gnu"

define i64 @wombat() #0 gc "statepoint-example" personality i32* ()* @snork {
bb:
  br label %bb1

bb1:                                              ; preds = %bb
  br label %bb3

bb2:                                              ; No predecessors!
  br label %bb3

bb3:                                              ; preds = %bb2, %bb1
  %tmp = phi i32 [ undef, %bb2 ], [ undef, %bb1 ]
  %tmp4 = phi i32 [ undef, %bb2 ], [ undef, %bb1 ]
  %tmp5 = mul i32 %tmp, %tmp4
  %tmp6 = mul i32 %tmp5, %tmp4
  %tmp7 = mul i32 %tmp6, %tmp4
  %tmp8 = mul i32 %tmp7, %tmp4
  %tmp9 = mul i32 %tmp8, %tmp4
  %tmp10 = mul i32 %tmp9, %tmp4
  %tmp11 = mul i32 %tmp10, %tmp4
  %tmp12 = mul i32 %tmp11, %tmp4
  %tmp13 = mul i32 %tmp12, %tmp4
  %tmp14 = mul i32 %tmp13, %tmp4
  %tmp15 = mul i32 %tmp14, %tmp4
  %tmp16 = mul i32 %tmp15, %tmp4
  %tmp17 = mul i32 %tmp16, %tmp4
  %tmp18 = mul i32 %tmp17, %tmp4
  %tmp19 = mul i32 %tmp18, %tmp4
  %tmp20 = mul i32 %tmp19, %tmp4
  %tmp21 = mul i32 %tmp20, %tmp4
  %tmp22 = mul i32 %tmp21, %tmp4
  %tmp23 = mul i32 %tmp22, %tmp4
  %tmp24 = mul i32 %tmp23, %tmp4
  %tmp25 = mul i32 %tmp24, %tmp4
  %tmp26 = mul i32 %tmp25, %tmp4
  %tmp27 = mul i32 %tmp26, %tmp4
  %tmp28 = mul i32 %tmp27, %tmp4
  %tmp29 = mul i32 %tmp28, %tmp4
  %tmp30 = mul i32 %tmp29, %tmp4
  %tmp31 = mul i32 %tmp30, %tmp4
  %tmp32 = mul i32 %tmp31, %tmp4
  %tmp33 = mul i32 %tmp32, %tmp4
  %tmp34 = mul i32 %tmp33, %tmp4
  %tmp35 = mul i32 %tmp34, %tmp4
  %tmp36 = mul i32 %tmp35, %tmp4
  %tmp37 = mul i32 %tmp36, %tmp4
  %tmp38 = mul i32 %tmp37, %tmp4
  %tmp39 = mul i32 %tmp38, %tmp4
  %tmp40 = mul i32 %tmp39, %tmp4
  %tmp41 = mul i32 %tmp40, %tmp4
  %tmp42 = mul i32 %tmp41, %tmp4
  %tmp43 = mul i32 %tmp42, %tmp4
  %tmp44 = mul i32 %tmp43, %tmp4
  %tmp45 = mul i32 %tmp44, %tmp4
  %tmp46 = mul i32 %tmp45, %tmp4
  %tmp47 = mul i32 %tmp46, %tmp4
  %tmp48 = mul i32 %tmp47, %tmp4
  %tmp49 = mul i32 %tmp48, %tmp4
  %tmp50 = mul i32 %tmp49, %tmp4
  %tmp51 = mul i32 %tmp50, %tmp4
  %tmp52 = mul i32 %tmp51, %tmp4
  %tmp53 = mul i32 %tmp52, %tmp4
  %tmp54 = mul i32 %tmp53, %tmp4
  %tmp55 = mul i32 %tmp54, %tmp4
  %tmp56 = mul i32 %tmp55, %tmp4
  %tmp57 = mul i32 %tmp56, %tmp4
  %tmp58 = mul i32 %tmp57, %tmp4
  %tmp59 = mul i32 %tmp58, %tmp4
  %tmp60 = mul i32 %tmp59, %tmp4
  %tmp61 = mul i32 %tmp60, %tmp4
  %tmp62 = mul i32 %tmp61, %tmp4
  %tmp63 = mul i32 %tmp62, %tmp4
  %tmp64 = add i32 undef, %tmp63
  %tmp65 = sext i32 %tmp64 to i64
  ret i64 %tmp65
}

declare i32* @snork()

attributes #0 = { "target-features"="+sse4.1" }

```

Failure is
```
opt: /localhome/mkazantsev/work/llvm/llvm/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:3235: llvm::slpvectorizer::BoUpSLP::~BoUpSLP(): Assertion `I->use_empty() && "trying to erase instruction with users."' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /localhome/mkazantsev/work/llvm/build/RA/bin/opt -passes=slp-vectorizer -S ./renamed.ll
 #0 0x00000000021d06ec llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /localhome/mkazantsev/work/llvm/llvm/llvm/lib/Support/Unix/Signals.inc:569:0
 #1 0x00000000021ce7d4 llvm::sys::RunSignalHandlers() /localhome/mkazantsev/work/llvm/llvm/llvm/lib/Support/Signals.cpp:103:0
 #2 0x00000000021cee53 SignalHandler(int) /localhome/mkazantsev/work/llvm/llvm/llvm/lib/Support/Unix/Signals.inc:397:0
 #3 0x00007f9a7986e630 __restore_rt sigaction.c:0:0
 #4 0x00007f9a783ca387 raise (/lib64/libc.so.6+0x36387)
 #5 0x00007f9a783cba78 abort (/lib64/libc.so.6+0x37a78)
 #6 0x00007f9a783c31a6 __assert_fail_base (/lib64/libc.so.6+0x2f1a6)
 #7 0x00007f9a783c3252 (/lib64/libc.so.6+0x2f252)
 #8 0x00000000023fa8fc (/localhome/mkazantsev/work/llvm/build/RA/bin/opt+0x23fa8fc)
 #9 0x00000000024392c1 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.2569) /localhome/mkazantsev/work/llvm/llvm/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:8814:0
#10 0x0000000002439d1b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /localhome/mkazantsev/work/llvm/llvm/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:8768:0
#11 0x000000000248602d llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /localhome/mkazantsev/work/llvm/llvm/llvm/include/llvm/IR/PassManagerInternal.h:89:0
#12 0x00000000019b7861 llvm::SmallPtrSet<void*, 2u>::operator=(llvm::SmallPtrSet<void*, 2u>&&) /localhome/mkazantsev/work/llvm/llvm/llvm/include/llvm/ADT/SmallPtrSet.h:489:0
#13 0x00000000019b7861 llvm::PreservedAnalyses::operator=(llvm::PreservedAnalyses&&) /localhome/mkazantsev/work/llvm/llvm/llvm/include/llvm/IR/PassManager.h:152:0
#14 0x00000000019b7861 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /localhome/mkazantsev/work/llvm/llvm/llvm/include/llvm/IR/PassManager.h:522:0
#15 0x00000000024828bd llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /localhome/mkazantsev/work/llvm/llvm/llvm/include/llvm/IR/PassManagerInternal.h:89:0
#16 0x00000000019b7073 llvm::SmallPtrSet<void*, 2u>::operator=(llvm::SmallPtrSet<void*, 2u>&&) /localhome/mkazantsev/work/llvm/llvm/llvm/include/llvm/ADT/SmallPtrSet.h:489:0
#17 0x00000000019b7073 llvm::PreservedAnalyses::operator=(llvm::PreservedAnalyses&&) /localhome/mkazantsev/work/llvm/llvm/llvm/include/llvm/IR/PassManager.h:152:0
#18 0x00000000019b7073 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /localhome/mkazantsev/work/llvm/llvm/llvm/lib/IR/PassManager.cpp:127:0
#19 0x00000000024877ad llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /localhome/mkazantsev/work/llvm/llvm/llvm/include/llvm/IR/PassManagerInternal.h:89:0
#20 0x00000000019b5737 llvm::SmallPtrSet<void*, 2u>::operator=(llvm::SmallPtrSet<void*, 2u>&&) /localhome/mkazantsev/work/llvm/llvm/llvm/include/llvm/ADT/SmallPtrSet.h:489:0
#21 0x00000000019b5737 llvm::PreservedAnalyses::operator=(llvm::PreservedAnalyses&&) /localhome/mkazantsev/work/llvm/llvm/llvm/include/llvm/IR/PassManager.h:152:0
#22 0x00000000019b5737 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /localhome/mkazantsev/work/llvm/llvm/llvm/include/llvm/IR/PassManager.h:522:0
#23 0x00000000007f9910 llvm::SmallPtrSetImplBase::~SmallPtrSetImplBase() /localhome/mkazantsev/work/llvm/llvm/llvm/include/llvm/ADT/SmallPtrSet.h:83:0
#24 0x00000000007f9910 llvm::SmallPtrSetImpl<llvm::AnalysisKey*>::~SmallPtrSetImpl() /localhome/mkazantsev/work/llvm/llvm/llvm/include/llvm/ADT/SmallPtrSet.h:344:0
#25 0x00000000007f9910 llvm::SmallPtrSet<llvm::AnalysisKey*, 2u>::~SmallPtrSet() /localhome/mkazantsev/work/llvm/llvm/llvm/include/llvm/ADT/SmallPtrSet.h:450:0
#26 0x00000000007f9910 llvm::PreservedAnalyses::~PreservedAnalyses() /localhome/mkazantsev/work/llvm/llvm/llvm/include/llvm/IR/PassManager.h:152:0
#27 0x00000000007f9910 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::StringRef>, llvm::ArrayRef<llvm::PassPlugin>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool) /localhome/mkazantsev/work/llvm/llvm/llvm/tools/opt/NewPMDriver.cpp:496:0
#28 0x000000000076e0c8 llvm::SmallVectorTemplateCommon<llvm::StringRef, void>::end() /localhome/mkazantsev/work/llvm/llvm/llvm/include/llvm/ADT/SmallVector.h:251:0
#29 0x000000000076e0c8 llvm::SmallVector<llvm::StringRef, 4u>::~SmallVector() /localhome/mkazantsev/work/llvm/llvm/llvm/include/llvm/ADT/SmallVector.h:1189:0
#30 0x000000000076e0c8 main /localhome/mkazantsev/work/llvm/llvm/llvm/tools/opt/opt.cpp:800:0
#31 0x00007f9a783b6555 __libc_start_main (/lib64/libc.so.6+0x22555)
#32 0x00000000007edb20 _start (/localhome/mkazantsev/work/llvm/build/RA/bin/opt+0x7edb20)
Aborted (core dumped)

```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztmllz2zgSgH-N_MKSigTAQw9-kC2rNjXJjMv2zKsKJCEZG14Lgj7y67cBSrJAA7IcK5md1KYcmkej0d0f0ESDTuv8-fymq7y6kd64oW3L2hGet0UzfmCZrAX_xoQ3vvXqypP3zFvVRVE_8mrtSdbKEZ6N_PnIn40if_OjLyUVaya9nEpa0Oe6kx7o9EYIsXEJbdi4QbEPJxjpg7oMzEt1FhF9GPPtySpRjQKUjKtEnUTbNvDsVt_m6ja03z5INv9BqX6GwAbDRCl4U7CteU9JtARdXfW1qh-rccGr7mm8rrpdq_6YsxWvmAd2eSPiP9ZlSuUIJSM0BSXY99aZUtZKKllT80qO2RMtoRu46TVMtHVFCy6fPQ42opnXN9VnxG-rWn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