<div dir="ltr">On Thu, Aug 15, 2013 at 5:15 PM, Jim Grosbach <span dir="ltr"><<a href="mailto:grosbach@apple.com" target="_blank">grosbach@apple.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: grosbach<br>
Date: Thu Aug 15 19:15:20 2013<br>
New Revision: 188512<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=188512&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=188512&view=rev</a><br>
Log:<br>
InstCombine: Simplify if(x!=0 && x!=-1).<br>
<br>
When both constants are positive or both constants are negative,<br>
InstCombine already simplifies comparisons like this, but when<br>
it's exactly zero and -1, the operand sorting ends up reversed<br>
and the pattern fails to match. Handle that special case.<br>
<br>
Follow up for rdar://14689217<br>
<br>
Modified:<br>
llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp<br>
llvm/trunk/test/Transforms/InstCombine/and2.ll<br>
<br>
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp?rev=188512&r1=188511&r2=188512&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp?rev=188512&r1=188511&r2=188512&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp Thu Aug 15 19:15:20 2013<br>
@@ -849,10 +849,15 @@ Value *InstCombiner::FoldAndOfICmps(ICmp<br>
case ICmpInst::ICMP_SGT: // (X != 13 & X s> 15) -> X s> 15<br>
return RHS;<br>
case ICmpInst::ICMP_NE:<br>
+ // Special case to get the ordering right when the values wrap around<br>
+ // zero.<br>
+ if (LHSCst->getValue() == 0 && RHSCst->getValue() == -1)<br>
+ std::swap(LHSCst, RHSCst);<br><br></blockquote><div><br></div><div>This is using the operator== which takes uint64_t, which is probably not what you want for the "-1" check. Try isAllOnesValue() instead.</div>
<div><br></div><div>-Eli</div></div></div></div>