Bug 15484 - [tree-ssa] bool and short function arguments promoted to int
Summary: [tree-ssa] bool and short function arguments promoted to int
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: memory-hog, missed-optimization
Depends on:
Blocks: 32492
  Show dependency treegraph
 
Reported: 2004-05-17 04:33 UTC by Dan Nicolaescu
Modified: 2019-06-26 05:06 UTC (History)
2 users (show)

See Also:
Host:
Target: i686-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-10-22 20:54:54


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Nicolaescu 2004-05-17 04:33:09 UTC
This code: 

_Bool bar (_Bool a);
_Bool foo1 (_Bool a)
{
  if (bar(a))     return 1;
  else            return 0;
}

static short barshort (short a);
short foo1short (short a)
{
  if (barshort(a))     return 1;
  else                 return 0;
}

is transformed to: (when using -O -fdump-tree-generic)

foo1 (a)
{
  int T.17;
  _Bool T.18;

  T.17 = (int)a; <------ this is not needed
  T.18 = bar (T.17);
  if (T.18 != 0)
    {
      return 1;
    }
  else
    {
      return 0;
    }
}

foo1short (a)
{
  int T.19;
  short int T.20;

  T.19 = (int)a; <------ this is not needed
  T.20 = barshort (T.19);
  if (T.20 != 0)
    {
      return 1;
    }
  else
    {
      return 0;
    }
}

the promotions shown are not needed, at least not at this point in the
compilation process.
Comment 1 Andrew Pinski 2004-05-17 04:37:39 UTC
Confirmed.
Comment 2 Nathan Sidwell 2004-11-17 13:33:04 UTC
The underlying ABI might require short & bool arguments to be passed as int. 
Some do, some don't.  Anyway, that's an argument marshalling issue, which is not
currently addressed at the tree level.

The cast to int has been inserted by the front end, I think C requires that.

This is a VRP issue, not an argument marshalling one.
Comment 3 Dan Nicolaescu 2004-12-29 01:33:33 UTC
(In reply to comment #2)
> The underlying ABI might require short & bool arguments to be passed as int. 
> Some do, some don't.  Anyway, that's an argument marshalling issue, which is not
> currently addressed at the tree level.
> 
> The cast to int has been inserted by the front end, I think C requires that.
> 
> This is a VRP issue, not an argument marshalling one.

A discussion about this is at:

http://gcc.gnu.org/ml/gcc/2004-05/msg00752.html

in that thread Jim Wilson has some more explanations about what is going on.

A patch that seems to work is also in that mail, but I won't have time to 
properly test it to try to get it committed anytime soon. If someone wants to
play with this, it would be great.

The problem is that the C and C++ front-ends generate casts to int when
c_promoting_integer_type_p returns true. Those casts are generated too early 
(if they are needed at all, and they might not be needed). Iff the casts are
needed they should be when lowering to RTL.

Comment 4 Richard Biener 2005-05-16 13:55:29 UTC
Maybe the same problem results in

static inline bool wrap(bool f) { return f; }
bool bar(bool f)
{
        return wrap(f);
}

producing

  return (int) (bool) (int) (bool) (int) f;

(and more, if you add another wrap())
Comment 5 Diego Novillo 2005-06-02 18:44:40 UTC
How is this related to VRP at all?  Removing dependency on 18373.
Comment 6 Dan Nicolaescu 2008-11-20 23:27:05 UTC
Still happens in 4.4. 
Comment 7 Andrew Pinski 2008-11-20 23:35:28 UTC
(In reply to comment #6)
> Still happens in 4.4. 

But as mentioned this is not really a bug.