[PATCH] D45854: [InstCombine] Support BitTests in ThreeWayComparison. Trivial case
Max Kazantsev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 19 18:30:05 PDT 2018
mkazantsev created this revision.
mkazantsev added reviewers: craig.topper, lebedev.ri, spatel, reames.
mkazantsev edited the summary of this revision.
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, %More
%select2 = select %c1, 0, %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, %More
%select2 = select %c1, 0, %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, %More
to
%shift = ashr %a, 31
%or = or ashr, %More
This is a part of fix for bug 37147.
https://reviews.llvm.org/D45854
Files:
lib/Transforms/InstCombine/InstCombineCompares.cpp
test/Transforms/InstCombine/three-way-comparison.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45854.143208.patch
Type: text/x-patch
Size: 8993 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180420/dc9072fe/attachment.bin>
More information about the llvm-commits
mailing list