From patchwork Tue Apr 18 07:18:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jiang, Haochen" X-Patchwork-Id: 84617 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2642208vqo; Tue, 18 Apr 2023 00:19:05 -0700 (PDT) X-Google-Smtp-Source: AKy350YJqTKBinFgbYruLbJfc9y6yxO29FKHcLE8u012plkprwenHsjXTLk2DR/tAphwzukHLfS3 X-Received: by 2002:a05:6402:cf:b0:506:b24d:7880 with SMTP id i15-20020a05640200cf00b00506b24d7880mr1397295edu.17.1681802345124; Tue, 18 Apr 2023 00:19:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681802345; cv=none; d=google.com; s=arc-20160816; b=wcwycKhuDlr4/VYzgO/QYZqGJer8VLJb6FVjvtLpQL4AvOprZTB1/6YFsk1XvEQ3uH 5dD0DAspHuVqhMhzzkMHjvVTg3h26vDSiVnmIwt6kLrHcO1nUOR6k/UIOLoo6xw9nQQ8 62R4jMwc6wV2WhSxk98pbOgR/5UfLtcoGiuSq9mmtaogJlQ0DaBJGHQgIVwpk9tkE9nJ tUqYrDgAN6ZeBq980A7qVX2THBxSJAst/dqHFmCzntHaRCGS+RQAnApdt2C3rscd9MMf OBlDFg5MsWk4r7oz1yxtrVauy+IfGaxdKFkzxF5AbrQ774eFUXP7eTC/MUMy+lxCTvc/ EsRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=XFq1XAeqzZ2pfebFR9Qr4Q0o2Ct1YvboTkIcvM9qKjQ=; b=eCwLIe3A7HCfhOZrRnLOT+kFoam8cgi5WuDZj3xcRXeZzTemAeJDpRmYTWf6Llyzxj UEH5UnHhyP9y7QqVJF0VKVdOOWVe0BZSaIgyWibYhLi7dv36cwX85oFlBb3Cs9+7Y75K GLL/qah7srfJix7DHjfpL/euKLn3ZOzoNutSP+Kq6fK3tlwp48WdOabb96F24P4dRz1g +AKTydYtsdfnL9XyjBL2UsRPEMwxUrSF+6FGZBpJy9VGVSF1UUUtufJVThf8VlYQgxf0 +J7hhPqcBeEb5MSG9FxxKWjOLhki7DNSKdKJXZsXDa07vW+rouqwn0TyE+of0uqRN7eK CtiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Ng8M3qVd; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d19-20020a056402001300b00506734fe162si10906868edu.450.2023.04.18.00.19.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 00:19:05 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Ng8M3qVd; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D33513857345 for ; Tue, 18 Apr 2023 07:18:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D33513857345 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681802332; bh=XFq1XAeqzZ2pfebFR9Qr4Q0o2Ct1YvboTkIcvM9qKjQ=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Ng8M3qVdh+cUToMd2ZyUua3ntcENzrhSm91WDrlxn2lIXWCb0Sc7uCqEw0bP498id gSKCBkcwNgM5amBu0cRIftWMVj7Tp+QOBm3SpPj2Qvand/4WmEZ6QI7daXB3VZJcQS pGm5DA8Ixt1iuMzXNU16kJioYLcd84nR9uI9MnWE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by sourceware.org (Postfix) with ESMTPS id 4127B3858C27 for ; Tue, 18 Apr 2023 07:18:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4127B3858C27 X-IronPort-AV: E=McAfee;i="6600,9927,10683"; a="431385352" X-IronPort-AV: E=Sophos;i="5.99,206,1677571200"; d="scan'208";a="431385352" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2023 00:18:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10683"; a="693531747" X-IronPort-AV: E=Sophos;i="5.99,206,1677571200"; d="scan'208";a="693531747" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by fmsmga007.fm.intel.com with ESMTP; 18 Apr 2023 00:18:05 -0700 Received: from shliclel4217.sh.intel.com (shliclel4217.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id 7CBC210081CD; Tue, 18 Apr 2023 15:18:04 +0800 (CST) To: gcc-patches@gcc.gnu.org Cc: hongtao.liu@intel.com, ubizjak@gmail.com Subject: [PATCH] i386: Add PCLMUL dependency for VPCLMULQDQ Date: Tue, 18 Apr 2023 15:18:04 +0800 Message-Id: <20230418071804.4192513-1-haochen.jiang@intel.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Haochen Jiang via Gcc-patches From: "Jiang, Haochen" Reply-To: Haochen Jiang Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763497575726883518?= X-GMAIL-MSGID: =?utf-8?q?1763497575726883518?= Hi all, Currently in GCC, the 128 bit intrin for instruction vpclmulqdq is under PCLMUL ISA. Because there is no dependency between ISA set PCLMUL and VPCLMULQDQ, The 128 bit intrin is not available when we just use compiler flag -mvpclmulqdq. But it should according to Intel SDM. Since VPCLMULQDQ is a VEX/EVEX promotion for PCLMUL, it is natural to add dependency between them. Also, with -mvpclmulqdq, we can use ymm under VEX encoding, so VPCLMULQDQ should imply AVX. Tested on x86_64-pc-linux-gnu. Ok for trunk? BRs, Haochen gcc/ChangeLog: * common/config/i386/i386-common.cc (OPTION_MASK_ISA_VPCLMULQDQ_SET): Add OPTION_MASK_ISA_PCLMUL_SET and OPTION_MASK_ISA_AVX_SET. (OPTION_MASK_ISA_AVX_UNSET): Add OPTION_MASK_ISA_VPCLMULQDQ_UNSET. (OPTION_MASK_ISA_PCLMUL_UNSET): Ditto. * config/i386/i386.md (vpclmulqdqvl): New. * config/i386/sse.md (pclmulqdq): Add evex encoding. * config/i386/vpclmulqdqintrin.h: Remove redudant avx target push. gcc/testsuite/ChangeLog: * gcc.target/i386/vpclmulqdq.c: Add compile test for xmm. --- gcc/common/config/i386/i386-common.cc | 9 ++++++--- gcc/config/i386/i386.md | 4 +++- gcc/config/i386/sse.md | 11 ++++++----- gcc/config/i386/vpclmulqdqintrin.h | 4 ++-- gcc/testsuite/gcc.target/i386/vpclmulqdq.c | 3 +++ 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/gcc/common/config/i386/i386-common.cc b/gcc/common/config/i386/i386-common.cc index 315db854862..c7954da8e34 100644 --- a/gcc/common/config/i386/i386-common.cc +++ b/gcc/common/config/i386/i386-common.cc @@ -171,7 +171,9 @@ along with GCC; see the file COPYING3. If not see #define OPTION_MASK_ISA_GFNI_SET OPTION_MASK_ISA_GFNI #define OPTION_MASK_ISA_SHSTK_SET OPTION_MASK_ISA_SHSTK #define OPTION_MASK_ISA2_VAES_SET OPTION_MASK_ISA2_VAES -#define OPTION_MASK_ISA_VPCLMULQDQ_SET OPTION_MASK_ISA_VPCLMULQDQ +#define OPTION_MASK_ISA_VPCLMULQDQ_SET \ + (OPTION_MASK_ISA_VPCLMULQDQ | OPTION_MASK_ISA_PCLMUL_SET \ + | OPTION_MASK_ISA_AVX_SET) #define OPTION_MASK_ISA_MOVDIRI_SET OPTION_MASK_ISA_MOVDIRI #define OPTION_MASK_ISA2_MOVDIR64B_SET OPTION_MASK_ISA2_MOVDIR64B #define OPTION_MASK_ISA2_WAITPKG_SET OPTION_MASK_ISA2_WAITPKG @@ -211,7 +213,7 @@ along with GCC; see the file COPYING3. If not see #define OPTION_MASK_ISA_AVX_UNSET \ (OPTION_MASK_ISA_AVX | OPTION_MASK_ISA_FMA_UNSET \ | OPTION_MASK_ISA_FMA4_UNSET | OPTION_MASK_ISA_F16C_UNSET \ - | OPTION_MASK_ISA_AVX2_UNSET ) + | OPTION_MASK_ISA_AVX2_UNSET | OPTION_MASK_ISA_VPCLMULQDQ_UNSET) #define OPTION_MASK_ISA_FMA_UNSET OPTION_MASK_ISA_FMA #define OPTION_MASK_ISA_FXSR_UNSET OPTION_MASK_ISA_FXSR #define OPTION_MASK_ISA_XSAVE_UNSET \ @@ -314,7 +316,8 @@ along with GCC; see the file COPYING3. If not see #define OPTION_MASK_ISA_AES_UNSET OPTION_MASK_ISA_AES #define OPTION_MASK_ISA_SHA_UNSET OPTION_MASK_ISA_SHA -#define OPTION_MASK_ISA_PCLMUL_UNSET OPTION_MASK_ISA_PCLMUL +#define OPTION_MASK_ISA_PCLMUL_UNSET \ + (OPTION_MASK_ISA_PCLMUL | OPTION_MASK_ISA_VPCLMULQDQ_UNSET) #define OPTION_MASK_ISA_ABM_UNSET OPTION_MASK_ISA_ABM #define OPTION_MASK_ISA2_PCONFIG_UNSET OPTION_MASK_ISA2_PCONFIG #define OPTION_MASK_ISA2_WBNOINVD_UNSET OPTION_MASK_ISA2_WBNOINVD diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index ed689b044c3..acc994226e7 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -841,7 +841,7 @@ avx,noavx,avx2,noavx2,bmi,bmi2,fma4,fma,avx512f,noavx512f, avx512bw,noavx512bw,avx512dq,noavx512dq,fma_or_avx512vl, avx512vl,noavx512vl,avxvnni,avx512vnnivl,avx512fp16,avxifma, - avx512ifmavl,avxneconvert,avx512bf16vl" + avx512ifmavl,avxneconvert,avx512bf16vl,vpclmulqdqvl" (const_string "base")) ;; Define instruction set of MMX instructions @@ -903,6 +903,8 @@ (eq_attr "isa" "avxneconvert") (symbol_ref "TARGET_AVXNECONVERT") (eq_attr "isa" "avx512bf16vl") (symbol_ref "TARGET_AVX512BF16 && TARGET_AVX512VL") + (eq_attr "isa" "vpclmulqdqvl") + (symbol_ref "TARGET_VPCLMULQDQ && TARGET_AVX512VL") (eq_attr "mmx_isa" "native") (symbol_ref "!TARGET_MMX_WITH_SSE") diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md index 26812ab6106..33e281901cf 100644 --- a/gcc/config/i386/sse.md +++ b/gcc/config/i386/sse.md @@ -25195,20 +25195,21 @@ (set_attr "mode" "TI")]) (define_insn "pclmulqdq" - [(set (match_operand:V2DI 0 "register_operand" "=x,x") - (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x") - (match_operand:V2DI 2 "vector_operand" "xBm,xm") + [(set (match_operand:V2DI 0 "register_operand" "=x,x,v") + (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x,v") + (match_operand:V2DI 2 "vector_operand" "xBm,xm,vm") (match_operand:SI 3 "const_0_to_255_operand")] UNSPEC_PCLMUL))] "TARGET_PCLMUL" "@ pclmulqdq\t{%3, %2, %0|%0, %2, %3} + vpclmulqdq\t{%3, %2, %1, %0|%0, %1, %2, %3} vpclmulqdq\t{%3, %2, %1, %0|%0, %1, %2, %3}" - [(set_attr "isa" "noavx,avx") + [(set_attr "isa" "noavx,avx,vpclmulqdqvl") (set_attr "type" "sselog1") (set_attr "prefix_extra" "1") (set_attr "length_immediate" "1") - (set_attr "prefix" "orig,vex") + (set_attr "prefix" "orig,vex,evex") (set_attr "mode" "TI")]) (define_expand "avx_vzeroall" diff --git a/gcc/config/i386/vpclmulqdqintrin.h b/gcc/config/i386/vpclmulqdqintrin.h index ba93fc4ff9c..2c83b6037a0 100644 --- a/gcc/config/i386/vpclmulqdqintrin.h +++ b/gcc/config/i386/vpclmulqdqintrin.h @@ -53,9 +53,9 @@ _mm512_clmulepi64_epi128 (__m512i __A, __m512i __B, const int __C) #pragma GCC pop_options #endif /* __DISABLE_VPCLMULQDQF__ */ -#if !defined(__VPCLMULQDQ__) || !defined(__AVX__) +#if !defined(__VPCLMULQDQ__) #pragma GCC push_options -#pragma GCC target("vpclmulqdq,avx") +#pragma GCC target("vpclmulqdq") #define __DISABLE_VPCLMULQDQ__ #endif /* __VPCLMULQDQ__ */ diff --git a/gcc/testsuite/gcc.target/i386/vpclmulqdq.c b/gcc/testsuite/gcc.target/i386/vpclmulqdq.c index d93f776803f..27b2fd71ea4 100644 --- a/gcc/testsuite/gcc.target/i386/vpclmulqdq.c +++ b/gcc/testsuite/gcc.target/i386/vpclmulqdq.c @@ -2,16 +2,19 @@ /* { dg-options "-mvpclmulqdq -mavx512vl -mavx512f -O2" } */ /* { dg-final { scan-assembler-times "vpclmulqdq\[ \\t\]+\[^\{\n\]*\\\$3\[^\n\r]*%zmm\[0-9\]+\[^\n\r]*%zmm\[0-9\]+\[^\n\r]*%zmm\[0-9\]+(?:\n|\[ \\t\]+#)" 1 } } */ /* { dg-final { scan-assembler-times "vpclmulqdq\[ \\t\]+\[^\{\n\]*\\\$3\[^\n\r]*%ymm\[0-9\]+\[^\n\r]*%ymm\[0-9\]+\[^\n\r]*%ymm\[0-9\]+(?:\n|\[ \\t\]+#)" 1 } } */ +/* { dg-final { scan-assembler-times "vpclmulqdq\[ \\t\]+\[^\{\n\]*\\\$3\[^\n\r]*%xmm\[0-9\]+\[^\n\r]*%xmm\[0-9\]+\[^\n\r]*%xmm\[0-9\]+(?:\n|\[ \\t\]+#)" 1 } } */ #include volatile __m512i x1, x2; volatile __m256i x3, x4; +volatile __m128i x5, x6; void extern avx512vl_test (void) { x1 = _mm512_clmulepi64_epi128(x1, x2, 3); x3 = _mm256_clmulepi64_epi128(x3, x4, 3); + x5 = _mm_clmulepi64_si128(x5, x6, 3); }