public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/103661] New: __builtin_cpu_supports returns a negative integer for avx512vbmi2
@ 2021-12-11 16:56 stefan.kneifel at bluewin dot ch
2021-12-11 18:08 ` [Bug target/103661] " pinskia at gcc dot gnu.org
` (10 more replies)
0 siblings, 11 replies; 12+ messages in thread
From: stefan.kneifel at bluewin dot ch @ 2021-12-11 16:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103661
Bug ID: 103661
Summary: __builtin_cpu_supports returns a negative integer for
avx512vbmi2
Product: gcc
Version: 11.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: stefan.kneifel at bluewin dot ch
Target Milestone: ---
__builtin_cpu_supports is supposed to return a positive integer if the run-time
CPU supports the requested feature and zero otherwise (see Documentation).
However, for the feature "avx512vbmi2", a negative integer (0x80000000) is
returned.
FEATURE_AVX512VBMI2 equals to 31 in gcc/common/config/i386/i386-cpuinfo.h, thus
the returned 32-bit integer has bit 31 set and is therefore negative.
This might lead to surprising errors even inside GCC (e.g. when features are
tested in automatically generated resolvers; the code seems to rely on the
positivity).
Would it be an acceptable solution to declare __builtin_cpu_supports as
unsigned, or do you see another solution?
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/103661] __builtin_cpu_supports returns a negative integer for avx512vbmi2
2021-12-11 16:56 [Bug target/103661] New: __builtin_cpu_supports returns a negative integer for avx512vbmi2 stefan.kneifel at bluewin dot ch
@ 2021-12-11 18:08 ` pinskia at gcc dot gnu.org
2021-12-11 18:08 ` pinskia at gcc dot gnu.org
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-11 18:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103661
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Oh it does say positive integer:
This function returns a positive integer if the run-time CPU supports feature
and returns 0 otherwise.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/103661] __builtin_cpu_supports returns a negative integer for avx512vbmi2
2021-12-11 16:56 [Bug target/103661] New: __builtin_cpu_supports returns a negative integer for avx512vbmi2 stefan.kneifel at bluewin dot ch
2021-12-11 18:08 ` [Bug target/103661] " pinskia at gcc dot gnu.org
@ 2021-12-11 18:08 ` pinskia at gcc dot gnu.org
2021-12-11 23:50 ` stefan.kneifel at bluewin dot ch
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-11 18:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103661
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target| |x86_64
Keywords| |wrong-code
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/x86-Built-in-Functions.html#index-_005f_005fbuiltin_005fcpu_005fsupports-1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/103661] __builtin_cpu_supports returns a negative integer for avx512vbmi2
2021-12-11 16:56 [Bug target/103661] New: __builtin_cpu_supports returns a negative integer for avx512vbmi2 stefan.kneifel at bluewin dot ch
2021-12-11 18:08 ` [Bug target/103661] " pinskia at gcc dot gnu.org
2021-12-11 18:08 ` pinskia at gcc dot gnu.org
@ 2021-12-11 23:50 ` stefan.kneifel at bluewin dot ch
2021-12-12 12:50 ` stefan.kneifel at bluewin dot ch
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: stefan.kneifel at bluewin dot ch @ 2021-12-11 23:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103661
--- Comment #3 from Stefan Kneifel <stefan.kneifel at bluewin dot ch> ---
Created attachment 51975
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51975&action=edit
First try of a patch, making it unsigned (and correcting the resolver
generator)
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/103661] __builtin_cpu_supports returns a negative integer for avx512vbmi2
2021-12-11 16:56 [Bug target/103661] New: __builtin_cpu_supports returns a negative integer for avx512vbmi2 stefan.kneifel at bluewin dot ch
` (2 preceding siblings ...)
2021-12-11 23:50 ` stefan.kneifel at bluewin dot ch
@ 2021-12-12 12:50 ` stefan.kneifel at bluewin dot ch
2021-12-13 10:12 ` marxin at gcc dot gnu.org
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: stefan.kneifel at bluewin dot ch @ 2021-12-12 12:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103661
--- Comment #4 from Stefan Kneifel <stefan.kneifel at bluewin dot ch> ---
Created attachment 51978
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51978&action=edit
Testcase
Without the proposed patch, it compiles to:
--------
0000000000000000 <has_vbmi>:
0: 50 push %rax
1: e8 00 00 00 00 call 6 <has_vbmi+0x6>
2: R_X86_64_PLT32 __cpu_indicator_init-0x4
6: 31 c0 xor %eax,%eax
8: f6 05 00 00 00 00 04 testb $0x4,0x0(%rip) # f <has_vbmi+0xf>
a: R_X86_64_PC32 __cpu_model+0xa
f: 5a pop %rdx
10: 0f 95 c0 setne %al
13: c3 ret
0000000000000014 <has_vbmi2>:
14: 50 push %rax
15: e8 00 00 00 00 call 1a <has_vbmi2+0x6>
16: R_X86_64_PLT32 __cpu_indicator_init-0x4
1a: 31 c0 xor %eax,%eax
1c: 5a pop %rdx
1d: c3 ret
--------
returning 1 only for avx512vbmi, but not for avx512vbmi2, where it returns
always zero regardless whether the machine has it or not.
With the proposed patch, it compiles to:
--------
0000000000000000 <has_vbmi>:
0: 50 push %rax
1: e8 00 00 00 00 call 6 <has_vbmi+0x6>
2: R_X86_64_PLT32 __cpu_indicator_init-0x4
6: 8b 05 00 00 00 00 mov 0x0(%rip),%eax # c <has_vbmi+0xc>
8: R_X86_64_PC32 __cpu_model+0x8
c: 5a pop %rdx
d: c1 e8 1a shr $0x1a,%eax
10: 83 e0 01 and $0x1,%eax
13: c3 ret
0000000000000014 <has_vbmi2>:
14: 50 push %rax
15: e8 00 00 00 00 call 1a <has_vbmi2+0x6>
16: R_X86_64_PLT32 __cpu_indicator_init-0x4
1a: 8b 05 00 00 00 00 mov 0x0(%rip),%eax # 20
<has_vbmi2+0xc>
1c: R_X86_64_PC32 __cpu_model+0x8
20: 5a pop %rdx
21: c1 e8 1f shr $0x1f,%eax
24: c3 ret
--------
returning correctly 1 if the machine has avx512vbmi2.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/103661] __builtin_cpu_supports returns a negative integer for avx512vbmi2
2021-12-11 16:56 [Bug target/103661] New: __builtin_cpu_supports returns a negative integer for avx512vbmi2 stefan.kneifel at bluewin dot ch
` (3 preceding siblings ...)
2021-12-12 12:50 ` stefan.kneifel at bluewin dot ch
@ 2021-12-13 10:12 ` marxin at gcc dot gnu.org
2021-12-15 9:31 ` cvs-commit at gcc dot gnu.org
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-12-13 10:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103661
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |marxin at gcc dot gnu.org
--- Comment #5 from Martin Liška <marxin at gcc dot gnu.org> ---
@Stefan: Great, can you please send the patch to the mailing list?
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/103661] __builtin_cpu_supports returns a negative integer for avx512vbmi2
2021-12-11 16:56 [Bug target/103661] New: __builtin_cpu_supports returns a negative integer for avx512vbmi2 stefan.kneifel at bluewin dot ch
` (4 preceding siblings ...)
2021-12-13 10:12 ` marxin at gcc dot gnu.org
@ 2021-12-15 9:31 ` cvs-commit at gcc dot gnu.org
2021-12-15 10:52 ` marxin at gcc dot gnu.org
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-12-15 9:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103661
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Liska <marxin@gcc.gnu.org>:
https://gcc.gnu.org/g:127c7178d5ec502d95862fd823537cbca1a0cb99
commit r12-5993-g127c7178d5ec502d95862fd823537cbca1a0cb99
Author: Martin Liska <mliska@suse.cz>
Date: Mon Dec 13 15:34:30 2021 +0100
i386: Fix emissing of __builtin_cpu_supports.
PR target/103661
gcc/ChangeLog:
* config/i386/i386-builtins.c (fold_builtin_cpu): Compare to 0
as API expects that non-zero values are returned (do that
it mask == 31).
For "avx512vbmi2" argument, we return now 1 << 31, which is a
negative integer value.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/103661] __builtin_cpu_supports returns a negative integer for avx512vbmi2
2021-12-11 16:56 [Bug target/103661] New: __builtin_cpu_supports returns a negative integer for avx512vbmi2 stefan.kneifel at bluewin dot ch
` (5 preceding siblings ...)
2021-12-15 9:31 ` cvs-commit at gcc dot gnu.org
@ 2021-12-15 10:52 ` marxin at gcc dot gnu.org
2021-12-15 10:52 ` marxin at gcc dot gnu.org
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-12-15 10:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103661
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2021-12-15
Known to work| |12.0
--- Comment #7 from Martin Liška <marxin at gcc dot gnu.org> ---
Fixed on master so far.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/103661] __builtin_cpu_supports returns a negative integer for avx512vbmi2
2021-12-11 16:56 [Bug target/103661] New: __builtin_cpu_supports returns a negative integer for avx512vbmi2 stefan.kneifel at bluewin dot ch
` (6 preceding siblings ...)
2021-12-15 10:52 ` marxin at gcc dot gnu.org
@ 2021-12-15 10:52 ` marxin at gcc dot gnu.org
2021-12-16 11:46 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-12-15 10:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103661
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |marxin at gcc dot gnu.org
Status|NEW |ASSIGNED
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/103661] __builtin_cpu_supports returns a negative integer for avx512vbmi2
2021-12-11 16:56 [Bug target/103661] New: __builtin_cpu_supports returns a negative integer for avx512vbmi2 stefan.kneifel at bluewin dot ch
` (7 preceding siblings ...)
2021-12-15 10:52 ` marxin at gcc dot gnu.org
@ 2021-12-16 11:46 ` cvs-commit at gcc dot gnu.org
2021-12-16 13:03 ` cvs-commit at gcc dot gnu.org
2021-12-16 13:04 ` marxin at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-12-16 11:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103661
--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Martin Liska
<marxin@gcc.gnu.org>:
https://gcc.gnu.org/g:43d67e5e75627ad1f5ba2e983a730f37547ba9b7
commit r11-9394-g43d67e5e75627ad1f5ba2e983a730f37547ba9b7
Author: Martin Liska <mliska@suse.cz>
Date: Mon Dec 13 15:34:30 2021 +0100
i386: Fix emissing of __builtin_cpu_supports.
PR target/103661
gcc/ChangeLog:
* config/i386/i386-builtins.c (fold_builtin_cpu): Compare to 0
as API expects that non-zero values are returned (do that
it mask == 31).
For "avx512vbmi2" argument, we return now 1 << 31, which is a
negative integer value.
(cherry picked from commit 127c7178d5ec502d95862fd823537cbca1a0cb99)
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/103661] __builtin_cpu_supports returns a negative integer for avx512vbmi2
2021-12-11 16:56 [Bug target/103661] New: __builtin_cpu_supports returns a negative integer for avx512vbmi2 stefan.kneifel at bluewin dot ch
` (8 preceding siblings ...)
2021-12-16 11:46 ` cvs-commit at gcc dot gnu.org
@ 2021-12-16 13:03 ` cvs-commit at gcc dot gnu.org
2021-12-16 13:04 ` marxin at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-12-16 13:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103661
--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Martin Liska
<marxin@gcc.gnu.org>:
https://gcc.gnu.org/g:a2af3581cba0e7fa662bd8bed7e3b90451ef6a94
commit r10-10341-ga2af3581cba0e7fa662bd8bed7e3b90451ef6a94
Author: Martin Liska <mliska@suse.cz>
Date: Mon Dec 13 15:34:30 2021 +0100
i386: Fix emissing of __builtin_cpu_supports.
PR target/103661
gcc/ChangeLog:
* config/i386/i386-builtins.c (fold_builtin_cpu): Compare to 0
as API expects that non-zero values are returned (do that
it mask == 31).
For "avx512vbmi2" argument, we return now 1 << 31, which is a
negative integer value.
(cherry picked from commit 127c7178d5ec502d95862fd823537cbca1a0cb99)
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug target/103661] __builtin_cpu_supports returns a negative integer for avx512vbmi2
2021-12-11 16:56 [Bug target/103661] New: __builtin_cpu_supports returns a negative integer for avx512vbmi2 stefan.kneifel at bluewin dot ch
` (9 preceding siblings ...)
2021-12-16 13:03 ` cvs-commit at gcc dot gnu.org
@ 2021-12-16 13:04 ` marxin at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-12-16 13:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103661
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #10 from Martin Liška <marxin at gcc dot gnu.org> ---
Fixed in gcc-10,11 braches.
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2021-12-16 13:04 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-11 16:56 [Bug target/103661] New: __builtin_cpu_supports returns a negative integer for avx512vbmi2 stefan.kneifel at bluewin dot ch
2021-12-11 18:08 ` [Bug target/103661] " pinskia at gcc dot gnu.org
2021-12-11 18:08 ` pinskia at gcc dot gnu.org
2021-12-11 23:50 ` stefan.kneifel at bluewin dot ch
2021-12-12 12:50 ` stefan.kneifel at bluewin dot ch
2021-12-13 10:12 ` marxin at gcc dot gnu.org
2021-12-15 9:31 ` cvs-commit at gcc dot gnu.org
2021-12-15 10:52 ` marxin at gcc dot gnu.org
2021-12-15 10:52 ` marxin at gcc dot gnu.org
2021-12-16 11:46 ` cvs-commit at gcc dot gnu.org
2021-12-16 13:03 ` cvs-commit at gcc dot gnu.org
2021-12-16 13:04 ` marxin at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).