[Bug c++/67558] New: [C++] OpenMP "if" clause does not utilize compile-time constants

bisqwit at iki dot fi gcc-bugzilla@gcc.gnu.org
Sat Sep 12 13:59:00 GMT 2015


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

            Bug ID: 67558
           Summary: [C++] OpenMP "if" clause does not utilize compile-time
                    constants
           Product: gcc
           Version: 5.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bisqwit at iki dot fi
  Target Milestone: ---

Consider this example code.

    unsigned x;

    template<bool Threads>
    void plain_if(unsigned y)
    {
        if(Threads)
        {
            #pragma omp task firstprivate(y) shared(x)
            x = y >> 1;
        }
        else
        {
            x = y >> 1;
        }
    }

    template<bool Threads>
    void omp_if(unsigned y)
    {
        #pragma omp task if(Threads) firstprivate(y) shared(x)
        x = y >> 1;
    }

    void plain_if_false(unsigned y) { plain_if<false>(y); }
    void plain_if_true(unsigned y) { plain_if<true>(y); }

    void omp_if_false(unsigned y) { omp_if<false>(y); }
    void omp_if_true(unsigned y) { omp_if<true>(y); }

plain_if and omp_if do essentially the same thing. In both of them, the
template parameter "Threads" controls whether to create an OpenMP task for the
action or not.

However, when the code is compiled, all functions explicitly call GOMP_task,
except plain_if<false>.
It is clear that GCC treats a plain if() differently than an OpenMP if(). It is
a case of lacking optimization.



More information about the Gcc-bugs mailing list