One of the micro-optimizations that may be done inside the tree optimizer involves disregarding V_MAY_DEF/V_MUST_DEF operands for read-only globals.
So, if a symbol is marked read-only and the operand scanner requests a V_MAY_DEF or V_MUST_DEF operand for it, we replace it with a VUSE. This works fine, except that I was having comparison errors with SPEC2000's eon. I tracked it down to the C++ FE emitting an assignment instruction for a global const variable. The source code declares const double ggPi = 3.14159265358979323846; double const divPi = 1 / ggPi; And since divPi is initialized to an expression, I guess it needs to compute it at runtime, so it emits an initialization function: void __static_initialization_and_destruction_0(int, int) (__initialize_p, __priority) { ... if (D.55019) { ggPi.319 = ggPi; D.55021 = 1.0e+0 / ggPi.319; divPi = D.55021; } ... } So, we now have an assignment for divPi in the IL stream. This throws a monkey wrench into this micro-optimization because it shouldn't really have ignored that V_MUST_DEF (the tree optimizers end up removing the assignment). This optimization is currently disabled because of this. If the C++ FE is fixed to address this problem, the following patch will re-enable the optimization: --- tree-ssa-operands.c 9 Apr 2005 01:37:24 -0000 2.75 +++ tree-ssa-operands.c 9 Apr 2005 01:51:02 -0000 @@ -1803,14 +1803,8 @@ add_stmt_operand (tree *var_p, stmt_ann_ it into a VUSE. This happens when read-only variables are marked call-clobbered and/or aliased to writeable variables. So we only check that this only happens on stores, and not writes to GIMPLE - registers. - - FIXME: The C++ FE is emitting assignments in the IL stream for - read-only globals. This is wrong, but for the time being disable - this transformation on V_MUST_DEF operands (otherwise, we - mis-optimize SPEC2000's eon). */ + registers. */ if ((flags & opf_is_def) - && !(flags & opf_kill_def) && unmodifiable_var_p (var)) { gcc_assert (!is_real_op); -- Summary: C++ FE emitting assignments to read-only global symbols Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: dnovillo at gcc dot gnu dot org CC: gcc-bugs at gcc dot gnu dot org,mark at codesourcery dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20912