https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119602

            Bug ID: 119602
           Summary: [OpenMP] append_args dependent prefer_type uses value
                    from first instantiation in all instantiations
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: waffl3x at protonmail dot com
  Target Milestone: ---

Created attachment 60968
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=60968&action=edit
Output with -ftree-dump-gimple

This bug is already fixed in my patch,
I am just posting it for record keeping purposes.

The problem is more evident in the gimple tree dump, but can still be
observed in godbolt.  The most obvious indicator is the string literal
with the value for omp_ifr_level_zero is not contained at the top.  You
can also observe the incorrect literals being moved into edx before
each instantiation of v_dependent_fr is called.
https://godbolt.org/z/PGvocd9Pv
```
typedef enum omp_interop_t : __UINTPTR_TYPE__
{
  omp_interop_none = 0
} omp_interop_t;

typedef enum omp_interop_fr_t
{
  omp_ifr_cuda = 1,
  omp_ifr_cuda_driver = 2,
  omp_ifr_opencl = 3,
  omp_ifr_sycl = 4,
  omp_ifr_hip = 5,
  omp_ifr_level_zero = 6,
  omp_ifr_hsa = 7,
  omp_ifr_last = omp_ifr_hsa
} omp_interop_fr_t;

template<omp_interop_fr_t V>
struct FR {};

template<omp_interop_fr_t V, typename T2>
void v_dependent_fr(FR<V> x, T2 y) { }

#pragma omp declare variant(v_dependent_fr) match(construct={dispatch}) \
  append_args(interop(prefer_type(V)))
template<omp_interop_fr_t V>
void b_dependent_fr(FR<V> x) { }


template<typename T, typename T2>
void v_cuda(T x, T2 y) { }

#pragma omp declare variant(v_cuda) match(construct={dispatch}) \
  append_args(interop(prefer_type(omp_ifr_cuda_driver)))
template<typename T>
void b_cuda(T x) { }


template<typename T, typename T2>
void v_hip(T x, T2 y) { }

#pragma omp declare variant(v_hip) match(construct={dispatch}) \
  append_args(interop(prefer_type(omp_ifr_hip)))
template<typename T>
void b_hip(T x) { }


template<typename T, typename T2>
void v_hsa(T x, T2 y) { }

#pragma omp declare variant(v_hsa) match(construct={dispatch}) \
  append_args(interop(prefer_type(omp_ifr_hsa)))
template<typename T>
void b_hsa(T x) { }

void f ()
{
  #pragma omp dispatch
  b_dependent_fr (FR<omp_ifr_cuda_driver>{});

  #pragma omp dispatch
  b_dependent_fr (FR<omp_ifr_hip>{});

  #pragma omp dispatch
  b_dependent_fr (FR<omp_ifr_level_zero>{});

  #pragma omp dispatch
  b_dependent_fr (FR<omp_ifr_hsa>{});

  #pragma omp dispatch
  b_cuda (0);

  #pragma omp dispatch
  b_hip (0);

  #pragma omp dispatch
  b_hsa (0);
}
```

To reiterate, this is already fixed and I will post the patch later
this week.
  • [Bug c++/119602] New: [OpenMP] ... waffl3x at protonmail dot com via Gcc-bugs

Reply via email to