<div dir="ltr">On Tue, Aug 13, 2013 at 2:30 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: Tue Aug 13 16:30:58 2013<br>
New Revision: 188315<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=188315&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=188315&view=rev</a><br>
Log:<br>
DAG: Combine (and (setne X, 0), (setne X, -1)) -> (setuge (add X, 1), 2)<br>
<br>
A common idiom is to use zero and all-ones as sentinal values and to<br>
check for both in a single conditional ("x != 0 && x != (unsigned)-1").<br>
That generates code, for i32, like:<br>
  testl %edi, %edi<br>
  setne %al<br>
  cmpl  $-1, %edi<br>
  setne %cl<br>
  andb  %al, %cl<br>
<br>
With this transform, we generate the simpler:<br>
  incl  %edi<br>
  cmpl  $1, %edi<br>
  seta  %al<br>
<br>
Similar improvements for other integer sizes and on other platforms. In<br>
general, combining the two setcc instructions into one is better.<br>
<br>
rdar://14689217<br><br></blockquote><div><br></div><div>We already have code in InstCombiner::FoldAndOfICmps to handle this sort of thing; it looks like it isn't catching this particular case for some reason, though.</div>
<div><br></div><div>-Eli </div></div><br></div></div>