[cfe-dev] __builtin_shufflevector vs. llvm shufflevector

Florian Pflug fgp at phlo.org
Wed Feb 8 07:35:04 PST 2012


Hi

>From the llvm documentation I gather that llvm's shufflevector allows indices to be set to <undef> and interprets that as "don't care". From the initial discussion on clang's __builtin_shufflevector (http://lists.cs.uiuc.edu/pipermail/cfe-dev/2008-February/001151.html) it sounds as if the plan was to make "-1" translate to llvm's <undef>. This code fragment from clang's lib/CodeGen/CGExprScalar.cpp supports that theory

  static llvm::Constant *getMaskElt(llvm::ShuffleVectorInst *SVI, unsigned Idx,
                                    unsigned Off, llvm::Type *I32Ty) {
    int MV = SVI->getMaskValue(Idx);
    if (MV == -1) 
      return llvm::UndefValue::get(I32Ty);
    return llvm::ConstantInt::get(I32Ty, Off+MV);
  }

clang 3.0, however, responds to

  typedef signed char v2s8_t __attribute__ ((__ext_vector_type__ (2)));
  v2s8_t v = (v2s8_t){(signed char)1, (signed char)2};
  v = __builtin_shufflevector(v, v, 1, -1);

with

  error: index for __builtin_shufflevector must be less than the total number of vector elements

Does that mean that the initial plan was abolished and masks with undef element aren't supported in clang, or is this simply a signed vs. unsigned bug in Sema::SemaBuiltinShuffleVector (as the phrasing of the error message makes me suspect)?

Also, are there plans to add support for zeroed elements to llvm's shufflevector? At least SSE's pshufb instruction supports that, but currently the only way to access that functionality is via __builtin__pshufb().

best regards,
Florian Pflug

PS: Sorry if this is the wrong list to asks this question. I'd have posted on cfe-users, but such a thing does not seem to exist.





More information about the cfe-dev mailing list