This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH: PR middle-end/33007: builtin lround doesn't work
On 8/21/07, H.J. Lu <hjl@lucon.org> wrote:
> On Tue, Aug 21, 2007 at 10:21:26AM +0200, Richard Guenther wrote:
> > On 8/20/07, H.J. Lu <hjl@lucon.org> wrote:
> > > On Mon, Aug 20, 2007 at 10:32:24AM +0200, Richard Guenther wrote:
> > > > On 8/7/07, H.J. Lu <hjl@lucon.org> wrote:
> > > > > fold_fixed_mathfn may turn builtin lround into FIX_TRUNC_EXPR. But
> > > > > expand_builtin_int_roundingfn_2 isn't prepared to deal with it. This
> > > > > patch checks return from expand_expr and handle FIX_TRUNC_EXPR.
> > > > >
> > > >
> > > > This is not the right way to fix this really. Instead this is the
> > > > common problem
> > > > that build_call_expr folds the built expression. Instead for
> > > >
> > > > /* Wrap the computation of the argument in a SAVE_EXPR, as we may
> > > > need to expand the argument again. This way, we will not perform
> > > > side-effects more the once. */
> > > > narg = builtin_save_expr (arg);
> > > > if (narg != arg)
> > > > {
> > > > arg = narg;
> > > > exp = build_call_expr (fndecl, 1, arg);
> > > > }
> > > >
> > > > we should re-build the call expression _without_ folding it. (Or
> > > > rather we can fix
> > > > the place that created the call without folding it - that is, fold
> > > > during TER). See
> > > > for example expand_builtin_cexpi or others which make sure not to re-fold the
> > > > call expression.
> > > >
> > >
> > > The testcase is
> > >
> > > long
> > > foo (int i)
> > > {
> > > float x;
> > > x = i;
> > > return __builtin_lroundf (x);
> > > }
> > >
> > > When fold_fixed_mathfn is called the first time, integer_valued_real_p
> > > returns false since it doesn't enough info. When fold_fixed_mathfn is
> > > called after expand_builtin_int_roundingfn_2, integer_valued_real_p
> > > returns true, fold_fixed_mathfn can perform optimization. Will your
> > > suggestion lead to missed optimization?
> >
> > Yes. But only because we expand unfolded expressions.
> >
>
> Do you have a suggestion to geneate the same assembly code for
>
> long
> foo (int i)
> {
> float x;
> x = i;
> return __builtin_lroundf (x);
> }
>
> and
>
> long
> foo (int i)
> {
> return __builtin_lroundf (i);
> }
A tree combiner. That is, extend value-numbering to do this.
Richard.