[InstCombine] Don't miscompile select to poison
authorDavid Majnemer <david.majnemer@gmail.com>
Sat, 6 Jun 2015 02:30:43 +0000 (02:30 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sat, 6 Jun 2015 02:30:43 +0000 (02:30 +0000)
commitb21b529990e868311911c40c9261820c8502edbf
tree019c131cded3ce78945ea56f41d7510a51c739d5
parentdcb11d3206e01dec45b8b21f82f7b07c6cc9dd7a
[InstCombine] Don't miscompile select to poison

If we have (select a, b, c), it is sometimes valid to simplify this to a
single select operand.  However, doing so is only valid if the
computation doesn't inject poison into the computation.

It might be helpful to consider the following example:
  (select (icmp ne %i, INT_MAX), (add nsw %i, 1), INT_MIN)

The select is equivalent to (add %i, 1) but not (add nsw %i, 1).

Self hosting on x86_64 revealed that this occurs very, very rarely so
bailing out is hopefully pretty reasonable.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239215 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineSelect.cpp
test/Transforms/InstCombine/select.ll