Find a file
Roger Sayle 3635e8c67e PR target/109973: CCZmode and CCCmode variants of [v]ptest on x86.
This is my proposed minimal fix for PR target/109973 (hopefully suitable
for backporting) that follows Jakub Jelinek's suggestion that we introduce
CCZmode and CCCmode variants of ptest and vptest, so that the i386
backend treats [v]ptest instructions similarly to testl instructions;
using different CCmodes to indicate which condition flags are desired,
and then relying on the RTL cmpelim pass to eliminate redundant tests.

This conveniently matches Intel's intrinsics, that provide different
functions for retrieving different flags, _mm_testz_si128 tests the
Z flag, _mm_testc_si128 tests the carry flag.  Currently we use the
same instruction (pattern) for both, and unfortunately the *ptest<mode>_and
optimization is only valid when the ptest/vptest instruction is used to
set/test the Z flag.

The downside, as predicted by Jakub, is that GCC's cmpelim pass is
currently COMPARE-centric and not able to merge the ptests from expressions
such as _mm256_testc_si256 (a, b) + _mm256_testz_si256 (a, b), which is a
known issue, PR target/80040.

2023-06-01  Roger Sayle  <roger@nextmovesoftware.com>
	    Uros Bizjak  <ubizjak@gmail.com>

gcc/ChangeLog
	PR target/109973
	* config/i386/i386-builtin.def (__builtin_ia32_ptestz128): Use new
	CODE_for_sse4_1_ptestzv2di.
	(__builtin_ia32_ptestc128): Use new CODE_for_sse4_1_ptestcv2di.
	(__builtin_ia32_ptestz256): Use new CODE_for_avx_ptestzv4di.
	(__builtin_ia32_ptestc256): Use new CODE_for_avx_ptestcv4di.
	* config/i386/i386-expand.cc (ix86_expand_branch): Use CCZmode
	when expanding UNSPEC_PTEST to compare against zero.
	* config/i386/i386-features.cc (scalar_chain::convert_compare):
	Likewise generate CCZmode UNSPEC_PTESTs when converting comparisons.
	(general_scalar_chain::convert_insn): Use CCZmode for COMPARE result.
	(timode_scalar_chain::convert_insn): Use CCZmode for COMPARE result.
	* config/i386/i386-protos.h (ix86_match_ptest_ccmode): Prototype.
	* config/i386/i386.cc (ix86_match_ptest_ccmode): New predicate to
	check for suitable matching modes for the UNSPEC_PTEST pattern.
	* config/i386/sse.md (define_split): When splitting UNSPEC_MOVMSK
	to UNSPEC_PTEST, preserve the FLAG_REG mode as CCZ.
	(*<sse4_1>_ptest<mode>): Add asterisk to hide define_insn.  Remove
	":CC" mode of FLAGS_REG, instead use ix86_match_ptest_ccmode.
	(<sse4_1>_ptestz<mode>): New define_expand to specify CCZ.
	(<sse4_1>_ptestc<mode>): New define_expand to specify CCC.
	(<sse4_1>_ptest<mode>): A define_expand using CC to preserve the
	current behavior.
	(*ptest<mode>_and): Specify CCZ to only perform this optimization
	when only the Z flag is required.

gcc/testsuite/ChangeLog
	PR target/109973
	* gcc.target/i386/pr109973-1.c: New test case.
	* gcc.target/i386/pr109973-2.c: Likewise.
2023-06-01 15:11:25 +01: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-05-19 00:17:43 +00:00
fixincludes Daily bump. 2023-03-29 00:17:01 +00:00
gcc PR target/109973: CCZmode and CCCmode variants of [v]ptest on x86. 2023-06-01 15:11:25 +01: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 Daily bump. 2023-05-19 00:17:43 +00: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-20 00:16:40 +00:00
libgfortran Daily bump. 2023-05-13 00:17:14 +00:00
libgm2 Daily bump. 2023-05-17 00:17:44 +00:00
libgo syscall: add prlimit 2023-05-11 09:17:48 -07:00
libgomp OpenMP/Fortran: Permit pure directives inside PURE 2023-06-01 09:51:07 +02: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 Daily bump. 2023-05-23 00:17:11 +00: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 libstdc++: optimize EH phase 2 2023-06-01 08:49:20 -04: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
.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-31 00:17:14 +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: Add myself to write after approval 2023-05-30 11:02:37 -05:00
Makefile.def configure: Do not build the ununsed libffi shared library. 2022-12-31 17:51:47 +00:00
Makefile.in Disable warnings as errors for STAGEautofeedback. 2023-05-17 22:43:49 -07:00
Makefile.tpl Disable warnings as errors for STAGEautofeedback. 2023-05-17 22:43:49 -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.