This patch fixes the wrong code regression PR target/124194 on x86_64.
The target implements a pre-reload splitter that recognizes that
integer vector comparisons can be evaluated at compile-time when the
operands being compared are the same (register).  The (admittedly rare)
case when the comparison operator is always-true, was incorrectly
handled and folded to false instead of the correct value true.

This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
and make -k check, both with and without --target_board=unix{-m32}
with no new failures.  Committed as pre-approved by Hongtao in bugzilla
(many thanks).


2025-02-26  Roger Sayle  <[email protected]>

gcc/ChangeLog
        PR target/124194
        * config/i386/sse.md (*<avx512>_cmp<mode>3_dup_op): Also return
        CONSTM1_RTX for the case cmp_imm == 7 (predicate TRUE).

gcc/testsuite/ChangeLog
        PR target/124194
        * gcc.target/i386/pr124194.c: New test case.


Roger
--

diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index cfe7a046f42..2e15842b3c7 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -4913,8 +4913,8 @@
 {
   int cmp_imm = INTVAL (operands[3]);
   rtx res = CONST0_RTX (<avx512fmaskmode>mode);
-  /* EQ/LE/NLT.  */
-  if (cmp_imm == 0 || cmp_imm == 2 || cmp_imm == 5)
+  /* EQ/LE/NLT/TRUE.  */
+  if (cmp_imm == 0 || cmp_imm == 2 || cmp_imm == 5 || cmp_imm == 7)
   {
     int nelts = GET_MODE_NUNITS (<MODE>mode);
     if (nelts >= 8)
diff --git a/gcc/testsuite/gcc.target/i386/pr124194.c 
b/gcc/testsuite/gcc.target/i386/pr124194.c
new file mode 100644
index 00000000000..c295b69b49a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr124194.c
@@ -0,0 +1,15 @@
+/* PR target/124194 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512vl" } */
+typedef __attribute__((__vector_size__ (8 *sizeof (int)))) int V;
+
+int
+main ()
+{
+  unsigned char x = __builtin_ia32_cmpd256_mask ((V){}, (V){}, 7, 0xff);
+  if (x != 0xff)
+    __builtin_abort();
+  return 0;
+}
+/* { dg-final { scan-assembler-times "xorl" 1 } } */
+/* { dg-final { scan-assembler-not "vpcmpd" } } */

Reply via email to