TEST repository for https://forge.sourceware.org/ experimenting.
  • C++ 30.7%
  • C 30.2%
  • Ada 14.4%
  • D 6.1%
  • Go 5.7%
  • Other 12.4%
Find a file
Tamar Christina cd13223e77 AArch64: Don't enable ptest elimination for partial vectors [PR124162]
The following loop

char b = 41;
int main() {
  signed char a[31];
#pragma GCC novector
  for (int c = 0; c < 31; ++c)
    a[c] = c * c + c % 5;
  {
    signed char *d = a;
#pragma GCC novector
    for (int c = 0; c < 31; ++c, b += -16)
      d[c] += b;
  }
  for (int c = 0; c < 31; ++c) {
    signed char e = c * c + c % 5 + 41 + c * -16;
    if (a[c] != e)
      __builtin_abort();
  }
}

compiled with -O2 -ftree-vectorize -msve-vector-bits=256 -march=armv8.2-a+sve

generates

        ptrue   p6.b, vl32
        add     x2, x2, :lo12:.LC0
        add     w5, w5, 16
        ld1rw   z25.s, p6/z, [x2]
        strb    w5, [x6, #:lo12:.LANCHOR0]
        mov     w0, 0
        mov     p7.b, p6.b
        mov     w2, 31
        index   z30.s, #0, #1
        mov     z26.s, #5
        mov     z27.b, #41
.L6:
        mov     z29.d, z30.d
        movprfx z28, z30
        add     z28.b, z28.b, #240
        mad     z29.b, p6/m, z28.b, z27.b
        mov     w3, w0
        movprfx z31, z30
        smulh   z31.s, p6/m, z31.s, z25.s
        add     w0, w0, 8
        asr     z31.s, z31.s, #1
        msb     z31.s, p6/m, z26.s, z30.s
        add     z31.b, z31.b, z29.b
        ld1b    z29.s, p7/z, [x1]
        cmpne   p7.b, p7/z, z31.b, z29.b
        b.any   .L15
        add     x1, x1, 8
        add     z30.s, z30.s, #8
        whilelo p7.s, w0, w2
        b.any   .L6

Which uses a predicate for the first iteration where all bits are 1. i.e. all
lanes active. This causes the result of the cmpne to set the wrong CC flags.
The second iteration uses

        whilelo p7.s, w0, w2

which gives the correct mask layout going forward.

This is due to the CSE'ing code that tries to share predicates as much as
possible.  In aarch64_expand_mov_immediate we do during predicate generation

	  /* Only the low bit of each .H, .S and .D element is defined,
	     so we can set the upper bits to whatever we like.  If the
	     predicate is all-true in MODE, prefer to set all the undefined
	     bits as well, so that we can share a single .B predicate for
	     all modes.  */
	  if (imm == CONSTM1_RTX (mode))
	    imm = CONSTM1_RTX (VNx16BImode);

which essentially maps all predicates to .b unless the predicate is created
outside the immediate expansion code.

It creates the sparse predicate for data lane VNx4QI from a VNx16QI and then
has a "conversion" operation. The conversion operation results in a simple copy:

        mov     p7.b, p6.b

because in the data model for partial vectors the upper lanes are *don't care*.
So computations using this vector are fine.  However for comparisons, or any
operations setting flags the predicate value does matter otherwise we get the
wrong flags as the above.

Additionally we don't have a way to distinguish based on the predicate alone
whether the operation is partial or not. i.e. we have no "partial predicate"
modes.

two ways to solve this:

1. restore the ptest for partial vector compares.  This would slow down the loop
   though and introduce a second ptrue .s, VL8 predicate.

2. disable the sharing of partial vector predicates.  This allows us to remove
   the ptest.  Since the ptest would introduce a second predicate here anyway
   I'm leaning towards disabling sharing between partial and full predicates.

For the patch I ended up going with 1.  The reason is that this is that
unsharing the predicate does end up being pessimistic loops that only operate on
full vectors only (which are the majority of the cases).

I also don't fully understand all the places we depend on this sharing (and
about 3600 ACLE tests fail assembler scans).  I suspect one way to possibly
deal with this is to perform the sharing on GIMPLE using the new isel hook and
make RTL constant expansion not manually force it.  Since in gimple it's easy to
follow compares from a back-edge to figure out if it's safe to share the
predicate.

I also tried changing it so that during cond_vec_cbranch_any we perform an AND
with the proper partial predicate.  But unfortunately folding doesn't realize

that the and on the latch edge is useless (e.g.  whilelo p7.s, w0, w2 makes it
a no-op) and that the AND should be moved outside the loop.  This is something
that again isel should be able to do.

I also tried changing the

        mov     p7.b, p6.b

into an AND, while this worked, folding didn't quite get that the and can be
eliminated.  And this also pessimists actual register copies.

So for now I just undo ptest elimination for partial vectors for GCC 16 and will
revisit it for GCC 17 when we extend ptest elimination.

gcc/ChangeLog:

	PR target/124162
	* config/aarch64/aarch64-sve.md (cond_vec_cbranch_any,
	cond_vec_cbranch_all): Drop partial vectors support.

gcc/testsuite/ChangeLog:

	PR target/124162
	* gcc.target/aarch64/sve/vect-early-break-cbranch_16.c: New test.
2026-02-27 07:41:20 +00:00
.forgejo Containerfile for base forge actions 2026-01-08 07:31:40 -05:00
.github
c++tools Update copyright years. 2026-01-02 09:56:11 +01:00
config Daily bump. 2026-02-05 00:16:28 +00:00
contrib Daily bump. 2026-02-25 00:16:33 +00:00
fixincludes Daily bump. 2026-02-16 00:16:25 +00:00
gcc AArch64: Don't enable ptest elimination for partial vectors [PR124162] 2026-02-27 07:41:20 +00:00
gnattools Daily bump. 2026-01-10 00:16:49 +00:00
gotools
include Daily bump. 2026-02-06 00:16:39 +00:00
INSTALL
libada Update copyright years. 2026-01-02 09:56:11 +01:00
libatomic Daily bump. 2026-02-22 00:16:27 +00:00
libbacktrace Update copyright years. 2026-01-02 10:47:06 +01:00
libcc1 Daily bump. 2026-01-16 00:16:30 +00:00
libcody Update Copyright year in ChangeLog files 2026-01-01 18:58:28 +01:00
libcpp Daily bump. 2026-02-23 00:16:26 +00:00
libdecnumber Daily bump. 2026-01-10 00:16:49 +00:00
libffi Daily bump. 2026-01-30 00:16:31 +00:00
libga68 Daily bump. 2026-02-24 00:16:30 +00:00
libgcc Daily bump. 2026-02-24 00:16:30 +00:00
libgcobol Daily bump. 2026-02-27 00:16:38 +00:00
libgfortran Daily bump. 2026-02-27 00:16:38 +00:00
libgm2 Daily bump. 2025-12-30 00:16:33 +00:00
libgo libgo: use -Wc,-shared-libgcc on Solaris 2025-12-19 15:23:49 -08:00
libgomp Daily bump. 2026-02-24 00:16:30 +00:00
libgrust Update copyright years. 2026-01-02 09:56:11 +01:00
libiberty Daily bump. 2026-02-27 00:16:38 +00:00
libitm Daily bump. 2026-02-13 00:16:32 +00:00
libobjc Update copyright years. 2026-01-02 09:56:11 +01:00
libphobos Daily bump. 2026-02-06 00:16:39 +00:00
libquadmath Daily bump. 2026-01-02 00:16:23 +00:00
libsanitizer Daily bump. 2025-12-30 00:16:33 +00:00
libssp Update copyright years. 2026-01-02 09:56:11 +01:00
libstdc++-v3 Daily bump. 2026-02-27 00:16:38 +00:00
libvtv Update copyright years. 2026-01-02 09:56:11 +01:00
lto-plugin Update copyright years. 2026-01-02 09:56:11 +01:00
maintainer-scripts Daily bump. 2026-01-27 00:16:29 +00:00
zlib Daily bump. 2025-12-30 00:16:33 +00:00
.b4-config
.dir-locals.el
.editorconfig editorconfig: Add explicit tab_width when indent_size != 8 2025-10-28 15:06:51 +00:00
.gitattributes
.gitignore Rust: Move 'libformat_parser' build into the GCC build directory 2025-08-05 16:36:43 +02:00
ABOUT-NLS
ar-lib
ChangeLog Daily bump. 2026-02-20 00:16:32 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in toplevel: Unbreak Ada build [PR123490] 2026-01-10 11:36:25 +01:00
config.guess
config.rpath
config.sub
configure AMDGCN: Disable subdirectory configuration for unsupported GAS and LD 2026-02-18 17:32:33 +00:00
configure.ac AMDGCN: Disable subdirectory configuration for unsupported GAS and LD 2026-02-18 17:32:33 +00:00
COPYING
COPYING.LIB
COPYING.RUNTIME
COPYING3
COPYING3.LIB
depcomp
install-sh
libtool-ldflags
libtool.m4 build: Cherry-pick libtool.m4 support for GNU ld *_sol2 emulations 2025-12-29 12:09:35 +01:00
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
MAINTAINERS MAINTAINERS: Add myself to Write After Approval and DCO 2026-01-22 02:55:30 +01:00
Makefile.def a68: support for Algol 68 code in libga68 and initial transput 2025-12-30 22:45:51 +01:00
Makefile.in Makefile.tpl: Implement per-stage GDCFLAGS [PR116975] 2026-02-05 14:25:08 +01:00
Makefile.tpl Makefile.tpl: Implement per-stage GDCFLAGS [PR116975] 2026-02-05 14:25:08 +01:00
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
README
SECURITY.txt a68: top-level misc files 2025-11-30 01:52:24 +01:00
symlink-tree bugzilla: remove gcc-bugs@ mailing list address 2026-01-09 11:10:38 +01:00
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.