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)?


Zhenqiang Chen <zhenqiang.chen@linaro.org> writes:

> For the following case: -O0/-O2 can optimize if (x != x + 10) to if
> (1) at the beginning. But -Os can not. All options can optimize  if (x
> + 10 != x) to if (1).
>
> To reproduce it, check test.c.003t.original for the two commands.
>
> gcc test.c -fdump-tree-all -c -O0.
> gcc test.c -fdump-tree-all -c -Os.
>
> void test (int x, unsigned int y)
> {
>   if (x != x + 10)
>     ;
>   if (x + 10 != x)
>     ;
> }
>
> 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.

Ian


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