On Thu, Sep 10, 2020 at 11:17:34AM +0200, Tobias Burnus wrote:
> Hi Jakub, hello all,
> 
> when looking at target.c, I stumbled over that code:
>   size_t mapnum  → unsigned
>   if (mapnum == 0)
>     ...
>     return;
> 
>   if (mapnum > 0 || ....)
>     ...

But it is not mapnum > 0 here but mapnum > 1
So, for mapnum == 1 and e.g. target enter data it doesn't need to create the
chunks stuff, for a single mapping there is nothing to merge together.

> diff --git a/libgomp/target.c b/libgomp/target.c
> index 3e292eb8c62..440aad6b048 100644
> --- a/libgomp/target.c
> +++ b/libgomp/target.c
> @@ -676,28 +676,23 @@ gomp_map_vars_internal (struct gomp_device_descr 
> *devicep,
>    if (mapnum == 0)
>      {
>        tgt->tgt_start = 0;
>        tgt->tgt_end = 0;
>        return tgt;
>      }
>  
>    tgt_align = sizeof (void *);
>    tgt_size = 0;
> -  cbuf.chunks = NULL;
> -  cbuf.chunk_cnt = -1;
> +  cbuf.chunk_cnt = 0;
>    cbuf.use_cnt = 0;
> -  cbuf.buf = NULL;
> -  if (mapnum > 1 || pragma_kind == GOMP_MAP_VARS_TARGET)
> -    {
> -      size_t chunks_size = (mapnum + 1) * sizeof (struct 
> gomp_coalesce_chunk);
> -      cbuf.chunks = (struct gomp_coalesce_chunk *) gomp_alloca (chunks_size);
> -      cbuf.chunk_cnt = 0;
> -    }
> +  size_t chunks_size = (mapnum + 1) * sizeof (struct gomp_coalesce_chunk);
> +  cbuf.chunks = (struct gomp_coalesce_chunk *) gomp_alloca (chunks_size);
> +
>    if (pragma_kind == GOMP_MAP_VARS_TARGET)
>      {
>        size_t align = 4 * sizeof (void *);
>        tgt_align = align;
>        tgt_size = mapnum * sizeof (void *);
>        cbuf.chunk_cnt = 1;
>        cbuf.use_cnt = 1 + (mapnum > 1);
>        cbuf.chunks[0].start = 0;
>        cbuf.chunks[0].end = tgt_size;


        Jakub

Reply via email to