GCC modified for the FreeChainXenon project
Find a file
Juzhe-Zhong f2afe68a17 RISC-V: Support TARGET_VECTORIZE_PREFERRED_VECTOR_ALIGNMENT to optimize codegen of both VLA && VLS auto-vectorization
This patch optimizes both RVV VLA && VLS vectorization.

Consider this following case:
void __attribute__((noinline, noclone))
f (int * __restrict dst, int * __restrict op1, int * __restrict op2, int
count)
{
  for (int i = 0; i < count; ++i)
    dst[i] = op1[i] + op2[i];
}

VLA:
Before this patch:
        ble	a3,zero,.L1
        srli	a4,a1,2
        negw	a4,a4
        andi	a5,a4,3
        sext.w	a3,a3
        beq	a5,zero,.L3
        lw	a7,0(a1)
        lw	a6,0(a2)
        andi	a4,a4,2
        addw	a6,a6,a7
        sw	a6,0(a0)
        beq	a4,zero,.L3
        lw	a7,4(a1)
        lw	a4,4(a2)
        li	a6,3
        addw	a4,a4,a7
        sw	a4,4(a0)
        bne	a5,a6,.L3
        lw	a6,8(a2)
        lw	a4,8(a1)
        addw	a4,a4,a6
        sw	a4,8(a0)
.L3:
        subw	a3,a3,a5
        slli	a4,a3,32
        csrr	a6,vlenb
        srli	a4,a4,32
        srli	a6,a6,2
        slli	a3,a5,2
        mv	a5,a4
        bgtu	a4,a6,.L17
.L5:
        csrr	a6,vlenb
        add	a1,a1,a3
        add	a2,a2,a3
        add	a0,a0,a3
        srli	a7,a6,2
        li	a3,0
.L8:
        vsetvli	zero,a5,e32,m1,ta,ma
        vle32.v	v1,0(a1)
        vle32.v	v2,0(a2)
        vsetvli	t1,zero,e32,m1,ta,ma
        add	a3,a3,a7
        vadd.vv	v1,v1,v2
        vsetvli	zero,a5,e32,m1,ta,ma
        vse32.v	v1,0(a0)
        mv	a5,a4
        bleu	a4,a3,.L6
        mv	a5,a3
.L6:
        sub	a5,a4,a5
        bleu	a5,a7,.L7
        mv	a5,a7
.L7:
        add	a1,a1,a6
        add	a2,a2,a6
        add	a0,a0,a6
        bne	a5,zero,.L8
.L1:
        ret
.L17:
        mv	a5,a6
        j	.L5

After this patch:
f:
        ble     a3,zero,.L1
        csrr    a4,vlenb
        srli    a4,a4,2
        mv      a5,a3
        bgtu    a3,a4,.L9
.L3:
        csrr    a6,vlenb
        li      a4,0
        srli    a7,a6,2
.L6:
        vsetvli zero,a5,e32,m1,ta,ma
        vle32.v v2,0(a1)
        vle32.v v1,0(a2)
        vsetvli t1,zero,e32,m1,ta,ma
        add     a4,a4,a7
        vadd.vv v1,v1,v2
        vsetvli zero,a5,e32,m1,ta,ma
        vse32.v v1,0(a0)
        mv      a5,a3
        bleu    a3,a4,.L4
        mv      a5,a4
.L4:
        sub     a5,a3,a5
        bleu    a5,a7,.L5
        mv      a5,a7
.L5:
        add     a0,a0,a6
        add     a2,a2,a6
        add     a1,a1,a6
        bne     a5,zero,.L6
.L1:
        ret
.L9:
        mv      a5,a4
        j       .L3

VLS:
Before this patch:
f3:
        ble	a3,zero,.L1
        srli	a5,a1,2
        negw	a5,a5
        andi	a4,a5,3
        sext.w	a3,a3
        beq	a4,zero,.L3
        lw	a7,0(a1)
        lw	a6,0(a2)
        andi	a5,a5,2
        addw	a6,a6,a7
        sw	a6,0(a0)
        beq	a5,zero,.L3
        lw	a7,4(a1)
        lw	a5,4(a2)
        li	a6,3
        addw	a5,a5,a7
        sw	a5,4(a0)
        bne	a4,a6,.L3
        lw	a6,8(a2)
        lw	a5,8(a1)
        addw	a5,a5,a6
        sw	a5,8(a0)
.L3:
        subw	a3,a3,a4
        slli	a6,a4,2
        slli	a5,a3,32
        srli	a5,a5,32
        add	a1,a1,a6
        add	a2,a2,a6
        add	a0,a0,a6
        li	a3,4
.L6:
        mv	a4,a5
        bleu	a5,a3,.L5
        li	a4,4
.L5:
        vsetvli	zero,a4,e32,m1,ta,ma
        vle32.v	v1,0(a1)
        vle32.v	v2,0(a2)
        vsetivli	zero,4,e32,m1,ta,ma
        sub	a5,a5,a4
        vadd.vv	v1,v1,v2
        vsetvli	zero,a4,e32,m1,ta,ma
        vse32.v	v1,0(a0)
        addi	a1,a1,16
        addi	a2,a2,16
        addi	a0,a0,16
        bne	a5,zero,.L6
.L1:
        ret

After this patch:
f3:
        ble	a3,zero,.L1
        li	a4,4
.L4:
        mv	a5,a3
        bleu	a3,a4,.L3
        li	a5,4
.L3:
        vsetvli	zero,a5,e32,m1,ta,ma
        vle32.v	v2,0(a1)
        vle32.v	v1,0(a2)
        vsetivli	zero,4,e32,m1,ta,ma
        sub	a3,a3,a5
        vadd.vv	v1,v1,v2
        vsetvli	zero,a5,e32,m1,ta,ma
        vse32.v	v1,0(a0)
        addi	a2,a2,16
        addi	a0,a0,16
        addi	a1,a1,16
        bne	a3,zero,.L4
.L1:
        ret

Signed-off-by: Juzhe-Zhong <juzhe.zhong@rivai.ai>

gcc/ChangeLog:

	* config/riscv/riscv.cc
	(riscv_vectorize_preferred_vector_alignment): New function.
	(TARGET_VECTORIZE_PREFERRED_VECTOR_ALIGNMENT): New target hook.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/autovec/binop/shift-rv32gcv.c: Adapt testcase.
	* gcc.target/riscv/rvv/autovec/align-1.c: New test.
	* gcc.target/riscv/rvv/autovec/align-2.c: New test.
2023-05-15 14:06:46 +08:00
c++tools Daily bump. 2023-04-01 00:17:38 +00:00
config Daily bump. 2022-11-15 08:32:29 +00:00
contrib Daily bump. 2023-04-29 00:16:48 +00:00
fixincludes Daily bump. 2023-03-29 00:17:01 +00:00
gcc RISC-V: Support TARGET_VECTORIZE_PREFERRED_VECTOR_ALIGNMENT to optimize codegen of both VLA && VLS auto-vectorization 2023-05-15 14:06:46 +08:00
gnattools Daily bump. 2023-04-26 00:17:46 +00:00
gotools Daily bump. 2022-08-31 00:16:45 +00:00
include Daily bump. 2023-05-12 00:18:12 +00:00
INSTALL
intl Daily bump. 2022-11-24 00:17:47 +00:00
libada Update copyright years. 2023-01-16 11:52:17 +01:00
libatomic Daily bump. 2023-03-25 00:16:51 +00:00
libbacktrace Daily bump. 2023-03-29 00:17:01 +00:00
libcc1 Update copyright years. 2023-01-16 11:52:17 +01:00
libcody Update Copyright year in ChangeLog files 2023-01-02 09:23:36 +01:00
libcpp Daily bump. 2023-05-10 00:17:49 +00:00
libdecnumber Update copyright years. 2023-01-16 11:52:17 +01:00
libffi Daily bump. 2023-05-07 00:16:40 +00:00
libgcc Daily bump. 2023-05-03 00:17:11 +00:00
libgfortran Daily bump. 2023-05-13 00:17:14 +00:00
libgm2 Daily bump. 2023-05-14 00:16:39 +00:00
libgo syscall: add prlimit 2023-05-11 09:17:48 -07:00
libgomp Daily bump. 2023-05-13 00:17:14 +00:00
libiberty Daily bump. 2023-04-03 00:16:43 +00:00
libitm Update copyright years. 2023-01-16 11:52:17 +01:00
libobjc Update copyright years. 2023-01-16 11:52:17 +01:00
libphobos Daily bump. 2023-03-18 00:16:40 +00:00
libquadmath Daily bump. 2023-03-03 00:16:38 +00:00
libsanitizer Daily bump. 2023-05-01 00:16:44 +00:00
libssp Update copyright years. 2023-01-16 11:52:17 +01:00
libstdc++-v3 Daily bump. 2023-05-13 00:17:14 +00:00
libvtv Update copyright years. 2023-01-16 11:52:17 +01:00
lto-plugin Daily bump. 2023-05-12 00:18:12 +00:00
maintainer-scripts Daily bump. 2023-04-21 00:17:31 +00:00
zlib Daily bump. 2022-11-24 00:17:47 +00:00
.dir-locals.el dir-locals: Use https for bug references 2021-07-20 11:40:34 +01:00
.gitattributes
.gitignore .gitignore: do not ignore config.h 2022-07-19 17:07:04 +03:00
ABOUT-NLS
ar-lib
ChangeLog Daily bump. 2023-05-12 00:18:12 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in
config.guess
config.rpath
config.sub config.sub: change mode to 755. 2021-12-21 09:10:57 +01:00
configure configure: Only create serdep.tmp if needed 2023-04-21 13:16:08 -06:00
configure.ac configure: Only create serdep.tmp if needed 2023-04-21 13:16:08 -06:00
COPYING
COPYING.LIB
COPYING.RUNTIME
COPYING3
COPYING3.LIB
depcomp
install-sh
libtool-ldflags
libtool.m4 Generic configury support for shared libs on VxWorks 2022-10-11 07:31:07 +00:00
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
MAINTAINERS MAINTAINERS: Fix alphabetic sorting. 2023-05-11 14:30:22 +02:00
Makefile.def configure: Do not build the ununsed libffi shared library. 2022-12-31 17:51:47 +00:00
Makefile.in Fix autoprofiledbootstrap build 2023-04-28 13:15:33 -07:00
Makefile.tpl Fix autoprofiledbootstrap build 2023-04-28 13:15:33 -07:00
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
README
symlink-tree
test-driver
ylwrap

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.