Skip to content

Commit

Permalink
i386: Guard 128 bit VAES builtins with AVX512VL
Browse files Browse the repository at this point in the history
Hi all,

Currently on trunk, both usage of intrin and builtin for 128 bit VAES
ISA will result in ICE since we did not check AVX512VL until pattern,
which is not user expected. This patch aims to fix that ICE and throw
an error under this scenario.

Regtested on x86-64-linux-gnu{-m32,}. Ok for trunk?

BRs,
Haochen

Since commit 24a8acc, 128 bit intrin is enabled for VAES. However,
AVX512VL is not checked until we reached into pattern, which reports an
ICE.

Added an AVX512VL guard at builtin to report error when checking ISA
flags.

gcc/ChangeLog:

	* config/i386/i386-builtins.cc (ix86_init_mmx_sse_builtins):
	Add OPTION_MASK_ISA_AVX512VL.
	* config/i386/i386-expand.cc (ix86_check_builtin_isa_match):
	Ditto.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/avx512vl-vaes-1.c: New test.
  • Loading branch information
jianghc724 authored and ouuleilei-bot committed Jul 11, 2023
1 parent c2d62cd commit c03b0b8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
12 changes: 8 additions & 4 deletions gcc/config/i386/i386-builtins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -662,19 +662,23 @@ ix86_init_mmx_sse_builtins (void)
VOID_FTYPE_UNSIGNED_UNSIGNED, IX86_BUILTIN_MWAIT);

/* AES */
def_builtin_const (OPTION_MASK_ISA_AES | OPTION_MASK_ISA_SSE2,
def_builtin_const (OPTION_MASK_ISA_AES | OPTION_MASK_ISA_SSE2
| OPTION_MASK_ISA_AVX512VL,
OPTION_MASK_ISA2_VAES,
"__builtin_ia32_aesenc128",
V2DI_FTYPE_V2DI_V2DI, IX86_BUILTIN_AESENC128);
def_builtin_const (OPTION_MASK_ISA_AES | OPTION_MASK_ISA_SSE2,
def_builtin_const (OPTION_MASK_ISA_AES | OPTION_MASK_ISA_SSE2
| OPTION_MASK_ISA_AVX512VL,
OPTION_MASK_ISA2_VAES,
"__builtin_ia32_aesenclast128",
V2DI_FTYPE_V2DI_V2DI, IX86_BUILTIN_AESENCLAST128);
def_builtin_const (OPTION_MASK_ISA_AES | OPTION_MASK_ISA_SSE2,
def_builtin_const (OPTION_MASK_ISA_AES | OPTION_MASK_ISA_SSE2
| OPTION_MASK_ISA_AVX512VL,
OPTION_MASK_ISA2_VAES,
"__builtin_ia32_aesdec128",
V2DI_FTYPE_V2DI_V2DI, IX86_BUILTIN_AESDEC128);
def_builtin_const (OPTION_MASK_ISA_AES | OPTION_MASK_ISA_SSE2,
def_builtin_const (OPTION_MASK_ISA_AES | OPTION_MASK_ISA_SSE2
| OPTION_MASK_ISA_AVX512VL,
OPTION_MASK_ISA2_VAES,
"__builtin_ia32_aesdeclast128",
V2DI_FTYPE_V2DI_V2DI, IX86_BUILTIN_AESDECLAST128);
Expand Down
4 changes: 3 additions & 1 deletion gcc/config/i386/i386-expand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12601,6 +12601,7 @@ ix86_check_builtin_isa_match (unsigned int fcode,
OPTION_MASK_ISA2_AVXIFMA
(OPTION_MASK_ISA_AVX512VL | OPTION_MASK_ISA2_AVX512BF16) or
OPTION_MASK_ISA2_AVXNECONVERT
OPTION_MASK_ISA_AES or (OPTION_MASK_ISA_AVX512VL | OPTION_MASK_ISA2_VAES)
where for each such pair it is sufficient if either of the ISAs is
enabled, plus if it is ored with other options also those others.
OPTION_MASK_ISA_MMX in bisa is satisfied also if TARGET_MMX_WITH_SSE. */
Expand All @@ -12624,7 +12625,8 @@ ix86_check_builtin_isa_match (unsigned int fcode,
OPTION_MASK_ISA2_AVXIFMA);
SHARE_BUILTIN (OPTION_MASK_ISA_AVX512VL, OPTION_MASK_ISA2_AVX512BF16, 0,
OPTION_MASK_ISA2_AVXNECONVERT);
SHARE_BUILTIN (OPTION_MASK_ISA_AES, 0, 0, OPTION_MASK_ISA2_VAES);
SHARE_BUILTIN (OPTION_MASK_ISA_AES, 0, OPTION_MASK_ISA_AVX512VL,
OPTION_MASK_ISA2_VAES);
isa = tmp_isa;
isa2 = tmp_isa2;

Expand Down
12 changes: 12 additions & 0 deletions gcc/testsuite/gcc.target/i386/avx512vl-vaes-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* { dg-do compile } */
/* { dg-options "-mvaes -mno-avx512vl -mno-aes" } */

#include <immintrin.h>

typedef long long v2di __attribute__((vector_size (16)));

v2di
f1 (v2di x, v2di y)
{
return __builtin_ia32_aesenc128 (x, y); /* { dg-error "needs isa option" } */
}

0 comments on commit c03b0b8

Please sign in to comment.