This is the mail archive of the 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]
Other format: [Raw text]

Re: PATCH: [gcc3.5 improvement branch] Very Simple constant propagation

Roger Sayle <> writes:

> On Thu, 15 Jan 2004, Caroline Tice wrote:
> > This patch is to address an efficiency problem in gcc.  If you compile
> > the following small loop with -O3 -ffast-math, the optimizer converts
> > the "a/b"  into "a * 1/b", in the hopes of being able to do some further
> > optimizations.  In this case it can't so ideally  the combiner should
> > convert "a * 1/b"  back into "a/b".  Unfortunately, it can't figure out
> > that it can do that because the combiner only looks within the current
> > basic block, and the constant 1 has been hoisted out of the loop.  This
> > is unfortunate, because it causes an extra floating point
> > multiplication to be performed in every iteration of this loop, which is
> > a major performance hit in the code this originally came from.
> Hi Caroline,
> Interestingly, I also have a patch for exactly this problem that I've
> had waiting until we re-enter stage1.  In my solution, we make use of
> the fact that the 1.0/b is recorded in a REG_EQUAL note on the division,
> and simply enhance "combine" to reduce "a * 1.0/b" into just "a/b"!
> I post it here for comparison, if anyone's interested in evaluating
> compile-time and performance impact of both patches.
> 2003-10-16  Roger Sayle  <>
> 	* combine.c (unmentioned_reg_p): New function to check whether an
> 	expression is a "specialization" of another, i.e. that there are
> 	no registers or memory references mentioned in the first that don't
> 	appear in the second.
> 	(unmentioned_reg_p_1): New helper subroutine of unmentioned_reg_p.
> 	(combine_instructions): Also try combining instructions using the
> 	REG_EQUAL note from a preceding log-linked instruction.

> + /* Check for any register or memory mentioned in EQUIV that is not
> +    mentioned in EXPR.  This is used to restrict EQUIV to "specializations"
> +    of EXPR where some registers may have been replaced by constants.  */

I'm pretty sure this isn't safe.  What happens if you have

(set r4 (neg r3)
  REG_EQUAL (neg r3))

(set r3 (neg r3))

(set r5 (plus r4 r3))


- Geoffrey Keating <>

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