[Attributor] Fold terminators before changing instructions to unreachable
authorStefanos Baziotis <sdi1600105@di.uoa.gr>
Sat, 7 Mar 2020 10:38:44 +0000 (12:38 +0200)
committerStefanos Baziotis <sdi1600105@di.uoa.gr>
Sat, 7 Mar 2020 10:38:44 +0000 (12:38 +0200)
commit01c48d7d11e657fba0d031fa8b478ae9fc730a98
treee1ea553b957554dd5c07375ffd1f51b2b819a4d6
parent320f0b003682a7bf5f0a89827763dcb1443c96e9
[Attributor] Fold terminators before changing instructions to unreachable

It is possible that an instruction to be changed to unreachable is
in the same block with a terminator that can be constant-folded.
In this case, as of now, the instruction will be changed to
unreachable before the terminator is folded. But, then the
whole BB becomes invalidated and so when we go ahead to fold
the terminator, we trap.

Change the order of these two.

Differential Revision: https://reviews.llvm.org/D75780
llvm/lib/Transforms/IPO/Attributor.cpp
llvm/test/Transforms/Attributor/undefined_behavior.ll