[InstCombine] make icmp vector canonicalization safe for constant with undef elements
authorSanjay Patel <spatel@rotateright.com>
Tue, 29 Oct 2019 14:39:59 +0000 (10:39 -0400)
committerSanjay Patel <spatel@rotateright.com>
Tue, 29 Oct 2019 14:58:14 +0000 (10:58 -0400)
commita22282be54b309ce7ab0e6bf8595893384971646
tree9dcd54d8d8a288376787cf1c2c33b434e2f75d5d
parent98f3151a7dded8838fafcb5f46e6c8358def96b8
[InstCombine] make icmp vector canonicalization safe for constant with undef elements

This is a fix for:
https://bugs.llvm.org/show_bug.cgi?id=43730
...and as shown there, we have existing test cases that show potential miscompiles.

We could just bail out for vector constants that contain any undef elements, or we can do as shown here:
allow the transform, but replace the undefs with a safe value.

For most of the tests shown, this results in a full splat constant (no undefs) which is probably a win
for further IR analysis because we conservatively don't match undefs in most cases. Codegen can probably
recover these kinds of undef lanes via demanded elements analysis if that's profitable.

Differential Revision: https://reviews.llvm.org/D69519
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-eq-to-icmp-ule.ll
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-sle-to-icmp-sle.ll
llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-uge-to-icmp-ule.ll
llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-ule-to-icmp-ule.ll
llvm/test/Transforms/InstCombine/icmp-vec.ll
llvm/test/Transforms/InstCombine/reuse-constant-from-select-in-icmp.ll