Enabling AVX512 via command line may cause the compiler to generate
AVX512 instructions even before the runtime CPU feature check, causing
the test to SIGILL if the CPU lacks AVX512. Extract tests to do_test
and change main to call only if __builtin_cpu_supports ("gfni") returns
true to avoid any AVX512 instructions in main:
main:
movq __cpu_features2@GOTPCREL(%rip), %rax
testb $1, (%rax)
jne .L1577
xorl %eax, %eax
ret
.L1577:
pushq %rax
call do_test
xorl %eax, %eax
popq %rdx
ret
* gcc.target/i386/shift-gf2p8affine-2.c (do_test): New function.
Extracted from main.
(main): Drop __builtin_cpu_init. Call do_test only if
__builtin_cpu_supports ("gfni") returns true.
--
H.J.
From b277262e2d735bb70b4a7dd6dc0293ed9275887c Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <[email protected]>
Date: Sun, 3 May 2026 04:39:19 +0800
Subject: [PATCH] x86: Fix shift-gf2p8affine-2.c failure on non-AVX512 CPU
Enabling AVX512 via command line may cause the compiler to generate
AVX512 instructions even before the runtime CPU feature check, causing
the test to SIGILL if the CPU lacks AVX512. Extract tests to do_test
and change main to call only if __builtin_cpu_supports ("gfni") returns
true to avoid any AVX512 instructions in main:
main:
movq __cpu_features2@GOTPCREL(%rip), %rax
testb $1, (%rax)
jne .L1577
xorl %eax, %eax
ret
.L1577:
pushq %rax
call do_test
xorl %eax, %eax
popq %rdx
ret
* gcc.target/i386/shift-gf2p8affine-2.c (do_test): New function.
Extracted from main.
(main): Drop __builtin_cpu_init. Call do_test only if
__builtin_cpu_supports ("gfni") returns true.
Signed-off-by: H.J. Lu <[email protected]>
---
gcc/testsuite/gcc.target/i386/shift-gf2p8affine-2.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/gcc/testsuite/gcc.target/i386/shift-gf2p8affine-2.c b/gcc/testsuite/gcc.target/i386/shift-gf2p8affine-2.c
index ef088ab0b95..5b88ae098d7 100644
--- a/gcc/testsuite/gcc.target/i386/shift-gf2p8affine-2.c
+++ b/gcc/testsuite/gcc.target/i386/shift-gf2p8affine-2.c
@@ -151,12 +151,10 @@ FUNC (N5)
func##N##ref (array2, len); \
if (memcmp (array, array2, len)) __builtin_abort ()
-int main ()
+__attribute__ ((noipa))
+void
+do_test (void)
{
- __builtin_cpu_init ();
- if (!__builtin_cpu_supports ("gfni"))
- return 0;
-
const unsigned long len = 256;
char array[len], array2[len];
unsigned char filler = FILLER;
@@ -195,6 +193,11 @@ int main ()
TEST (N5, sbyteshiftr);
TEST (N5, ubyteror);
TEST (N5, ubyterol);
+}
+int main ()
+{
+ if (__builtin_cpu_supports ("gfni"))
+ do_test ();
return 0;
}
--
2.54.0