davemgreen wrote: Could it use SmallSetVector to store the Dead instructions? It should rule out any duplicated whilst keeping them in order, so that they are removed in the correct order. https://github.com/llvm/llvm-project/pull/122643