[DSE] Don't remove nounwind invokes
authorHeejin Ahn <aheejin@gmail.com>
Mon, 20 Jun 2022 05:48:48 +0000 (22:48 -0700)
committerHeejin Ahn <aheejin@gmail.com>
Tue, 21 Jun 2022 18:54:09 +0000 (11:54 -0700)
commit27e4afcea71818ef2ceb0be109321b9595a8fba2
tree75fb2b397c715509a02a24449d1c0a5363b29396
parent7b7166f1a20fe64a9c04a30f6e9335ef0a556d70
[DSE] Don't remove nounwind invokes

For non-mem-intrinsic and non-lifetime `CallBase`s, the current
`isRemovable` function only checks if the `CallBase` 1. has no uses 2.
will return 3. does not throw:
https://github.com/llvm/llvm-project/blob/80fb7823367c1d105fcbc8f21b69205a0d68c859/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp#L1017

But we should also exclude invokes even in case they don't throw,
because they are terminators and thus cannot be removed. While it
doesn't seem to make much sense for `invoke`s to have an `nounwind`
target, this kind of code can be generated and is also valid bitcode.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D128224
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
llvm/test/Transforms/DeadStoreElimination/nounwind-invoke.ll [new file with mode: 0644]