How to get MIN_EXPR without using deprecated min operator

Andrew Pinski pinskia@physics.uc.edu
Fri May 6 14:25:00 GMT 2005


On May 6, 2005, at 9:27 AM, chris jefferson wrote:

> Michael Cieslinski wrote:
>
>> 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] = std::min(SrcP[x], MinP[x]);
>>    }
>>
>>
>> If I compile it with
>>    gcc41 -O2 -ftree-vectorize -ftree-vectorizer-verbose=5
>> function Tst1 gets vectorized but Tst2 not.
>>
>> The reason for this is <? results in a MIN_EXPR while std::min 
>> generates a
>> conditional code.
>> My question is, how can I get a MIN_EXPR without using the deprecated 
>> min <?
>> operator?

The problem with C++ is in fold as we now have to disable the 
optimization
which converted "a >= b ? b : a" to MIN_EXPR.
Try the following instead:
MinP[x] = (SrcP[x]<MinP[x]) ? (short)SrcP[x] : MinP[x];

which forces this to be an rvalue instead of the normal lvalue which 
should
allow fold to convert this to MIN_EXPR

-- Pinski



More information about the Gcc mailing list