[llvm-bugs] [Bug 44607] New: Relax ARM NEON literal rules

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jan 21 05:41:24 PST 2020


https://bugs.llvm.org/show_bug.cgi?id=44607

            Bug ID: 44607
           Summary: Relax ARM NEON literal rules
           Product: clang
           Version: 9.0
          Hardware: Other
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C
          Assignee: unassignedclangbugs at nondot.org
          Reporter: husseydevin at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Currently, the NEON "constant" restrictions are too strict compared to SSE2 and
GCC.

#include <arm_neon.h>

static inline uint32x4_t shift(uint32x4_t inp, const int amt)
{
    return vshlq_n_u32(inp, amt);
}

int main()                                                                    {
    uint32x4_t val = vdupq_n_u32(2384);
    uint32x4_t shifted = shift(val, 3);
}

`shift` should be constant propagated, and Clang should accept this code.

GCC accepts this code, and Clang also accepts the SSE2 equivalent:

#include <emmintrin.h>

static inline __m128i shift(__m128i val, int amt)
{
    return _mm_slli_epi32(val, amt);
}

int main()
{
    __m128i val = _mm_set1_epi32(2384);
    __m128i shifted = shift(val, 3);
}

However, I get this with Clang 9.0.1 on Termux aarch64:

neon.cpp:7:12: error: argument to '__builtin_neon_vshlq_n_v' must be a
      constant integer
    return vshlq_n_u32(inp, amt);
           ^                ~~~
/data/data/com.termux/files/usr/lib/clang/9.0.1/include/arm_neon.h:24327:24:
note:
      expanded from macro 'vshlq_n_u32'
  __ret = (uint32x4_t) __builtin_neon_vshlq_n_v((int8x16_t)__s0, __p1, 50); \
                       ^                                         ~~~~
1 error generated.


In addition, GCC also converts some things to the non-literal forms. If I
remove the static inline part, I get the following assembly:

shift:
        dup     v1.4s, w0
        sshl    v0.4s, v0.4s, v1.4s
        ret

This strict literal requirement makes things difficult for things like C++
wrappers, and the requirements should be relaxed like GCC and SSE2.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200121/a6fb54cb/attachment.html>


More information about the llvm-bugs mailing list