This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Non-call exceptions versus cse
- From: Andrew Haley <aph at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 10 Dec 2002 17:18:34 +0000 (GMT)
- Subject: Non-call exceptions versus cse
- References: <200211191621.gAJGLTs10581@cuddles.cambridge.redhat.com><15834.30922.508706.58112@cuddles.cambridge.redhat.com>
This is a re-posting of a patch.
To recap: store_expr does a little optimization which removes a copy
insn. This is usually OK, but if the right hand side of a store expr
can trap this is wrong.
This is the case I'm interested in:
a = ({ tmp = foo->bar; tmp; });
We must not convert this into
a = foo->bar;
I'm not sure why we're doing this optimization during store_expr,
because the temporary will be deleted by a later compiler pass. I
suppose doing the job early reduces the amount of RTL that we process
and thus speeds up the compiler.
In any case, disabling this optimization when using non-call
exceptions should only make a difference to optimized code when it
would otherwise be incorrect.
If anyone can think of a better way to fix this I'm all ears.
Andrew.
* expr.c (store_expr): Always return target if we're using
non-call exceptions and optimizing.
Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/expr.c,v
retrieving revision 1.494
diff -c -2 -p -r1.494 expr.c
*** expr.c 27 Nov 2002 02:29:11 -0000 1.494
--- expr.c 10 Dec 2002 17:14:29 -0000
*************** store_expr (exp, target, want_value)
*** 4454,4458 ****
&& !(GET_CODE (target) == MEM && MEM_VOLATILE_P (target))
&& ! rtx_equal_p (temp, target)
! && (CONSTANT_P (temp) || want_value))
dont_return_target = 1;
}
--- 4454,4459 ----
&& !(GET_CODE (target) == MEM && MEM_VOLATILE_P (target))
&& ! rtx_equal_p (temp, target)
! && (CONSTANT_P (temp) || want_value)
! && !(flag_non_call_exceptions && optimize))
dont_return_target = 1;
}
Andrew Haley writes:
> I have found another case when using non-call exceptions where a
> temporary variable is incorrectly elided. In this case, expanding a
> store expr turns this:
>
> a = ({ tmp = foo->bar; tmp; });
>
> into this:
>
> a = foo->bar;
>
> Andrew.
>
> * expr.c (store_expr): Always return target if we're using
> non-call exceptions.
>
> Index: expr.c
> ===================================================================
> RCS file: /cvs/gcc/gcc/gcc/expr.c,v
> retrieving revision 1.488
> diff -u -r1.488 expr.c
> --- expr.c 15 Oct 2002 20:09:32 -0000 1.488
> +++ expr.c 19 Nov 2002 17:31:41 -0000
> @@ -4398,7 +4398,8 @@
> && REGNO (target) < FIRST_PSEUDO_REGISTER)
> && !(GET_CODE (target) == MEM && MEM_VOLATILE_P (target))
> && ! rtx_equal_p (temp, target)
> - && (CONSTANT_P (temp) || want_value))
> + && (CONSTANT_P (temp) || want_value)
> + && !flag_non_call_exceptions)
> dont_return_target = 1;
> }
>