[cfe-dev] __builtin_shufflevector vs. llvm shufflevector

Florian Pflug fgp at phlo.org
Wed Feb 8 17:35:37 PST 2012

On Feb8, 2012, at 21:08 , Eli Friedman wrote:
> On Wed, Feb 8, 2012 at 7:35 AM, Florian Pflug <fgp at phlo.org> wrote:
>> 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)?
> I'm pretty sure this is just an accident... I wasn't really thinking
> about undef shuffle indexes when I wrote the code in SemaChecking.cpp.

I tried relaxing the check during sema checking to allow -1, and fixed
codegen to consistently translate index value -1 to undef. And voila,
it works. __builtin_shufflevector(v, v, 1, -1) is now translated to

  shufflevector <2 x i8> %v, <2 x i8> undef, <2 x i32> <i32 1, i32 undef>

Patch is attached.

The patch also changes the error message for out-of-range index values
to be more specific about the allowed range (-1 to 2*N), changes the
diag code from err_shufflevector_argument_too_large to 
err_shufflevector_argument_out_of_range since the former seemed strange
for signed values, and finally verifies that the indices fit into 32-bit
signed integers. The previous check for getActiveBits() <= 64 seemed
overly lax, since the indices are later treated as 32-bit quantities,
by both clang and llvm.

best regards,
Florian Pflug
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang.shufflevector.undef.v1.patch
Type: application/octet-stream
Size: 2594 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120209/0f3275c7/attachment.obj>

More information about the cfe-dev mailing list