[Patch]New InstCombine pattern for Icmp
nunoplopes at sapo.pt
Sun Jul 27 09:04:12 PDT 2014
I belive this patch is incorrect for some inputs.
This is what ALIVe has to say:
$ alive.py < file.opt
Precondition: isPowerOf2(C1 ^ C2)
%x = add %A, C1
%i = icmp ult %x, C3
%y = add %A, C2
%j = icmp ult %y, C3
%r = or %i, %j
%and = and %A, ~(C1 ^ C2)
%lhs = add %and, umax(C1, C2)
%r = icmp ult %lhs, C3
ERROR: Mismatch in values of i1 %r
%A i1 = 0 (0x0)
C1 i1 = 0 (0x0)
%x i1 = 0 (0x0)
C3 i1 = 1 (0x1)
%i i1 = 1 (0x1)
C2 i1 = 1 (0x1)
%y i1 = 1 (0x1)
%j i1 = 0 (0x0)
%and i1 = 0 (0x0)
%lhs i1 = 1 (0x1)
Source value: 1 (0x1)
Target value: 0 (0x0)
Please let me know if you need more information/help.
(I didn't try the proof for ule, just ult)
----- Original Message -----
> Hi Ben,
> Thank you for your comments! Here is a new version. In this version, I
> still kept some “if” thinking that some operand has been already extracted
> so I would like to use it directly. Please let me know if any other
> On Jul 25, 2014, at 2:12 AM, Benjamin Kramer <benny.kra at gmail.com> wrote:
>> On Fri, Jul 25, 2014 at 1:24 AM, Yi Jiang <yjiang at apple.com> wrote:
>>> his patch is trying to fold (icmp ult/ule (A + C1), C3) | (icmp ult/ule
>>> (A +
>>> C2), C3) to (icmp ult/ule ((A & ~(C1 ^ C2)) + max(C1, C2)), C3) .
>>> This transformation is legal if C1 ^ C2 is one-bit mask, in other word,
>>> is only one bit different from C2. In this case, we can “mask” that bit
>>> do just one comparison.
>>> A typical example is:
>>> isALPHA(c) ((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z’)
>>> Now llvm will optimize it to ((c + 191) <=25) || ((c + 159) <=25)
>>> With this patch, we can optimize it further to:
>>> (c & 223) + 191 <= 25
>>> The binary format of the constants are:
>>> 191 10111111
>>> 159 10011111
>>> 223 11011111
>>> Here is some experiment result on arm64:
>>> The patch shows no regression and improve spec2000 perlbmk 3.8% in
>>> test-suite under -O3.
>>> We also test the spec2006 400.perlbench with ref size input, it will
>>> 1% under -O3 and 1.2% under -O3+lto+pgo.
>> Wow, very nice.
>>> Any comments are appreciated.
>> The patch could be significantly simplified with the PatternMatch
>> tool. Something like match(LHS, m_Add(m_OneUse(m_Value(A),
>> m_ConstantInt(LAddCst)... could replace your if chain.
>> - Ben
More information about the llvm-commits