Author: yug
Date: 2012-03-19 04:54:08 -0400 (Mon, 19 Mar 2012)
New Revision: 3887
Modified:
trunk/osprey/wgen/wgen_stmt.cxx
Log:
fix for bug798.
When we build switch construct in wgen, if the
switch index is a constant. we don't generate
the index var, instead, we use constant the as switch
expression directly. This helps compiler eliminates the
unreachable branch code even at O0 phase.
Code Review: Chandrasekhar Murthy.
Modified: trunk/osprey/wgen/wgen_stmt.cxx
===================================================================
--- trunk/osprey/wgen/wgen_stmt.cxx 2012-03-19 03:37:07 UTC (rev 3886)
+++ trunk/osprey/wgen/wgen_stmt.cxx 2012-03-19 08:54:08 UTC (rev 3887)
@@ -2722,10 +2722,18 @@
// The switch index may be needed more than once if it contains case
// range. As it may have side-effects like a function call, save the
// index into a temporary, and used the saved value.
- ST *save_expr_st = Gen_Temp_Symbol (MTYPE_TO_TY_array[index_mtype],
"_switch_index");
- WN *stid = WN_Stid (index_mtype, 0, save_expr_st,
MTYPE_TO_TY_array[index_mtype], index);
- WGEN_Stmt_Append(stid, Get_Srcpos());
- index = WN_Ldid(index_mtype, 0, save_expr_st,
MTYPE_TO_TY_array[index_mtype]);
+
+ // open64.net bug798. when the switch index is a constant,
+ // we don't generate the index var, instead, we use constant the as switch
+ // expression directly. This helps compiler eliminates the unreachable
+ // branch code even at O0 phase.
+
+ if ( WN_operator(index) != OPR_INTCONST) {
+ ST *save_expr_st = Gen_Temp_Symbol (MTYPE_TO_TY_array[index_mtype],
"_switch_index");
+ WN *stid = WN_Stid (index_mtype, 0, save_expr_st,
MTYPE_TO_TY_array[index_mtype], index);
+ WGEN_Stmt_Append(stid, Get_Srcpos());
+ index = WN_Ldid(index_mtype, 0, save_expr_st,
MTYPE_TO_TY_array[index_mtype]);
+ }
#endif
WGEN_Stmt_Push (switch_block, wgen_stmk_switch, Get_Srcpos());
------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Open64-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/open64-devel