Consider the following short program:

#include <algorithm>

void Tst1(short* __restrict__ SrcP, short* __restrict__ MinP, int Len)
{
    for (int x=0; x<Len; x++)
        MinP[x] = SrcP[x] <? MinP[x];
}

void Tst2(short* __restrict__ SrcP, short* __restrict__ MinP, int Len)
{
    for (int x=0; x<Len; x++)
        MinP[x] = (SrcP[x]<MinP[x]) ? SrcP[x] : MinP[x];
}

void Tst3(short* __restrict__ SrcP, short* __restrict__ MinP, int Len)
{
    for (int x=0; x<Len; x++)
        MinP[x] = (SrcP[x]<MinP[x]) ? (short)SrcP[x] : MinP[x];
}

void Tst4(short* __restrict__ SrcP, short* __restrict__ MinP, int Len)
{
    for (int x=0; x<Len; x++)
        MinP[x] = std::min(SrcP[x], MinP[x]);
}

void Tst5(short* __restrict__ SrcP, short* __restrict__ MinP, int Len)
{
    for (int x=0; x<Len; x++)
        if (SrcP[x]<MinP[x])  MinP[x]=SrcP[x];
}

If I compile it with
    gcc41 -O2 -ftree-vectorize -ftree-vectorizer-verbose=5
function Tst1/Tst2/Tst3 gets vectorized but Tst4/Tst5 not.

The reason for this is the first three funtions result in a MIN_EXPR while 
std::min and the if statement generate conditional code which the vectorizer 
does not recognize.


Michael Cieslinski

-- 
           Summary: if statement not converted to MIN_EXPR
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: micis at gmx dot de
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21462

Reply via email to