On Fri, Aug 7, 2026 at 4:13 PM H.J. Lu <[email protected]> wrote:
>
> On Fri, Aug 7, 2026 at 3:14 PM Liu, Hongtao <[email protected]> wrote:
> >
> >
> >
> > > -----Original Message-----
> > > From: H.J. Lu <[email protected]>
> > > Sent: Friday, August 7, 2026 2:51 PM
> > > To: Hongtao Liu <[email protected]>
> > > Cc: [email protected]; GCC Patches <[email protected]>; Uros
> > > Bizjak <[email protected]>; Liu, Hongtao <[email protected]>; Jiang,
> > > Haochen <[email protected]>
> > > Subject: Re: [PATCH] tree-vect.h: Compile check_vect with -O0
> > >
> > > On Fri, Aug 7, 2026 at 2:19 PM Hongtao Liu <[email protected]> wrote:
> > > >
> > > > On Fri, Aug 7, 2026 at 10:59 AM H.J. Lu <[email protected]> wrote:
> > > > >
> > > > > On Fri, Aug 7, 2026 at 6:12 AM H.J. Lu <[email protected]> wrote:
> > > > > >
> > > > > > 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.
> > > > >
> > > > > This fixes:
> > > > >
> > > > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126697
> > > >
> > > > Can we use
> > > >
> > > > unsigned int __ext = __leaf & 0xC0000000;
> > > >
> > > > Assume it can also support zhaoxin's maximum secondary extended
> > > > level(0xC0000000);?
> > >
> > > Or we can fold it into __get_cpuid_max.
> > That would be better, then we don't need 2 duplicated parts in __get_cpuid 
> > and __get_cpuid_count
> >
>
> Should it be reverted for now and reimplement it in __get_cpuid_max?
>

Or this patch.

-- 
H.J.
---
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 ra
nge

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" } } */

Change __get_cpuid and __get_cpuid_count to pass the leaf argument
directly to __get_cpuid_max and apply 0xC0000000 mask before passing
it to CPUID.

PR testsuite/126697
* config/i386/cpuid.h (__get_cpuid_max): Rename the first
argument to __leaf and apply 0xC0000000 mask before passing
it to CPUID.
(__get_cpuid): Pass __leaf to __get_cpuid_max.
(__get_cpuid_count): Likewise.
From af8f21ea65f501f76d68ca00e421e814cd0d68ac Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <[email protected]>
Date: Fri, 7 Aug 2026 16:21:54 +0800
Subject: [PATCH] x86: Update cpuid.h to pass leaf to __get_cpuid_max

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 ra
nge

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" } } */

Change __get_cpuid and __get_cpuid_count to pass the leaf argument
directly to __get_cpuid_max and apply 0xC0000000 mask before passing
it to CPUID.

	PR testsuite/126697
	* config/i386/cpuid.h (__get_cpuid_max): Rename the first
	argument to __leaf and apply 0xC0000000 mask before passing
	it to CPUID.
	(__get_cpuid): Pass __leaf to __get_cpuid_max.
	(__get_cpuid_count): Likewise.

Signed-off-by: H.J. Lu <[email protected]>
---
 gcc/config/i386/cpuid.h | 33 ++++++---------------------------
 1 file changed, 6 insertions(+), 27 deletions(-)

diff --git a/gcc/config/i386/cpuid.h b/gcc/config/i386/cpuid.h
index 129531dcc38..5e1aad57d40 100644
--- a/gcc/config/i386/cpuid.h
+++ b/gcc/config/i386/cpuid.h
@@ -270,8 +270,8 @@
 			: "0" (level), "2" (count))
 
 
-/* Return highest supported input value for cpuid instruction.  ext can
-   be either 0x0, 0x40000000, 0x80000000, or 0xC0000000 to return
+/* Return highest supported input value for cpuid instruction.  leaf can
+   be either 0xXXX, 0x40000XXX, 0x80000XXX, or 0xC000XXX to return
    highest supported value for basic, hypervisor, extended, or
    Centaur/Zhaoxin cpuid information.  Function returns 0 if cpuid
    is not supported or whatever cpuid returns in eax register.  If sig
@@ -279,9 +279,10 @@
    (as found in ebx register) are returned in location pointed by sig.  */
 
 static __inline unsigned int
-__get_cpuid_max (unsigned int __ext, unsigned int *__sig)
+__get_cpuid_max (unsigned int __leaf, unsigned int *__sig)
 {
   unsigned int __eax, __ebx, __ecx, __edx;
+  unsigned int __ext = __leaf & 0xC0000000;
 
 #ifndef __x86_64__
   /* See if we can use cpuid.  On AMD64 we always can.  */
@@ -338,18 +339,7 @@ __get_cpuid (unsigned int __leaf,
 	     unsigned int *__eax, unsigned int *__ebx,
 	     unsigned int *__ecx, unsigned int *__edx)
 {
-  unsigned int __ext;
-
-  if (__leaf >= 0xC0000000)
-    __ext = 0xC0000000;
-  else if (__leaf >= 0x80000000)
-    __ext = 0x80000000;
-  else if (__leaf >= 0x40000000)
-    __ext = 0x40000000;
-  else
-    __ext = 0x00000000;
-
-  unsigned int __maxlevel = __get_cpuid_max (__ext, 0);
+  unsigned int __maxlevel = __get_cpuid_max (__leaf, 0);
 
   if (__maxlevel == 0 || __maxlevel < __leaf)
     return 0;
@@ -365,18 +355,7 @@ __get_cpuid_count (unsigned int __leaf, unsigned int __subleaf,
 		   unsigned int *__eax, unsigned int *__ebx,
 		   unsigned int *__ecx, unsigned int *__edx)
 {
-  unsigned int __ext;
-
-  if (__leaf >= 0xC0000000)
-    __ext = 0xC0000000;
-  else if (__leaf >= 0x80000000)
-    __ext = 0x80000000;
-  else if (__leaf >= 0x40000000)
-    __ext = 0x40000000;
-  else
-    __ext = 0x00000000;
-
-  unsigned int __maxlevel = __get_cpuid_max (__ext, 0);
+  unsigned int __maxlevel = __get_cpuid_max (__leaf, 0);
 
   if (__builtin_expect (__maxlevel == 0, 0) || __maxlevel < __leaf)
     return 0;
-- 
2.55.0

Reply via email to