[PATCH] tree-vect.h: Compile check_vect with -O0

"H.J. Lu" <[email protected]> Fri, 7 Aug 2026 06:12:29 +0800
Newsgroups gmane.comp.gcc.patches
Message-ID <CAMe9rOrrqqvwQxWWHXFFf5VtUxfexGzVLxSRQjEFT9BmWHZbsw@mail.gmail.com>
commit 44cc8e5718efd0cc1ef57c68052dbe33b047f158
Author: Ewan <[email protected]>
Date:   Tue Mar 17 16:12:15 2026 +0800

    i386: Fix __get_cpuid() and __get_cpuid_count() for
Centaur/Zhaoxin CPUID range

caused many regressions, like

FAIL: gcc.dg/vect/vect-100.c scan-tree-dump-not optimized "Invalid sum"

on Linux/x86-64 with -m32.  The commit above changed __get_cpuid_count
which is used by check_vect in tree-vect.h.  When GCC tried to vectorize
check_vect, it outputted

__attribute__((noinline))
void check_vect ()
{
...
;;   Invalid sum of incoming counts 966367640 (estimated locally, freq
0.9000), should be 719407024 (estimated locally, freq 0.6700)

which failed

/* { dg-final { scan-tree-dump-not "Invalid sum" "optimized" } } */

Compile check_vect with -O0 to avoid it.

* gcc.dg/vect/tree-vect.h (check_vect): Compile with -O0.


-- 
H.J.
0001-tree-vect.h-Compile-check_vect-with-O0.patch (text/x-patch, 1.6 KB)
From 349d008e398580a83f37869894ba85cb2bd93069 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <[email protected]>
Date: Fri, 7 Aug 2026 06:05:11 +0800
Subject: [PATCH] tree-vect.h: Compile check_vect with -O0

commit 44cc8e5718efd0cc1ef57c68052dbe33b047f158
Author: Ewan <[email protected]>
Date:   Tue Mar 17 16:12:15 2026 +0800

    i386: Fix __get_cpuid() and __get_cpuid_count() for Centaur/Zhaoxin CPUID range

caused many regressions, like

FAIL: gcc.dg/vect/vect-100.c scan-tree-dump-not optimized "Invalid sum"

on Linux/x86-64 with -m32.  The commit above changed __get_cpuid_count
which is used by check_vect in tree-vect.h.  When GCC tried to vectorize
check_vect, it outputted

__attribute__((noinline))
void check_vect ()
{
...
;;   Invalid sum of incoming counts 966367640 (estimated locally, freq 0.9000), should be 719407024 (estimated locally, freq 0.6700)

which failed

/* { dg-final { scan-tree-dump-not "Invalid sum" "optimized" } } */

Compile check_vect with -O0 to avoid it.

	* gcc.dg/vect/tree-vect.h (check_vect): Compile with -O0.

Signed-off-by: H.J. Lu <[email protected]>
---
 gcc/testsuite/gcc.dg/vect/tree-vect.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/vect/tree-vect.h b/gcc/testsuite/gcc.dg/vect/tree-vect.h
index 37908c911ab..de1e796f3d8 100644
--- a/gcc/testsuite/gcc.dg/vect/tree-vect.h
+++ b/gcc/testsuite/gcc.dg/vect/tree-vect.h
@@ -20,7 +20,7 @@ sig_ill_handler (int sig)
   exit(0);
 }
 
-static void __attribute__((noinline))
+static void __attribute__((noinline, optimize("-O0")))
 check_vect (void)
 {
   signal(SIGILL, sig_ill_handler);
-- 
2.55.0