Zhenqiang Chen <zhenqiang.chen@xxxxxxxxxx> 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. Ian