This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] tree-ssa-forwprop.c: Make a COND_EXPR absorb anon-narrowing cast.


>> On Fri, May 27, 2005 at 09:41:02AM -0400, Kazu Hirata wrote:
>> Attached is a patch to make a COND_EXPR absorb a non-narrowing cast.
>> 
>> int
>> foo (unsigned char *p)
>> {
>>   unsigned char a = *p;
>>   unsigned int b = (unsigned int) a;
>>   if (b == 2)
>>     return 100;
>>   return 200;
>> }
>> 
>> Note that we could replace the "if" statement's condition with
>> "a == 2".
>>
>> Tested on i686-pc-linux-gnu.  OK to apply?
> 
> No.  This is more of a copy propagation problem. If (unsigned int)
> really is a non-narrowing cast, we can copy propagate a into
> 'if (b == 2)' above.
> 
> We discussed this problem a couple of days ago and agreed that
> the copy propagator was a more natural candidate for this.

Actually it seems that, the final unsigned rank is always optimally the
lesser of the unsigned ranks in an arbitrary sequence of unsigned casts.

Unsigned casts of greater rank than their operand may always be dropped
without loosing any precision, (thereby implying source operand may be
propagated forward, effectively replacing the target operand in all
cases, as in the above example). Correspondingly all unsigned casts of
of lesser rank than their source operand must be logically retained as
it's precision has been specified as being effectively reduced, thereby
effectively propagating the lower rank target type back to the source
operand (which may in-turn be recursively further propagated back to
it's corresponding source operand if of greater rank). Therefore:

  unsigned char  a = n
  unsigned short b = a;
=>
  unsigned char a = n;

  unsigned short a = n;
  unsigned char  b = a;
=>
  unsigned char a = n;

(where in either case, the final unsigned rank is always the lesser
of the unsigned ranks in an arbitrary sequence of unsigned casts.)





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]