[cfe-dev] Sub-vector selection and CLang v5.0

ORiordan, Martin via cfe-dev cfe-dev at lists.llvm.org
Sat Feb 17 03:27:46 PST 2018


Thanks for the explanation Eli.

In this case the source language is C using the vector extensions - I chose 'char16' because it is familiar, but it could have been the ARM Neon form:

typedef char int8x16_t __attribute__((ext_vector_type(16)));

int8x16_t v0, v1;
...
v1.s0123456 = v0.s0123456; // Replace the 1st 7-elements of 'v1' with the 1st 7-elements of 'v0'

However, though OpenCL has a hard semantic requirement for swizzle vector lengths, there is no corresponding restriction on extensions for other languages that do not formally specify such a semantic constraint.

In the machine vision [MV] space we use a lot of vectors that are 3, 5, 7, 11 and 13 elements in length (NxN matrices heavily used in convolutions).

LLVM itself has no difficulty handling swizzles with arbitrary sub-vector lengths, so I would like to suggest that this test is only enabled if the source language is OpenCL.  Our Myriad:SHAVE target implementation also has very carefully optimised code generation for these odd-element length swizzles because algorithms using them are so common in the MV space.

Replace:
if (IsValidOpenCLComponentSwizzleLength(SwizzleLength) == false) {
with:
if (S.getLangOpts().OpenCL && IsValidOpenCLComponentSwizzleLength(SwizzleLength) == false) {

The rest of the 'Sema' checking and the LLVR-IR produced are valid for arbitrary sub-vector lengths.

Thanks,

            MartinO

From: Friedman, Eli [mailto:efriedma at codeaurora.org]
Sent: Friday, February 16, 2018 9:36 PM
To: ORiordan, Martin <martin.oriordan at intel.com>; Clang Dev <cfe-dev at lists.llvm.org>
Subject: Re: [cfe-dev] Sub-vector selection and CLang v5.0

On 2/16/2018 1:11 AM, ORiordan, Martin via cfe-dev wrote:
Hi CFE-Devs,

I received a bug report for a breaking change between CLang v4.0 and v5.0 regarding sub-vectors that has been caused by:

http://llvm.org/viewvc/llvm-project?view=revision&revision=298369

The example is as follows:

  char16 v0, v1;
  ...
  v1.s0123456 = v0.s0123456; // Replace the 1st 7-elements of 'v1' with the 1st 7-elements of 'v0'

which used to generate valid code, but which is now diagnosed with the following error:

  error: vector component access has invalid length 7. Supported: 1,2,3,4,8,16.

However, I don't see why it should not be possible to replace any range of elements of a vector with a corresponding set of elements.

Vector swizzles are defined in the OpenCL standard, and https://www.khronos.org/registry/OpenCL/specs/opencl-2.2-cplusplus.html#builtin-vector-data-types says "vector-swizzle-selector shall have swizzle size of 1, 2, 3, 4, 8 or 16."

-Eli



--

Employee of Qualcomm Innovation Center, Inc.

Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
--------------------------------------------------------------
Intel Research and Development Ireland Limited
Registered in Ireland
Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
Registered Number: 308263


This e-mail and any attachments may contain confidential material for the sole
use of the intended recipient(s). Any review or distribution by others is
strictly prohibited. If you are not the intended recipient, please contact the
sender and delete all copies.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180217/c7a509b1/attachment.html>


More information about the cfe-dev mailing list