Re: [Open64-devel] optimizing extern const
Brought to you by:
ributzka,
suneeljain
From: Christian B. <chr...@st...> - 2006-04-06 11:07:30
|
you might also want to test for SCLASS_AUTO since a const local variable might be modified. the front end would warn about this. Regards, Christian Mike Murphy wrote: > "extern const" is probably not a common usage, > but I ran into it in one of our tests, and discovered > that we don't optimize it very well. E.g. consider the code: > > extern const int ec; > extern void dummy(void); > > int test (int x, int y) > { > if (ec * 3 == x) > return 0; > dummy(); > if (ec * 3 == y) > return 1; > return 2; > } > Ideally we would cse the ec*3, > which should be safe since the value of ec > will not change across the call. > But open64 doesn't do this, because gccfe is only > marking initialized constants as ST_is_const_var. > This is a case of a const_var with unknown initialization. > > The fix I came up with is to add to > gccfe/tree_symtab.cxx:Create_ST_For_Tree: > if (TREE_CODE(decl_node) == VAR_DECL && TREE_READONLY(decl_node)) { > Set_ST_is_const_var(st); > } > and then in be/com/be_symtab.cxx:ST_is_const_initialized: > // if is extern const, then is same as unknown const > if (ST_sclass(st) == SCLASS_EXTERN) > return FALSE; > > If anyone sees a problem with this, please let me know. > > ------------------------------------------------------------------------ > This email message is for the sole use of the intended recipient(s) and > may contain confidential information. Any unauthorized review, use, > disclosure or distribution is prohibited. If you are not the intended > recipient, please contact the sender by reply email and destroy all > copies of the original message. > ------------------------------------------------------------------------ > |