This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Which pass optimizes if (x != x + 10) to if (1)?


On 21 March 2012 21:48, Ian Lance Taylor <iant@google.com> wrote:
> Zhenqiang Chen <zhenqiang.chen@linaro.org> writes:
>
>>>> Which pass optimizes if (x != x + 10) to if (1)? Why is it not applied to -Os?
>>>
>>> It's not a separate pass. ?It's code in fold-const.c.
>>>
>>> I don't know why -Os makes a difference here. ?It does seem odd. ?I
>>> encourage you to investigate what is happening.
>>>
>>
>> Thank you for the comment. I found the root cause. In function
>> tree_swap_operands_p (fold-const.c), there is a check
>>
>> if (optimize_function_for_size_p (cfun))
>> ? ? return 0;
>>
>> which blocks to swap (x != x + 10) to (x + 10 != x). And the following
>> optimization can only handle (x + 10 != x).
>>
>> In most cases, constant-folding will benefit for code size. Any reason
>> to add this check?
>
> Thanks for looking into this. ?The test was added here:
>
> http://gcc.gnu.org/ml/gcc-patches/2003-10/msg01208.html
>
> When I tried your test case, I agree that the test was not optimized out
> initially, but it was optimized out in the generated code. ?Do you have
> a test case in which the final generated code is worse? ?If you do,
> please open a bug report.

Here is the test case:

gcc/testsuite/gcc.dg/pr30951.c.

-Zhenqiang


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]