public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: fold_convert question
@ 2004-10-16 12:34 Richard Kenner
  2004-10-16 13:12 ` Andrew Pinski
  0 siblings, 1 reply; 13+ messages in thread
From: Richard Kenner @ 2004-10-16 12:34 UTC (permalink / raw)
  To: roger; +Cc: gcc

    But "fold" itself calls "fold_convert" to ensure/force a tree to a
    specified type.  i.e. fold_convert is called for both generic, gimple
    and potentially even by front-ends that don't use tree-ssa.

Hmm ...

    I agree completely that the problem is one of consistency, but I would
    argue that the bug is in (this use of) STRIP_USELESS_TYPE_CONVERSIONS.
    It's not that fold_convert is broken, but that the VIEW_CONVERT_EXPR
    shouldn't have been stripped off in the first place.   I probably wouldn't
    consider the conversion of an ARRAY_TYPE to a scalar to be useless?

It's not a conversion between arrays and scalars, but between two
ARRAY_TYPEs.  Otherwise, they wouldn't have been compartible!
(Ada says that two ARRAY_TYPEs are compatible if the component types
are compatible and the bounds are the same.)

    Indeed the fact that VIEW_CONVERT_EXPR is only used by Ada probably
    helps explain why S_U_T_C is overly aggressive in removing it.  For
    the majority of front-ends (and Ada uses) fold_convert does the right
    thing.

I added the removal of the VIEW_CONVERT_EXPR to S_U_T_C and I still believe
it should be there.

    tree_ssa_useless_type_conversion is an unfortunate hack to work around
    the fact that tree-ssa doesn't yet have a combiner pass.  Without a
    combiner, the optimization passes can only see one statement and its
    operands at a time, so the "necessary" type conversions required to
    keep operands consistent often create a "horizon affect" where
    optimization opportunities are missed due to the local nature of SSA
    form.

Perhaps, but I don't see it that way.  It's always better to keep code at any
level of representation as simple as possible.  If we have conversions that
we know aren't going to generate any code, the earlier we remove them the
better.

    If there's anything I can do to help you investigate/fix c61008a
    that avoids further degenerating the middle-end's type system, I'd
    be happy to help.  Ultimately, this might be a loosing crusade,
    but I couldn't forgive myself if I didn't try.  Worst case scenario
    of tweaking useless_type_conversions is that we miss some optimizations
    (until we get a tree-ssa combiner), but of perverting fold_convert
    is that we regress many difficult to diagnose code generation bugs.

The investigation of that failure is, to a large extent, secondary.

We have the larger problem of being careful to define what "type correctness"
means at tree level.  I previously thought it was uniformly agreed that it
means "strictly correct" in GENERIC and "compatible" (as defined by the lang
hook) in GIMPLE.  So the first question we need to answer is if that's
correct or not.

If it is, then we need to understand which of the tests fold_convert ought to
use based on when it's called.  It may well be that the bug here is in the
caller, which shouldn't be calling it if the types are already compatible.

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: fold_convert question
@ 2004-10-19  8:16 Richard Kenner
  0 siblings, 0 replies; 13+ messages in thread
From: Richard Kenner @ 2004-10-19  8:16 UTC (permalink / raw)
  To: law; +Cc: gcc

    Solving the tree combination problem in a general way that allows
    us to remove the useless type conversion, forward propagation,
    expression reassociation and related problems should be high on
    our todo list once we change focus from 4.0 to 4.1.

I agree. But the tree combiner should also be able to compute the sorts of
data that the RTL combiner produces (which bits are known zero and how
many copies of the sign bit we know we have).  How to do this was discussed
at the last summit.

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: fold_convert question
@ 2004-10-18 21:15 Richard Kenner
  2004-10-19  7:16 ` Eric Botcazou
  0 siblings, 1 reply; 13+ messages in thread
From: Richard Kenner @ 2004-10-18 21:15 UTC (permalink / raw)
  To: law; +Cc: gcc

    It seems to me we'd be best off turning:

      ADDR_EXPR <pointer_type <record_type>>
        VIEW_CONVERT_EXPR <record_type>
          NOP_EXPR <integer_type1>
            ARRAY_REF <integer_type2>

    Into

    NOP_EXPR <integer_type1>
      ADDR_EXPR <pointer_type <integer_type2>>
        ARRAY_REF <integer_type2>

I assume you mean the NOP_EXPR's type to be a pointer to integer_type1.
I thought we had code in gimplify.c to do that once, actually.  It
shouldn't be hard and I agree that it makes the most sense.

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: fold_convert question
@ 2004-10-16 14:36 Richard Kenner
  0 siblings, 0 replies; 13+ messages in thread
From: Richard Kenner @ 2004-10-16 14:36 UTC (permalink / raw)
  To: pinskia; +Cc: gcc

    What I don't understand is why have two different ARRAY types in the
    first place?

Two different subtypes, for example.

    This seems very inefficient.  As a new GCC developer I would like to
    see that types be correctly done in the front-end and middle-end.
    Saying two types are compatible but having a VIEW_CONVERT is just
    wrong.

No, it's not.  In the GENERIC tree, we require that the tree be precisely
type-correct.  The VIEW_CONVERT_EXPR serves that purpose.  For GIMPLE,
we weaken the type-correctness to compatible types.  At that point, the
VIEW_CONVERT_EXPR isn't needed and is removed.

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: fold_convert question
@ 2004-10-16  3:16 Richard Kenner
  2004-10-16  5:23 ` Roger Sayle
  0 siblings, 1 reply; 13+ messages in thread
From: Richard Kenner @ 2004-10-16  3:16 UTC (permalink / raw)
  To: roger; +Cc: gcc

    No, fold_convert is required to be strongly type safe by the GCC
    middle-end.

I'm confused.  I thought the rules are that GIMPLE is *not* strongly
type safe.  We remove all conversions between compatible types.
So the definition for GIMPLE is compatible types, not identical types.

Subsequent to sending my last email I discovered that this relevant to
the ACATS failure in c61008a, though fixing this isn't enough, since
something else is broken (I don't know what yet, but I suspect its the
type replacement for inlining).

The issue is the call from setup_one_parameter.  It wants to make sure
that the argument is converted to the type of the parameter.  In the
original GENERIC tree of the CALL_EXPR in this case, it was converted to
that type with a VIEW_CONVERT_EXPR.  But that was stripped off because
the types were compatible.  Then when the call was inlined, we tried to
convert it back, but couldn't at middle-end level because it was an
ARRAY_TYPE.

      If a function calls fold_convert (T, X), then the tree
        type of the returned expression will/must always be T.

    i.e.  TREE_TYPE (fold_convert (T, X)) == T

I don't see why.  Isn't it enough that they be compatible (in the
meaning of the lang hook)?

    [Likewise calling fold on a tree of type T, must always return
    a tree of type T]

Right, because "fold" is called on GENERIC, but fold_convert only on
GIMPLE and the typing rules are different.

    Besides, the phrase "types are compatible" is purely a front-end
    concept, that doesn't exist in the middle-end.  

Sure it does!  See STRIP_USELESS_TYPE_CONVERSION.

    As an Ada person, I'm sure you appreciate not having fold_convert
    impose any notion of "type compatability" on gigi's trees, other
    than the semantics implied by the original trees themselves.

Exactly the other way around: I expect the middle-end to consistently
use the language hook that says what's compatible and what isn't.  If it's
not going to do that, then it shouldn't trip "useless" type conversions!

^ permalink raw reply	[flat|nested] 13+ messages in thread
* fold_convert question
@ 2004-10-15 20:56 Richard Kenner
  2004-10-16  3:10 ` Roger Sayle
  0 siblings, 1 reply; 13+ messages in thread
From: Richard Kenner @ 2004-10-15 20:56 UTC (permalink / raw)
  To: gcc

Right now, it does nothing only if the original and resulting type
are the same. That seems wrong to me.  Shouldn't it also do nothing if
the types are compatible?

I don't have any specific bug here, but I did notice this when looking
for another bug (that wasn't caused by this).

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2004-10-18 20:58 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-16 12:34 fold_convert question Richard Kenner
2004-10-16 13:12 ` Andrew Pinski
  -- strict thread matches above, loose matches on Subject: below --
2004-10-19  8:16 Richard Kenner
2004-10-18 21:15 Richard Kenner
2004-10-19  7:16 ` Eric Botcazou
2004-10-16 14:36 Richard Kenner
2004-10-16  3:16 Richard Kenner
2004-10-16  5:23 ` Roger Sayle
2004-10-16 20:24   ` Eric Botcazou
2004-10-18 20:57     ` Jeffrey A Law
2004-10-19  7:06   ` Jeffrey A Law
2004-10-15 20:56 Richard Kenner
2004-10-16  3:10 ` Roger Sayle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).