This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

convert divisions to multiplications by reciprocals



Hi,
this implements optimization mentioned by Timothy.
In -ffast-math it changes code generation to emit all divisions as
multiplications by reciprocal and they are combined back to direct
divisions in combine.  Trick is that we may suceed CSEing or loop hoisting
the recirprocal and save some clock cycles, as multiplication is considerably
faster.

Even at trivial testcase
float a,b=1,c;
t()
{
  a/=b;
  c/=b;
}
I get roughly 15% speedup on Pentium3.

Honza

Tue Jul 17 17:25:50 CEST 2001  Jan Hubicka  <jh@suse.cz>

	* expr.c (epxand_expr): Convert divisions into multiplications by
	reciprocals if -ffast-math.

Index: expr.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/expr.c,v
retrieving revision 1.338
diff -c -3 -p -r1.338 expr.c
*** expr.c	2001/07/11 20:35:51	1.338
--- expr.c	2001/07/17 14:46:41
*************** expand_expr (exp, target, tmode, modifie
*** 7830,7835 ****
--- 7830,7844 ----
        return expand_divmod (0, code, mode, op0, op1, target, unsignedp);
  
      case RDIV_EXPR:
+       /* Emit a/b as a*(1/b).  Later we may manage CSE the reciprocal saving
+          expensive divide.  If not, combine will rebuild the original
+          computation.  */
+       if (flag_unsafe_math_optimizations && !real_onep (TREE_OPERAND (exp, 0)))
+         return expand_expr (build (MULT_EXPR, type, TREE_OPERAND (exp, 0),
+ 				   build (RDIV_EXPR, type,
+ 					  build_real (type, dconst1),
+ 					  TREE_OPERAND (exp, 1))),
+ 			    target, tmode, unsignedp);
        this_optab = flodiv_optab;
        goto binop;
  


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]