https://gcc.gnu.org/g:3275b86a822b23ad2e332d2425ac3d6abcb2105a
commit r16-7712-g3275b86a822b23ad2e332d2425ac3d6abcb2105a Author: Roger Sayle <[email protected]> Date: Thu Feb 26 08:07:12 2026 +0000 PR target/124194: Fix __builtin_ia32_cmpd256_mask(op,op,TRUE) 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. 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. Diff: --- gcc/config/i386/sse.md | 4 ++-- gcc/testsuite/gcc.target/i386/pr124194.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md index cfe7a046f428..2e15842b3c7d 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 000000000000..c295b69b49a9 --- /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" } } */
