Elimination of duplicate sign extensions

Mark Mitchell mark@codesourcery.com
Thu Sep 13 19:04:00 GMT 2007


Nigel Stephens wrote:

>>> To be clear, the case where the optimization you're working on is
>>> interesting is when the ABI does not require that callers sign-extend
>>> arguments to functions -- but we do it anyhow.  Is that correct?

> Not quite. This code relies on the fact that the caller has already
> performed the argument  promotion due to the prototype definition -- so
> we were performing the promotion twice, once in the caller and once in
> the callee.

I'm still confused. :-(  I'm having a hard time understanding why we
ever need the promotion in the callee.

Are you saying that the ABI requires that callers promote if there's a
prototype, but does not require that if there is no prototype?  So, in
the general case, we must also promote in the callee to handle cases
like this:

  a.c
  ---
  void g() { f ('a'); }

  b.c
  ---
  void f(int i) { ... }

?  But, doesn't C say that an unprototyped call promotes arguments to
'int' or 'double' anyhow, so that the caller will still promote 'a' to
'int'?

If we do sometimes need the promotion in the callee, due to lack of
prototypes, then we should be careful about cases like this:

  void g() { f('a'); }
  static void f(int i) { ... }

Here, we know that all calls to "f" are local, but the call was still
done without a prototype.  I'm not sure if that case matters, because
I'm confused overall, but it's worth remembering.

Sorry to be dense here,

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713



More information about the Gcc-patches mailing list