[llvm] r188315 - DAG: Combine (and (setne X, 0), (setne X, -1)) -> (setuge (add X, 1), 2)

Eli Friedman eli.friedman at gmail.com
Tue Aug 13 16:50:00 PDT 2013


On Tue, Aug 13, 2013 at 3:59 PM, Jim Grosbach <grosbach at apple.com> wrote:

>
> On Aug 13, 2013, at 3:33 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
>
> On Tue, Aug 13, 2013 at 3:09 PM, Jim Grosbach <grosbach at apple.com> wrote:
>
>>
>> On Aug 13, 2013, at 2:39 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
>>
>> On Tue, Aug 13, 2013 at 2:30 PM, Jim Grosbach <grosbach at apple.com> wrote:
>>
>>> Author: grosbach
>>> Date: Tue Aug 13 16:30:58 2013
>>> New Revision: 188315
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=188315&view=rev
>>> Log:
>>> DAG: Combine (and (setne X, 0), (setne X, -1)) -> (setuge (add X, 1), 2)
>>>
>>> A common idiom is to use zero and all-ones as sentinal values and to
>>> check for both in a single conditional ("x != 0 && x != (unsigned)-1").
>>> That generates code, for i32, like:
>>>   testl %edi, %edi
>>>   setne %al
>>>   cmpl  $-1, %edi
>>>   setne %cl
>>>   andb  %al, %cl
>>>
>>> With this transform, we generate the simpler:
>>>   incl  %edi
>>>   cmpl  $1, %edi
>>>   seta  %al
>>>
>>> Similar improvements for other integer sizes and on other platforms. In
>>> general, combining the two setcc instructions into one is better.
>>>
>>> rdar://14689217
>>>
>>>
>> 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.
>>
>>
>> There’s already a bunch of similar checks in the DAGCombiner, too. I
>> mainly put it there to that we’ll be able to catch more complicate cases
>> that simplify to this one from other DAG transformations, that are exposed
>> from target lowerings, etc..
>>
>
> I'm not convinced it will actually show up from lowering in practice.
>
>
> I’m not convinced either way, really. Simply a mild motivation in one
> direction over the other. *shrug*
>
> That said, then why do we have any of the transformations we do for setcc
> in DAGCombine? The same sort of arguments can be made equally strongly for
> them, yes?
>

Well, some of the transformations show up after legalization from simple
transformations like splitting an equality comparison.

-Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130813/bd10e3fe/attachment.html>


More information about the llvm-commits mailing list