[patch] for PRs 27639 and 26719
Richard Guenther
rguenther@suse.de
Thu Jul 6 13:57:00 GMT 2006
On Thu, 6 Jul 2006, Duncan Sands wrote:
> > > 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.
Ok, this undefinedness would need to be teached to fold. Certainly
we "preserve" truncation for types with different TYPE_PRECISION or
mode (of course). See the fold_unary case for NOP_EXPR at
/* Handle cases of two conversions in a row. */
if (TREE_CODE (op0) == NOP_EXPR
|| TREE_CODE (op0) == CONVERT_EXPR)
...
Richard.
>
> 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.
>
>
--
Richard Guenther <rguenther@suse.de>
Novell / SUSE Labs
More information about the Gcc-patches
mailing list