[InstCombine] foldICmpWithLowBitMaskedVal(): don't miscompile -1 vector elts
authorRoman Lebedev <lebedev.ri@gmail.com>
Thu, 6 Dec 2018 08:14:24 +0000 (08:14 +0000)
committerRoman Lebedev <lebedev.ri@gmail.com>
Thu, 6 Dec 2018 08:14:24 +0000 (08:14 +0000)
commit98cb1216a64ed3f41cfd115737837defc5d5778f
tree175dbc5dab2dffd9edfe533db6f0f2de1c52d119
parentd9941fa270466d4b9c907c368739ac43328861b7
[InstCombine] foldICmpWithLowBitMaskedVal(): don't miscompile -1 vector elts

I was finally able to quantify what i thought was missing in the fix,
it was vector constants. If we have a scalar (and %x, -1),
it will be instsimplified before we reach this code,
but if it is a vector, we may still have a -1 element.

Thus, we want to avoid the fold if *at least one* element is -1.
Or in other words, ignoring the undef elements, no sign bits
should be set. Thus, m_NonNegative().

A follow-up for rL348181
https://bugs.llvm.org/show_bug.cgi?id=39861

llvm-svn: 348462
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-sge-to-icmp-sle.ll
llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-slt-to-icmp-sgt.ll