diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp index 56a08b8438718..c88ed95de2946 100644 --- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp +++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp @@ -173,15 +173,16 @@ class VectorCombine { // further folds that were hindered by OneUse limits. SmallPtrSet Visited; for (Value *Op : Ops) { - if (Visited.insert(Op).second) { + if (!Visited.contains(Op)) { if (auto *OpI = dyn_cast(Op)) { if (RecursivelyDeleteTriviallyDeadInstructions( - OpI, nullptr, nullptr, [this](Value *V) { + OpI, nullptr, nullptr, [&](Value *V) { if (auto *I = dyn_cast(V)) { LLVM_DEBUG(dbgs() << "VC: Erased: " << *I << '\n'); Worklist.remove(I); if (I == NextInst) NextInst = NextInst->getNextNode(); + Visited.insert(I); } })) continue; diff --git a/llvm/test/Transforms/VectorCombine/X86/pr155543.ll b/llvm/test/Transforms/VectorCombine/X86/pr155543.ll new file mode 100644 index 0000000000000..b161c0aaf031c --- /dev/null +++ b/llvm/test/Transforms/VectorCombine/X86/pr155543.ll @@ -0,0 +1,15 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 +; RUN: opt < %s -passes=vector-combine -S -mtriple=x86_64-- | FileCheck %s + +; Make sure we don't double delete a dead instruction. + +define void @pr155543() { +; CHECK-LABEL: define void @pr155543() { +; CHECK-NEXT: ret void +; + %shuffle1 = shufflevector <4 x double> poison, <4 x double> poison, <8 x i32> + %shuffle2 = shufflevector <8 x double> poison, <8 x double> %shuffle1, <8 x i32> + %fadd = fadd <8 x double> %shuffle1, zeroinitializer + %dead = shufflevector <8 x double> %fadd, <8 x double> %shuffle2, <8 x i32> + ret void +}