Which pass optimizes if (x != x + 10) to if (1)?
Zhenqiang Chen
zhenqiang.chen@linaro.org
Wed Mar 21 07:00:00 GMT 2012
>> 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!
-Zhenqiang
More information about the Gcc-help
mailing list