[InstCombine] try harder to form select from logic ops (2nd try)
authorSanjay Patel <spatel@rotateright.com>
Wed, 24 Oct 2018 15:17:56 +0000 (15:17 +0000)
committerSanjay Patel <spatel@rotateright.com>
Wed, 24 Oct 2018 15:17:56 +0000 (15:17 +0000)
commit3b206305fd6afec0ec02749b8ebe7b5c19c7a0a1
tree5eaae7b8fba989b979e94f064ca7bf117dc6c657
parentb7e43df3c235754c34c7cd08c9dd1aa740807e91
[InstCombine] try harder to form select from logic ops (2nd try)

The original patch was committed here:
rL344609
...and reverted:
rL344612
...because it did not properly check/test data types before calling
ComputeNumSignBits().

The tests that caused bot failures for the previous commit are
over-reaching front-end tests that run the entire -O optimizer
pipeline:
    Clang :: CodeGen/builtins-systemz-zvector.c
    Clang :: CodeGen/builtins-systemz-zvector2.c

I've added a negative test here to ensure coverage for that case.
The new early exit check also tests the type of the 'B' parameter,
so we don't waste time on matching if either value is unsuitable.

Original commit message:

This is part of solving PR37549:
https://bugs.llvm.org/show_bug.cgi?id=37549

The patterns shown here are a special case of something
that we already convert to select. Using ComputeNumSignBits()
catches that case (but not the more complicated motivating
patterns yet).

The backend has hooks/logic to convert back to logic ops
if that's better for the target.

llvm-svn: 345149
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
llvm/test/Transforms/InstCombine/logical-select.ll
llvm/test/Transforms/InstCombine/vec_sext.ll