<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Ping...<br><div><div>On Aug 7, 2014, at 12:37 AM, Yi Jiang <<a href="mailto:yjiang@apple.com">yjiang@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">With the help of Nuno and the Alive tool, I figured out the new condition.  <span style="font-size: 11px;">The original condition actually refers to the following two ranges:</span><div><span style="font-size: 11px;">(icmp ult/ule (A + C1), C3) | (icmp ult/ule (A + C2), C3)</span><span style="font-size: 11px;"> ==</span><span style="font-size: 11px;"> </span><span style="font-size: 11px;"> [MAX_UINT-C1+1, MAX_UINT-C1+1+C3] and [MAX_UINT-C2+1, MAX_UINT-C2+1+C3]</span><div style="margin: 0px; font-size: 11px;"> We can fold these two range sif:</div><div style="margin: 0px; font-size: 11px;"> 1) C1 and C2 is unsigned greater than C3</div><div style="margin: 0px; font-size: 11px;"> 2) The two ranges are separated.  abs(LowRange1-LowRange2) > C3</div><div style="margin: 0px; font-size: 11px;"> 3) C1 ^ C2 is one-bit mask.</div><div style="margin: 0px; font-size: 11px;"> 4) LowRange1 ^ LowRange2 and HighRange1 ^ HighRange2 are one-bit mask.</div><div><br></div><div>Here is the new patch:</div><div></div></div></div><span><combinecmpV4.patch></span><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div></div><div><br><div><div>On Jul 30, 2014, at 2:24 PM, Nuno Lopes <<a href="mailto:nuno.lopes@ist.utl.pt">nuno.lopes@ist.utl.pt</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi Yi,<br><br>ALIVe still complains, I'm afraid:<br><br>Precondition: isPowerOf2(C1 ^ C2) && ugt(C1, C3) && ugt(C2, C3)<br>%x = add %A, C1<br>%i = icmp ult %x, C3<br>%y = add %A, C2<br>%j = icmp ult %y, C3<br>%r = or %i, %j<br> =><br>%and = and %A, ~(C1 ^ C2)<br>%lhs = add %and, umax(C1, C2)<br>%r = icmp ult %lhs, C3<br><br>Done: 1<br>ERROR: Mismatch in values of i1 %r<br><br>Example:<br>%A i2 = 2 (0x2)<br>C1 i2 = 3 (0x3)<br>%x i2 = 1 (0x1)<br>C3 i2 = 1 (0x1)<br>%i i1 = 0 (0x0)<br>C2 i2 = 2 (0x2)<br>%y i2 = 0 (0x0)<br>%j i1 = 1 (0x1)<br>%and i2 = 2 (0x2)<br>%lhs i2 = 1 (0x1)<br>Source value: 1 (0x1)<br>Target value: 0 (0x0)<br><br><br>Nuno<br><br>----- Original Message ----- From: "Yi Jiang" <<a href="mailto:yjiang@apple.com">yjiang@apple.com</a>><br>To: "Nuno Lopes" <<a href="mailto:nuno.lopes@ist.utl.pt">nuno.lopes@ist.utl.pt</a>><br>Cc: "LLVM Commits" <<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a>><br>Sent: Wednesday, July 30, 2014 8:28 PM<br>Subject: Re: [Patch]New InstCombine pattern for Icmp<br><br><br>Hi Nuno,<br><br>Thank you for pointing out this! One condition is missing: C1 and C2 should be unsigned greater than C3.<br>Here is the new patch.<br><br>-Yi<br><br>On Jul 29, 2014, at 11:34 AM, Nuno Lopes <<a href="mailto:nuno.lopes@ist.utl.pt">nuno.lopes@ist.utl.pt</a>> wrote:<br><br><blockquote type="cite">Hi,<br><br>I sent you an email the other day, but it was rejected by Apple's email server.  Tyring now through another email account.<br>Please take a look here: <a href="http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140721/227575.html">http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140721/227575.html</a><br><br>Nuno<br><br>----- Original Message -----<br><br>Ping...<br>On Jul 25, 2014, at 4:11 PM, Yi Jiang <<a href="mailto:yjiang@apple.com">yjiang@apple.com</a>> wrote:<br><br><blockquote type="cite">Hi Ben,<br><br>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 comments.<br><combinecmpV2.patch><br>-Yi<br>On Jul 25, 2014, at 2:12 AM, Benjamin Kramer <<a href="mailto:benny.kra@gmail.com">benny.kra@gmail.com</a>> wrote:<br><br><blockquote type="cite">On Fri, Jul 25, 2014 at 1:24 AM, Yi Jiang <<a href="mailto:yjiang@apple.com">yjiang@apple.com</a>> wrote:<br><blockquote type="cite">Hi,<br><br>his patch is trying to fold (icmp ult/ule (A + C1), C3) | (icmp ult/ule (A +<br>C2), C3)  to (icmp ult/ule ((A & ~(C1 ^ C2)) + max(C1, C2)), C3)  .<br>This transformation is legal if C1 ^ C2 is one-bit mask, in other word, C1<br>is only one bit different from C2. In this case, we can "mask" that bit and<br>do just one comparison.<br>A typical example is:<br>isALPHA(c)    ((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z')<br><br>Now llvm will optimize it to ((c + 191) <=25) || ((c + 159) <=25)<br><br>With this patch, we can optimize it further to:<br>(c & 223) + 191 <= 25<br><br>The binary format of the constants are:<br>191   10111111<br>159   10011111<br>223   11011111<br><br>Here is some experiment result on arm64:<br>The patch shows no regression and improve spec2000 perlbmk 3.8% in<br>test-suite under -O3.<br>We also test the spec2006 400.perlbench with ref size input, it will improve<br>1% under -O3 and 1.2% under -O3+lto+pgo.<br></blockquote><br>Wow, very nice.<br><br><blockquote type="cite">Any comments are appreciated.<br></blockquote><br>The patch could be significantly simplified with the PatternMatch<br>tool. Something like match(LHS, m_Add(m_OneUse(m_Value(A),<br>m_ConstantInt(LAddCst)... could replace your if chain.<br><br>- Ben <br></blockquote></blockquote></blockquote><br></blockquote></div><br></div></div></blockquote></div><br></body></html>