Three-way comparison matcher which is used in some of InstCombine's transforms
is intended to detect the following pattern:
%c1 = icmp eq %a, %b %c2 = icmp slt %a, %b %select1 = select %c2, %Less, %Greater %select2 = select %c1, %Equal, %select2
It works fine if %a and %b are some values about which we know nothing. However
if %b is a constant zero, the situation is different. If we look closer at the example:
%c1 = icmp eq %a, 0 %c2 = icmp slt %a, 0 %select1 = select %c2, %Less, %Greater %select2 = select %c1, %Equal, %select2
Then we can see that the pattern of %c2 and %select1 is actually a bit test of the
highest bit of %a. There are rules in InstCombine that detect this couple before we
go down to detection of the three-way comparison pattern which is only seen when we
process select2. These transforms may turn %c2, %select1 into something different,
and when we process %select2 we may not be able to recognize the three-way comparison
pattern.
This patch adds support of the following transform:
%c2 = icmp slt %a, 0 %select1 = select %c2, -1, %Greater
to
%shift = ashr %a, 31 %or = or %shift, %Greater
This is a part of fix for bug 37147.
Please use utils/update_test_checks.py (the file's header should say it was used), and don't adjust the ; CHECK lines afterwards manually.