<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 13, 2017 at 2:12 PM, Sanjay Patel <span dir="ltr"><<a href="mailto:spatel@rotateright.com" target="_blank">spatel@rotateright.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><div><div>We have several optimizations in InstCombine for bitwise logic ops (and/or/xor) that fail to handle compare patterns with the equivalent bitwise logic. Example:<br><br>define i8 @or_and_not(i8 %a, i8 %b) {<br>  %nota = xor i8 %a, -1<br>  %and = and i8 %nota, %b<br>  %res = or i8 %and, %a<br>  ret i8 %res<br>}<br><br>define i1 @or_and_cmp_not(i32 %a, i32 %b, i1 %c) {<br>  %cmp = icmp sgt i32 %a, %b<br>  %cmp_inv = icmp sle i32 %a, %b ; this is 'not' of %cmp<br>  %and = and i1 %c, %cmp_inv<br>  %res = or i1 %cmp, %and<br>  ret i1 %res<br>}<br><br>$ ./opt -instcombine hidden_not.ll -S<br><br>define i8 @or_and_not(i8 %a, i8 %b) {<br>  %res = or i8 %b, %a<br>  ret i8 %res<br>}<br><br>define i1 @or_and_cmp_not(i32 %a, i32 %b, i1 %c) {<br>  %cmp = icmp sgt i32 %a, %b<br>  %cmp_inv = icmp sle i32 %a, %b<br>  %and = and i1 %cmp_inv, %c<br>  %res = or i1 %cmp, %and<br>  ret i1 %res<br>}<br><br></div></div></div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><div><div>------------------------------<wbr>------------------------------<wbr>---------<br></div><br>Would adding to the existing InstCombine logic folds to handle this kind of pattern be a welcome enhancement? I don't know if it's possible to make the matchers handle this case without adding a new matcher. Eg:<br><br></div></div></div></div></blockquote><div><br></div><div>I would rather see this added to instsimplify than instcombine.</div><div>If you do that, GVN/et all will get this already.</div><div><br></div><div>This probably does require a special matcher though:</div><div><br></div><div><br>We have:</div><div> if (m_c_And(m_Cmp(Pred, m_Value(), m_Value()),<br></div><div><div>              m_Cmp(Pred, m_Value(), m_Value()))</div><div><br></div><div>and you really want:</div><div><div> if (m_c_And(m_Cmp(Pred, m_Value(), m_Value()),</div><div>              m_Cmp(m_Opposite(Pred), m_Value(), m_Value()))</div></div><div><br></div><div><br></div></div><div><br></div></div></div></div>