[Patch]New InstCombine pattern for Icmp

Yi Jiang yjiang at apple.com
Thu Jul 24 16:24:57 PDT 2014


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, C1 is only one bit different from C2. In this case, we can “mask” that bit and 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 improve 1% under -O3 and 1.2% under -O3+lto+pgo.

Any comments are appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140724/12f38d50/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: combinecmp.patch
Type: application/octet-stream
Size: 3381 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140724/12f38d50/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140724/12f38d50/attachment-0001.html>

More information about the llvm-commits mailing list