From patchwork Mon Nov 20 02:55:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 166925 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp1948803vqn; Sun, 19 Nov 2023 18:57:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IEqp7gTDz2iRBkB1SVtm05dZB0EpRX8FbXr4RtJxO3Dkhs16J1AbsEFzfwklPt6Lsb9wJ+e X-Received: by 2002:a05:6102:3f8a:b0:462:7bcd:6915 with SMTP id o10-20020a0561023f8a00b004627bcd6915mr6757566vsv.7.1700449068340; Sun, 19 Nov 2023 18:57:48 -0800 (PST) Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 1-20020ac84e81000000b0041cb5262974si6477787qtp.483.2023.11.19.18.57.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 18:57:48 -0800 (PST) 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=fail header.i=@intel.com header.s=Intel header.b=YwOjQAkk; arc=fail (signature failed); 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 20F9F388264C for ; Mon, 20 Nov 2023 02:57:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by sourceware.org (Postfix) with ESMTPS id E5BD1385840D for ; Mon, 20 Nov 2023 02:57:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E5BD1385840D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E5BD1385840D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700449044; cv=none; b=Z57k++m4Kk+nLhwKBSwhzagaBgTX9nPILNgN24pwTk0kUxAN1yomrAMpG1/4eNIrVcfg/391JOBurrvMgERReM8Ifa/dOnGCygOedFZiWGs/9AmrDmI7wsjbmntI1twU04RgwrbNz3+C3ZP3yI4rQ2XvVYyqYy5LZ5hq3zcIH1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700449044; c=relaxed/simple; bh=l+stnzWWVHh4s1THZ6CweonvacnuD+E1P9wkL2c2p8g=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=qvrG6n2/cS6ETq5Wi+l7ESFNUoDvDZMuxlKf9aGnepZBXVs19mPioWAPfLcke4cv8R7sHc8evdQwlAkDuItt+LEefd19FGJ5cwozK7xbAnrAmGHbPfKlQGaPq3M8fcWuW4E8KQee22pk8y9tI0F+hLIYlRU0lSHjcYLueaSbbvI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700449043; x=1731985043; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=l+stnzWWVHh4s1THZ6CweonvacnuD+E1P9wkL2c2p8g=; b=YwOjQAkkfX/KqTmM0MwkPvUwR77HnXwMf0aKPfrPeLmvrV7Cyf2rvE+z 0iPMMX0tsq0sdKaKAR+CFbcHPr3Q9Rway4syo7aZuQ/eyk750T/5F9uJS DsR0bQtPM5ul5lBCRg4QH6px3909syWKZ4kXHJ/q3KCb+5IMLEvWB1QOP w+42spcRuOwCis2UAwY72jKgzGxG8H+QliT2gEZWLAZ0+FTvJlDr6+iWJ VGKPoWC/05Wb1rIvfKnRDZFuqAZA86PACgmfpLq+jr4lTFfNxpBR1O/4B xDr30wrWFWGWelivonyPfoxAKu1M04c8bxMrb+3r4QACXkxtmSunvP+Lw Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10899"; a="13092892" X-IronPort-AV: E=Sophos;i="6.04,212,1695711600"; d="scan'208";a="13092892" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Nov 2023 18:57:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,212,1695711600"; d="scan'208";a="14453233" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by fmviesa001.fm.intel.com with ESMTP; 19 Nov 2023 18:57:19 -0800 Received: from shliclel4217.sh.intel.com (shliclel4217.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id 1F5FA100566C; Mon, 20 Nov 2023 10:57:18 +0800 (CST) From: liuhongt To: gcc-patches@gcc.gnu.org Cc: crazylht@gmail.com, hjl.tools@gmail.com Subject: [PATCH] [x86] Support reduc_{and, ior, xor}_scal_m for V4HI/V8QI/V4QImode Date: Mon, 20 Nov 2023 10:55:17 +0800 Message-Id: <20231120025517.1678251-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.2 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783050082266506280 X-GMAIL-MSGID: 1783050082266506280 Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}. Ready push to trunk. gcc/ChangeLog: PR target/112325 * config/i386/i386-expand.cc (emit_reduc_half): Hanlde V8QImode. * config/i386/mmx.md (reduc__scal_): New expander. (reduc__scal_v4qi): Ditto. gcc/testsuite/ChangeLog: * gcc.target/i386/pr112325-mmx-1.c: New test. --- gcc/config/i386/i386-expand.cc | 1 + gcc/config/i386/mmx.md | 31 +++++++++++++- .../gcc.target/i386/pr112325-mmx-1.c | 40 +++++++++++++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr112325-mmx-1.c diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc index a8d871d321e..fe56d2f6153 100644 --- a/gcc/config/i386/i386-expand.cc +++ b/gcc/config/i386/i386-expand.cc @@ -17748,6 +17748,7 @@ emit_reduc_half (rtx dest, rtx src, int i) tem = gen_mmx_lshrv1si3 (d, gen_lowpart (V1SImode, src), GEN_INT (i / 2)); break; + case E_V8QImode: case E_V4HImode: d = gen_reg_rtx (V1DImode); tem = gen_mmx_lshrv1di3 (d, gen_lowpart (V1DImode, src), diff --git a/gcc/config/i386/mmx.md b/gcc/config/i386/mmx.md index 355538749d1..c77c9719e9a 100644 --- a/gcc/config/i386/mmx.md +++ b/gcc/config/i386/mmx.md @@ -120,13 +120,15 @@ (define_mode_attr mmxscalarmode [(V2SI "SI") (V2SF "SF") (V4HF "HF") (V4BF "BF") (V2HF "HF") (V2BF "BF") - (V4HI "HI") (V2HI "HI")]) + (V4HI "HI") (V2HI "HI") + (V8QI "QI")]) (define_mode_attr mmxscalarmodelower [(V2SI "si") (V2SF "sf") (V4HF "hf") (V4BF "bf") (V2HF "hf") (V2BF "bf") - (V4HI "hi") (V2HI "hi")]) + (V4HI "hi") (V2HI "hi") + (V8QI "qi")]) (define_mode_attr Yv_Yw [(V8QI "Yw") (V4HI "Yw") (V2SI "Yv") (V1DI "Yv") (V2SF "Yv")]) @@ -6094,6 +6096,31 @@ (define_insn "*mmx_psadbw" (set_attr "type" "mmxshft,sseiadd,sseiadd") (set_attr "mode" "DI,TI,TI")]) +(define_expand "reduc__scal_" + [(any_logic:MMXMODE12 + (match_operand: 0 "register_operand") + (match_operand:MMXMODE12 1 "register_operand"))] + "TARGET_MMX_WITH_SSE" +{ + rtx tmp = gen_reg_rtx (mode); + ix86_expand_reduc (gen_3, tmp, operands[1]); + emit_insn (gen_vec_extract (operands[0], + tmp, const0_rtx)); + DONE; +}) + +(define_expand "reduc__scal_v4qi" + [(any_logic:V4QI + (match_operand:QI 0 "register_operand") + (match_operand:V4QI 1 "register_operand"))] + "TARGET_SSE2" +{ + rtx tmp = gen_reg_rtx (V4QImode); + ix86_expand_reduc (gen_v4qi3, tmp, operands[1]); + emit_insn (gen_vec_extractv4qiqi (operands[0], tmp, const0_rtx)); + DONE; +}) + (define_expand "reduc_plus_scal_v8qi" [(plus:V8QI (match_operand:QI 0 "register_operand") diff --git a/gcc/testsuite/gcc.target/i386/pr112325-mmx-1.c b/gcc/testsuite/gcc.target/i386/pr112325-mmx-1.c new file mode 100644 index 00000000000..887249fc6ad --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr112325-mmx-1.c @@ -0,0 +1,40 @@ +/* { dg-do compile { target { ! ia32 } } } */ +/* { dg-options "-msse2 -O2 -fdump-tree-slp2" } */ +/* { dg-final { scan-tree-dump-times ".REDUC_IOR" 3 "slp2" } } */ + +short +foo1 (short* a) +{ + short sum = 0; + sum |= a[0]; + sum |= a[1]; + sum |= a[2]; + sum |= a[3]; + return sum; +} + +char +foo2 (char* a) +{ + char sum = 0; + sum |= a[0]; + sum |= a[1]; + sum |= a[2]; + sum |= a[3]; + sum |= a[4]; + sum |= a[5]; + sum |= a[6]; + sum |= a[7]; + return sum; +} + +char +foo3 (char* a) +{ + char sum = 0; + sum |= a[0]; + sum |= a[1]; + sum |= a[2]; + sum |= a[3]; + return sum; +}