https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110897

--- Comment #2 from JuzheZhong <juzhe.zhong at rivai dot ai> ---
Yes, (In reply to Andrew Pinski from comment #1)
> Does the riscv backend support uint32_t shifting? How about extending and
> contracting to/from uint16_t to uint32_t?

Yes, RISC-V port support uint32_t shifting.

Try this code (I explictly add conversion ((uint32_t) a[i]) >> b[i]):


#include <stdint-gcc.h>

#define TEST2_TYPE(TYPE)                                        \
  __attribute__((noipa))                                        \
  void vshiftr_##TYPE (TYPE *dst, TYPE *a, TYPE *b, int n)      \
  {                                                             \
    for (int i = 0; i < n; i++)                                 \
      dst[i] = ((uint32_t) a[i]) >> b[i];                                      
\
  }

#define TEST_ALL()      \
 TEST2_TYPE(uint16_t)   \

TEST_ALL()

.L4:
        vsetvli a5,a3,e8,mf4,ta,ma
        vle16.v v3,0(a1)
        vle16.v v2,0(a2)
        vsetivli        zero,4,e32,m1,ta,ma
        vzext.vf2       v1,v3
        vsetvli zero,zero,e16,mf2,ta,ma
        slli    a4,a5,1
        vnsrl.wv        v1,v1,v2
        sub     a3,a3,a5
        vsetvli zero,a5,e16,mf2,ta,ma
        vse16.v v1,0(a0)
        add     a1,a1,a4
        add     a2,a2,a4
        add     a0,a0,a4
        bne     a3,zero,.L4
        ret

It vectorize it successfully.
But I think compiler recognize it since LLVM can do the job:
https://godbolt.org/z/ecKjYco5b

LLVM doesn't need the explicit conversion codes still can vectorize it.

Reply via email to