[PATCH] D87149: [InstCombine] erase instructions leading up to unreachable

Johannes Doerfert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 9 09:42:35 PDT 2020


jdoerfert added a comment.

In D87149#2263708 <https://reviews.llvm.org/D87149#2263708>, @nikic wrote:

> @lebedev.ri I don't think the printf() case is any different. Keep in mind that undefined behavior acts retroactively, so if we know that unreachable will be executed later, we are free to optimize away side-effects before it as well. (If printf is not considered willreturn, then we cannot optimize it away, and won't.)

I agree. Without analyzing the format of `printf` we should not be able to make it `willreturn` in the first place. That said, there is no good way to ensure an effect is kept unless you ensure the effect does not inevitably lead to UB.
This patch doesn't change that in principle, just makes it more obvious. Take: https://godbolt.org/z/4qMb5G which shows how we hoist a division if we assume `printf` is `willreturn` and `nounwind`, "eliminating" one `printf` call in case `d = 0` (which leads to UB).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87149/new/

https://reviews.llvm.org/D87149



More information about the llvm-commits mailing list