[InstCombine] Inefficient pattern for high-bits checking 2 (PR38708)
authorRoman Lebedev <lebedev.ri@gmail.com>
Thu, 13 Sep 2018 20:33:12 +0000 (20:33 +0000)
committerRoman Lebedev <lebedev.ri@gmail.com>
Thu, 13 Sep 2018 20:33:12 +0000 (20:33 +0000)
commit6dc87004fab4b34076e6f0f8505316e40b9ea2fb
tree006a78021884c24eae7db013688b12e3786d5d46
parentd565b0f017e216aa5693484249628d03e98e8d27
[InstCombine] Inefficient pattern for high-bits checking 2 (PR38708)

Summary:
It is sometimes important to check that some newly-computed value
is non-negative and only n bits wide (where n is a variable.)
There are many ways to check that:
https://godbolt.org/z/o4RB8D
The last variant seems best?
(I'm sure there are some other variations i haven't thought of..)

More complicated, canonical pattern:
https://rise4fun.com/Alive/uhA

We do need to have two `switch()`'es like this,
to not mismatch the swappable predicates.

https://bugs.llvm.org/show_bug.cgi?id=38708

Reviewers: spatel, craig.topper, RKSimon

Reviewed By: spatel

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D52001

llvm-svn: 342173
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/icmp-uge-of-not-of-shl-allones-by-bits-and-val-to-icmp-eq-of-lshr-val-by-bits-and-0.ll
llvm/test/Transforms/InstCombine/icmp-ult-of-not-of-shl-allones-by-bits-and-val-to-icmp-ne-of-lshr-val-by-bits-and-0.ll