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] for PRs 27639 and 26719


> > tmp1 = (supertype) a;
> > tmp2 = tmp1 + 1;
> > a = (subtype) tmp2;
> > tmp3 = (supertype) a;
> > tmp4 = tmp3 * 2;
> > a = (subtype) tmp4;
> > 
> > into
> > 
> > tmp1 = (supertype) a;
> > tmp2 = tmp1 + 1;
> > tmp4 = tmp2 * 2;
> > a = (subtype) tmp4;
> > 
> > the results should not turn out much different from the ones obtained by
> > the first possibility.
> 
> It can only do so, if it can prove that
> 
>  tmp3 = (supertype)(subtype)tmp2;
> 
> does not truncate tmp2, so at most VRP can handle this with appropriate
> range information.

Hi Richard, I'm not sure what you mean by "truncate".  If supertype
is the Ada base type of subtype, then casting to subtype doesn't do
anything, except tell the compiler (VRP) that either tmp2 is in the
range of subtype or the program is erroneous.  It certainly doesn't
change the numerical value in any way.  So there are two cases:
(a) tmp2 is in the range of subtype, in which case
(supertype)(subtype)tmp2 gives tmp2, or
(b) tmp2 is not in the range of the subtype [*], in which case the
program is erroneous, so you can assume that (supertype)(subtype)tmp2
yields tmp2 if you want.
So there is no need to prove anything here, certainly there are no
issues with truncation.

Duncan.

[*] in which case it is presumably an uninitialized variable or
equivalent, since otherwise we would not be executing this code
due to the range checks inserted by the front-end.


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