On Wed, 6 Aug 2014, Marek Polacek wrote:

> On Tue, Aug 05, 2014 at 02:14:21PM -0600, Jeff Law wrote:
> > My concern is the code we're removing discusses the need to simplify when
> > these expressions are in static initializers.  What's going to ensure that
> > we're still simplifying instances which appear in static initializers?  I
> > don't see anything which tests that.   And does it still work for targets
> > which utilize PSImode?
> 
> Aw nuts.  So with the patch we'd start erroring out on
> static __PTRDIFF_TYPE__ d1 = p - (p + 1);
> static __PTRDIFF_TYPE__ d2 = p - (p - 1);
> (it's nowhere in the testsuite/code base - and I hadn't noticed that
> until today :()
> while we'd still accept
> static __PTRDIFF_TYPE__ d5 = (p - 1) - p;
> static __PTRDIFF_TYPE__ d6 = (p + 1) - p;
> (Those are not constant expression according to ISO C.)
> 
> The reason is that fold_build can fold
> "(long int) (p + 4) - (long int) p" to 4, but not
> "(long int) p - (long int) (p + 4)".
> 
> That means we have to have a way how to fold the latter, but only in
> static initializers.  So I guess I need to implement this in
> fold-const.c...   Oh well.
> 
> Nevertheless, I'd guess the fwprop bits could go in separately (it's
> beneficial for C++).
> 
> As for PSImode, I dunno - seems only m32c and AVR use that?  I have no
> way how to perform testing on such targets.

The issue for those targets is mainly how they define their 'sizetype'
vs. their pointer types.  For m32c IIRC sizetype is 16bits while
pointer types are 24bit (PSImode).  That means that pointer-to-int
conversion is usually widening and that pointer-offsetting cannot
access large objects fully.  See also

        /* Allow conversions from pointer type to integral type only if
           there is no sign or zero extension involved.
           For targets were the precision of ptrofftype doesn't match that
           of pointers we need to allow arbitrary conversions to 
ptrofftype.  */
        if ((POINTER_TYPE_P (lhs_type)
             && INTEGRAL_TYPE_P (rhs1_type))
            || (POINTER_TYPE_P (rhs1_type)
                && INTEGRAL_TYPE_P (lhs_type)
                && (TYPE_PRECISION (rhs1_type) >= TYPE_PRECISION 
(lhs_type)
                    || ptrofftype_p (sizetype))))
          return false;

which we may restrict better with checking whether the pointer
uses a partial integer mode.  Not sure how PSImode -> SImode
"extends" on RTL?

Richard.

Reply via email to