[PATCH, PR 41112] Do not SRA arrays with non-contant domain bounds

Martin Jambor mjambor@suse.cz
Wed Sep 2 17:20:00 GMT 2009


Hi,
On Wed, Sep 02, 2009 at 06:18:22PM +0200, Richard Guenther wrote:
> On Wed, 2 Sep 2009, Martin Jambor wrote:
> 
> > Hi,
> > 
> > the patch below fixes PR 41112 by simply not scalarizing arrays with
> > domain bounds which are not integer constants.
> > 
> > I have asked for a testcase addition in the bugzilla since I don't
> > really know where to put it.  I got freaked out that there is no
> > pr<number> file in gcc/testsuite/gnats.dg and thus have reasons to
> > believe it should go someplace else.
> > 
> > I have just bootstrapped and regression tested this on x86_64-linux,
> > obviously including Ada, revision 151322 (i.e. after VTA).
> > 
> > OK for trunk?
> 
> Hmm.  I would have expected the array to be disqualified once we
> come along an ARRAY_REF/ARRAY_RANGE_REF with non-constant and non-NULL
> operand 2.  

Yes, get_ref_base_and_extent should do that... the only way I can see
it not happening (I don't really understand the ADA source) is when
the array is one element long, just with an unknown index of that one
element.  Then the maxsize returned by get_ref_base_and_extent would
equal to the size and SRA would happily try to scalarize it.

> With the attached patch you no longer scalarize
> struct { int i; int array[x..y]; } if only i is ever accessed.
> 

You are right.  I simply thought this scenario was rather rare and
thus such a quick fix was acceptable.  On the other hand, tree-sra
does not really traverse the ARRAY_REFs and ARRAY_RANGE_REFs on its
own but rather relies on get_ref_base_and_extent.  And so I would have
to add a special scan of every handled_component_p expression to look
for array types like this and I did not really want to.

Obviously, if constructs like the one above do happen often, I can do
that.  Eric, do you think it is worth it?

I hope this explains it,

Martin


> So - why is this check necessary?  Maybe the disqualification is
> not done properly?
> 
> Thanks,
> Richard.
> 
> > Thanks,
> > 
> > Martin
> > 
> > 
> > 
> > 2009-09-02  Martin Jambor  <mjambor@suse.cz>
> > 
> > 	* tree-sra.c (type_internals_preclude_sra_p): Disqualify array
> > 	types with non-constant domain bounds.
> > 
> > Index: mine/gcc/tree-sra.c
> > ===================================================================
> > --- mine.orig/gcc/tree-sra.c
> > +++ mine/gcc/tree-sra.c
> > @@ -548,6 +548,8 @@ type_internals_preclude_sra_p (tree type
> >        return false;
> >  
> >      case ARRAY_TYPE:
> > +      if (TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) != INTEGER_CST)
> > +	return false;
> >        et = TREE_TYPE (type);
> >  
> >        if (AGGREGATE_TYPE_P (et))
> > 
> > 



More information about the Gcc-patches mailing list