This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix 14844/15459/21608: Forward-propagate casts that will collapse
On Tue, May 24, 2005 at 07:04:01PM -0400, Diego Novillo wrote:
> What if you simply modify copy_prop_visit_stmt
> to strip type casts before checking the RHS for copies?
>
> T1 x_3 = (T1)y_1;
> T2 z_5 = (T2)x_3;
>
> If we strip T1, x_3's value becomes y_1 which is then substituted
> in the second statement. Final substitution can determine that
> the cast is not needed in z_5 = (T2)y_1.
I think we'd need a bit more than that.
T0 w_0;
T1 x_1 = (T1)w_0;
t1 y_2 = *x_1;
We can't propagate w_0 into y_2's definition here.
T0 w_0;
T1 x_1 = (T1)w_0;
T0 y_2 = (T0)x_1;
t0 z_3 = *y_2;
But we can propagate w_0 into z_3's definition. We need a check
If the final substitution is a bare RHS, then we can introduce a
new cast, otherwise we have to check that the copy is of the
desired type.
r~