[IR] fix crash in Constant::isElementWiseEqual() with FP types
authorSanjay Patel <spatel@rotateright.com>
Thu, 16 Jan 2020 21:20:48 +0000 (16:20 -0500)
committerSanjay Patel <spatel@rotateright.com>
Thu, 16 Jan 2020 21:49:16 +0000 (16:49 -0500)
commit52b44902d059e68c6b5553c1d043f768c516064a
tree22aceae492196b45701652029d7a3b3b97fa94c1
parent8b321929483ee3c4070a10c457733c1bddd10b51
[IR] fix crash in Constant::isElementWiseEqual() with FP types

We lifted this code from InstCombine for general usage in:
rL369842
...but it's not safe as-is. There are no existing users that can
trigger this bug, but I discovered it via crashing several
regression tests when trying to use it for select folding in
InstSimplify.

ICmp requires (vector) integer types, so give up on anything that's
not integer or FP (pointers and ?) then bitcast the constants
before trying the match. That matches the definition of "equal or
undef" that I was looking for. If someone wants an FP-aware version
of equality (deal with NaN, -0.0), that could be a different mode
or different function.

Differential Revision: https://reviews.llvm.org/D72784
llvm/lib/IR/Constants.cpp
llvm/unittests/IR/ConstantsTest.cpp