On Fri, Jul 31, 2015 at 11:41:47AM +0200, Richard Biener wrote: > >> Const qualification of a pointer or reference doesn't result in any > >> optimization. The > >> decl you refer to has to be constant. > > > > Even if the pointer would be addressable? > > Yes, it's the decls readonly setting that matters, not type qualification. > > > But it isn't in this case. > > Still the > > if (is_gimple_omp_offloaded (ctx->stmt)) > > type = build_qualified_type (type, TYPE_QUAL_CONST); > > would constify what the reference refers to. Maybe it doesn't make > > any difference either due to TYPE_QUAL_RESTRICT on the reference though. > > Maybe.
Ok, so I'll test: 2015-07-31 Jakub Jelinek <ja...@redhat.com> * omp-low.c (fixup_child_record_type): Const qualify *.omp_data_i. (create_omp_child_function): Set TREE_READONLY on .omp_data_i. --- gcc/omp-low.c.jj 2015-07-31 11:08:38.581201231 +0200 +++ gcc/omp-low.c 2015-07-31 11:49:14.764734054 +0200 @@ -1824,6 +1824,11 @@ fixup_child_record_type (omp_context *ct layout_type (type); } + /* In a target region we never modify any of the pointers in *.omp_data_i, + so attempt to help the optimizers. */ + if (is_gimple_omp_offloaded (ctx->stmt)) + type = build_qualified_type (type, TYPE_QUAL_CONST); + TREE_TYPE (ctx->receiver_decl) = build_qualified_type (build_reference_type (type), TYPE_QUAL_RESTRICT); } @@ -2521,6 +2526,7 @@ create_omp_child_function (omp_context * DECL_ARG_TYPE (t) = ptr_type_node; DECL_CONTEXT (t) = current_function_decl; TREE_USED (t) = 1; + TREE_READONLY (t) = 1; if (cilk_for_count) DECL_CHAIN (t) = DECL_ARGUMENTS (decl); DECL_ARGUMENTS (decl) = t; Jakub