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



             Bug #: 56790

           Summary: VEC_COND_EXPR not constant folded

    Classification: Unclassified

           Product: gcc

           Version: 4.8.0

            Status: UNCONFIRMED

          Keywords: missed-optimization

          Severity: enhancement

          Priority: P3

         Component: tree-optimization

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

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

            Target: x86_64-linux-gnu





#include <x86intrin.h>

__m128d f(){

  __m128d a={5,7};

  __m128d b={11,13};

  __m128i m={-1,0};

  return m?a:b;

}



With -msse3 or less, this is lowered to scalar operations and thus to a

constant. However, with -msse4 or higher, nothing folds it to a constant,

either at tree level or rtl level, and we end up with:



    pxor    %xmm0, %xmm0

    pcmpgtq    .LC0(%rip), %xmm0

    movapd    .LC2(%rip), %xmm1

    blendvpd    %xmm0, .LC1(%rip), %xmm1

    movapd    %xmm1, %xmm0



The most natural seems to be to add something to fold-const.c, which currently

only handles the case where the first argument is all 1s or all 0s. It would be

good if the optimization worked when the second and third arguments can be

either VECTOR_CST or CONSTRUCTOR, similarly to VEC_PERM_EXPR.

Reply via email to