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



             Bug #: 54700

           Summary: Optimize away x<0 as mask argument of a blend.

    Classification: Unclassified

           Product: gcc

           Version: 4.8.0

            Status: UNCONFIRMED

          Severity: normal

          Priority: P3

         Component: target

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: gli...@gcc.gnu.org

            Target: x86_64-linux-gnu





Hello,



blend instructions (vpblendvb, vblendvpd) only look at the high bit of the

elements of their mask. The mask may come from an operation, like v<0, which is

actually the identity on the high bits (for floats that may require

-fno-signed-zeros). In those cases, it would be nice to remove the useless

comparison.



Since the vectorizer is the only current producer of vec_cond_expr, here is an

example (compiled with -Ofast -mavx2):

#if 0

typedef double T;

#else

typedef signed char T;

#endif

void f(T* p){

  for(int i=0;i<10000000;++i){

    p[i]=(p[i]<0)?2:1;

  }

}



(I haven't checked if there is a penalty for using a register last used for

floating point as mask)



Also, if vcond is passed constants to compare (say {-5,7}<{0,0}), it doesn't

get constant folded. I couldn't get the vectorizer to generate this (missed

optimization, using i%2 shouldn't prevent from vectorizing), so I don't have a

testcase for that one.

Reply via email to