elliminate more float extensions

Segher Boessenkool segher@koffie.nl
Tue Jan 14 03:19:00 GMT 2003


Jan Hubicka wrote:
> 
> Hi,
> I've been looking for reasons of cvtss2sd (that is slow) in mesa sources and it
> looks like that after installing floor conversion patches to hammer branch most
> of these come from testcases like this:
> 
> /* { dg-do compile { target i?86-*-* x86_64-*-* } } */
> /* { dg-options "-O2 -msse2 -march=athlon" } */
> /* { dg-final { scan-assembler-not "cvtss2sd" } } */
> float a,b;
> main()
> {
>   a=b*3.0;
> }
> 
> We can optimize the cvtss2sd away.  I am doing this by teaching strip_float_extensions
> to find narrowest mode holding the FP constant so the rest of code will choose
> narrowest mode holding the operands and result of the operation.

Does this always work correctly?  Consider:

	float aiee(float a, float b)
	{
		return a * 3.0 * b;
	}

	int main()
	{
		aiee(2e+38f, 0.1f);
	}

This will overflow if the (a * 3.0) is calculated in single precision.

People who care about optimization at this low level should know to
write  3.0f  when they want it, imho.


Segher

(The CMP and ABS/NEGATE patches look safe to me, btw).




More information about the Gcc-patches mailing list