mbox series

[v5,0/6] Add Loongson SX/ASX instruction support to LoongArch target.

Message ID 20230824031316.16599-1-panchenghui@loongson.cn
Headers show
Series Add Loongson SX/ASX instruction support to LoongArch target. | expand

Message

Chenghui Pan Aug. 24, 2023, 3:13 a.m. UTC
This is an update of:
https://gcc.gnu.org/pipermail/gcc-patches/2023-August/627413.html

Changes since last version of patch set:
- Fix regression test fail of pr54346.c with RUNTESTFLAGS="--target_board=unix/-mlsx".
  This is caused by the code simplification of loongarch_expand_vec_perm_const_2 () in
  last version.
- Combine vilvh/xvilvh insn's RTL template impl.
- Add dg-skip-if for loongarch*-*-* in vshuf test in g++.dg/torture, because
  vshuf/xvshuf insn's result is undefined when 6 or 7 bit of vector's element is set,
  and insns with this condition are generated in these testcases.

Brief version history of patch set:

v1 -> v2:
- Reduce usage of "unspec" in RTL template.
- Append Support of ADDR_REG_REG in LSX and LASX.
- Constraint docs are appended in gcc/doc/md.texi and ccomment block.
- Codes related to vecarg are removed.
- Testsuite of LSX and LASX is added in v2. (Because of the size limitation of
  mail list, these patches are not shown)
- Adjust the loongarch_expand_vector_init() function to reduce instruction 
  output amount.
- Some minor implementation changes of RTL templates.

v2 -> v3:
- Revert vabsd/xvabsd RTL templates to unspec impl.
- Resolve warning in gcc/config/loongarch/loongarch.cc when bootstrapping 
  with BOOT_CFLAGS="-O2 -ftree-vectorize -fno-vect-cost-model -mlasx".
- Remove redundant definitions in lasxintrin.h.
- Refine commit info.

v3 -> v4:
- Code simplification.
- Testsuite patches are splited from this patch set again and will be submitted 
independently in the future.

Lulu Cheng (6):
  LoongArch: Add Loongson SX vector directive compilation framework.
  LoongArch: Add Loongson SX base instruction support.
  LoongArch: Add Loongson SX directive builtin function support.
  LoongArch: Add Loongson ASX vector directive compilation framework.
  LoongArch: Add Loongson ASX base instruction support.
  LoongArch: Add Loongson ASX directive builtin function support.

 gcc/config.gcc                                |    2 +-
 gcc/config/loongarch/constraints.md           |  131 +-
 .../loongarch/genopts/loongarch-strings       |    4 +
 gcc/config/loongarch/genopts/loongarch.opt.in |   12 +-
 gcc/config/loongarch/lasx.md                  | 5104 ++++++++++++++++
 gcc/config/loongarch/lasxintrin.h             | 5338 +++++++++++++++++
 gcc/config/loongarch/loongarch-builtins.cc    | 2686 ++++++++-
 gcc/config/loongarch/loongarch-c.cc           |   18 +
 gcc/config/loongarch/loongarch-def.c          |    6 +
 gcc/config/loongarch/loongarch-def.h          |    9 +-
 gcc/config/loongarch/loongarch-driver.cc      |   10 +
 gcc/config/loongarch/loongarch-driver.h       |    2 +
 gcc/config/loongarch/loongarch-ftypes.def     |  666 +-
 gcc/config/loongarch/loongarch-modes.def      |   39 +
 gcc/config/loongarch/loongarch-opts.cc        |   89 +-
 gcc/config/loongarch/loongarch-opts.h         |    3 +
 gcc/config/loongarch/loongarch-protos.h       |   35 +
 gcc/config/loongarch/loongarch-str.h          |    3 +
 gcc/config/loongarch/loongarch.cc             | 4660 +++++++++++++-
 gcc/config/loongarch/loongarch.h              |  117 +-
 gcc/config/loongarch/loongarch.md             |   56 +-
 gcc/config/loongarch/loongarch.opt            |   12 +-
 gcc/config/loongarch/lsx.md                   | 4467 ++++++++++++++
 gcc/config/loongarch/lsxintrin.h              | 5181 ++++++++++++++++
 gcc/config/loongarch/predicates.md            |  333 +-
 gcc/doc/md.texi                               |   11 +
 gcc/testsuite/g++.dg/torture/vshuf-v16hi.C    |    1 +
 gcc/testsuite/g++.dg/torture/vshuf-v16qi.C    |    1 +
 gcc/testsuite/g++.dg/torture/vshuf-v2df.C     |    2 +
 gcc/testsuite/g++.dg/torture/vshuf-v2di.C     |    1 +
 gcc/testsuite/g++.dg/torture/vshuf-v4sf.C     |    2 +-
 gcc/testsuite/g++.dg/torture/vshuf-v8hi.C     |    1 +
 32 files changed, 28717 insertions(+), 285 deletions(-)
 create mode 100644 gcc/config/loongarch/lasx.md
 create mode 100644 gcc/config/loongarch/lasxintrin.h
 create mode 100644 gcc/config/loongarch/lsx.md
 create mode 100644 gcc/config/loongarch/lsxintrin.h

Comments

Xi Ruoyao Aug. 24, 2023, 3:40 a.m. UTC | #1
On Thu, 2023-08-24 at 11:13 +0800, Chenghui Pan wrote:
> - Add dg-skip-if for loongarch*-*-* in vshuf test in g++.dg/torture, because
>   vshuf/xvshuf insn's result is undefined when 6 or 7 bit of vector's element is set,
>   and insns with this condition are generated in these testcases.

I'm almost sure this is wrong.  You need to fix the code generation so
__builtin_shuffle will always generate something defined on LoongArch,
instead of covering up the issue.
Xi Ruoyao Aug. 24, 2023, 3:49 a.m. UTC | #2
On Thu, 2023-08-24 at 11:40 +0800, Xi Ruoyao via Gcc-patches wrote:
> On Thu, 2023-08-24 at 11:13 +0800, Chenghui Pan wrote:
> > - Add dg-skip-if for loongarch*-*-* in vshuf test in g++.dg/torture, because
> >   vshuf/xvshuf insn's result is undefined when 6 or 7 bit of vector's element is set,
> >   and insns with this condition are generated in these testcases.
> 
> I'm almost sure this is wrong.  You need to fix the code generation so
> __builtin_shuffle will always generate something defined on LoongArch,
> instead of covering up the issue.

https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html says clearly:

   The elements of the input vectors are numbered in memory ordering of
   vec0 beginning at 0 and vec1 beginning at N. The elements of mask are
   considered modulo N in the single-operand case and modulo 2*N in the
   two-operand case.
   
So there is no undefined thing allowed here.  You must implement it as it's
documented.