This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Committed] PR26557: Handle const_int in emit_case_nodes
- From: Roger Sayle <roger at eyesopen dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 13 Mar 2006 16:37:08 -0700 (MST)
- Subject: [Committed] PR26557: Handle const_int in emit_case_nodes
This patch is the first of two fixes to resolve PR middle-end/26557.
The problem is that the middle-end may choose to evalutate the switch
statement comparisons in a mode different from the front-end specified
type, due to the availability of comparison instructions etc... This
comparison mode is specified to emit_case_nodes via the mode of the
index RTL passed to it. Unfortunately, it is currently possible for
the switch index to be detected as a constant integer during RTL
expansion, in which case GET_MODE(index) will be VOIDmode. In these
cases, we should compare in the mode specified by index_type.
The second of the two fixes mentioned above follows the "why fix it
once" idiom, by teaching fold-const.c/fold_stmt that dereferencing
constant initialized arrays with a constant index returns a constant
result. This should allow the constant index in the test case below
to be seen by the tree-ssa optimizers. Unfortunately, this second
change is significantly more intrusive, and probably not appropriate
for the 4.0 and 4.1 release branches.
The following patch has been bootstrapped and regression tested against
both mainline and the gcc-4_1-branch on x86_64-unknown-linux-gnu, all
default languages, with no new failures. I'll commit to the active
release branches as testing finishes.
Committed to mainline as revision 112032.
2006-03-13 Roger Sayle <roger@eyesopen.com>
PR middle-end/26557
* stmt.c (emit_case_nodes): Handle the case where the index is a
CONST_INT, where the comparison mode is specified by the index type.
* gcc.c-torture/compile/switch-1.c: New test case.
Index: stmt.c
===================================================================
*** stmt.c (revision 111970)
--- stmt.c (working copy)
*************** emit_case_nodes (rtx index, case_node_pt
*** 2936,2941 ****
--- 2936,2945 ----
enum machine_mode mode = GET_MODE (index);
enum machine_mode imode = TYPE_MODE (index_type);
+ /* Handle indices detected as constant during RTL expansion. */
+ if (mode == VOIDmode)
+ mode = imode;
+
/* See if our parents have already tested everything for us.
If they have, emit an unconditional jump for this node. */
if (node_is_bounded (node, index_type))
/* PR middle-end/26557. */
const int struct_test[1] = {1};
void g();
void f() {
switch(struct_test[0]) {
case 1: g();
}
}
Roger
--