[PATCH, take 2] Fix PR middle-end/26717

Roger Sayle roger@eyesopen.com
Sat Mar 25 05:01:00 GMT 2006


On Thu, 23 Mar 2006, Uros Bizjak wrote:
> 2006-03-23  Uros Bizjak  <uros@kss-loka.si>
>
> 	PR middle-end/26717
> 	* fold-const.c (fold_binary) [RDIV_EXPR]: Do not optimize A / A
> 	to 1.0 for non-real operands.
>

This is OK for mainline with the change that your new test/clause
	TREE_CODE (TREE_TYPE (arg0)) == REAL_TYPE
be changed to read SCALAR_FLOAT_TYPE_P (TREE_TYPE (arg0)) and
move it to be the first condition in the conjunction, i.e. before
the existing !HONOR_NANS test.


Ideally, however, it would be nice to implement this optimization for
complex types (so LAPACK would itself benefit).  Something like the
additional transformation:

	/* The complex version of the above X / X optimization.  */
	if (COMPLEX_FLOAT_TYPE_P (TREE_TYPE (arg0))
	    && operand_equal_p (arg0, arg1, 0))
	  {
	    tree elem_type = TREE_TYPE (TREE_TYPE (arg0));
	    if (! HONOR_NANS (TYPE_MODE (elem_type))
		&& ! HONOR_INFINITIES (TYPE_MODE (elem_type)))
	      {
		tree r = build_real (elem_type, dconst1);
		/* omit_two_operands will call fold_convert for us.  */
		return omit_two_operands (type, r, arg0, arg1);
	      }
	  }

The additional hunk above (or something similar) is pre-approved if it
survives bootstrap and regression testing.


I look forward to seeing Paolo's fix for PR26821 that apparently includes
a new function to generate a vector of identical constants (a generic
version of build_zero_vector) that should allow GCC to also implement
this same optimization for VECTOR_FLOAT_TYPE_P (TREE_TYPE (arg0)).


Thanks for tackling this, and many thanks in advance if you decide to
bootstrap/regtest/commit the complex implementation proposed above.


Roger
--



More information about the Gcc-patches mailing list