This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
another silly optimisation case
- To: Matthew Kirkwood <weejock at ferret dot lmh dot ox dot ac dot uk>
- Subject: another silly optimisation case
- From: Michael Hayes <m dot hayes at elec dot canterbury dot ac dot nz>
- Date: Thu, 11 Mar 1999 12:31:29 +1300 (NZDT)
- Cc: egcs at egcs dot cygnus dot com
- References: <Pine.LNX.3.96.990310182553.21254A-100000@ferret.lmh.ox.ac.uk>
Matthew Kirkwood writes:
> Hi,
>
> egcs RH5.2 (egcs-2.90.27 980315 (egcs-1.0.2 release))
> generates different code for these two functions, the
> first including a jump even with -O6:
>
> int f(int g) { return g ? 34 : 0; }
>
> int g(int f) { return f && 34; }
>
> I don't suppose (x ? y : 0) is a hugely common construction
> but it seems to be another candidate for simple optimisation.
While these functions are not equivalent (f will return 34 while g
will return 1), the first case will generate suboptimal code on
machines with conditional move instructions. There was a thread I
started a month or two ago on this.
Michael.