From patchwork Tue Aug 23 16:09:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Monakov X-Patchwork-Id: 682 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp1028943wro; Tue, 23 Aug 2022 09:10:53 -0700 (PDT) X-Google-Smtp-Source: AA6agR5SrEmiBhIWgz6xezQLKFyk+eMPySL/RW0bU+9jVnjo9FUIeFQbTo7Z7+oD9jDQSoqTLZ4v X-Received: by 2002:a05:6402:20b:b0:440:cb9f:c469 with SMTP id t11-20020a056402020b00b00440cb9fc469mr4422361edv.420.1661271053486; Tue, 23 Aug 2022 09:10:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661271053; cv=none; d=google.com; s=arc-20160816; b=X+fQOS0kYzIP3HYgBz/AFoKGHrxec3r0mhfLDNl77lC0OGCJwOniNUOcPID6WtVR1S NwufgyvRbeQauozH464tr/aiQCM+cM2InZhM4KkJTt0uE8R5r/nUOcqz8foJ7qNRi3mq /Qj3vA+63brPlPUjG3c8SXXjFbVeqyybafgGlpvfuj2SEDtv4SG8zepc3kpr9I7gvbO3 +P5M7rqwEyFvVXTQPAYoedH/TRiqfossy3VE5JWPU0n/vR89XkdsTd4jprrVhDg14j/z AeX/rbb7656aoOAW+eLnmN5bzwM/eAJdTLAgDArtcfU/ZU+MRPnAkkdeEzSQc6pwArqg Qq6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=Nz5SqA4DaJQZD4+3e2JwhZYYRwuXlTm+fLwoFt2bTeQ=; b=gMrugXKND8FLvUylWdPwPm2hLfxQcDXyRFoT0hLwgUVezJs3rE+VgquO/4dW7UqxMQ fgjG0vSH9qs0HJOASBgMRje15Dhm1Q+Nk358nrIQqK/FH6w/hk7BYMzf/+IcAgvDfsaa /S9fvGDJVALxMtPKEcomD7FQ+/pUT6VzOKTcWAOOwAwbHhcPj57IP1BLlYJfVO+bQj2p zA/qnklzhvZmiJJBeaALThGjcR1uLc5iH85sxQQgALXX7lBNOMFSdhT3uFVI3INvepvT WukuXasavL0tw9uc54x100qM3XcRblzJkiWCwGnIRlPt7A4bsqgIKqIrMUVr4NX6bJgo l7eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YW0dOuyg; 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 o10-20020a170906974a00b0073d710fec77si117958ejy.251.2022.08.23.09.10.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 09:10:53 -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=YW0dOuyg; 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 DBF043857825 for ; Tue, 23 Aug 2022 16:10:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DBF043857825 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661271045; bh=Nz5SqA4DaJQZD4+3e2JwhZYYRwuXlTm+fLwoFt2bTeQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=YW0dOuygOjKv0MA/RfFyC0cP24s+eyk7DcgmYWH5ugkZw78o5OjJ0JLPwrHRIihZ3 LBNCGfqG5FahoDBiDzSBZIvZQCrUeQrRXtntu+VBGU7W1j/L1+wbgre9nuG6umH4gA vVsf86ioulKg6ip0VkPzlHWCmkkCQgiwaCbeu368= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by sourceware.org (Postfix) with ESMTPS id D98423858C39 for ; Tue, 23 Aug 2022 16:10:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D98423858C39 Received: from localhost.intra.ispras.ru (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTP id 9980E40755E8; Tue, 23 Aug 2022 16:09:55 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] i386: avoid zero extension for crc32q Date: Tue, 23 Aug 2022 19:09:46 +0300 Message-Id: <20220823160946.19927-1-amonakov@ispras.ru> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Spam-Status: No, score=-9.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, 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: Alexander Monakov via Gcc-patches From: Alexander Monakov Reply-To: Alexander Monakov Cc: Alexander Monakov 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?1741968956023509324?= X-GMAIL-MSGID: =?utf-8?q?1741968956023509324?= The crc32q instruction takes 64-bit operands, but ignores high 32 bits of the destination operand, and zero-extends the result from 32 bits. Let's model this in the RTL pattern to avoid zero-extension when the _mm_crc32_u64 intrinsic is used with a 32-bit type. PR target/106453 gcc/ChangeLog: * config/i386/i386.md (sse4_2_crc32di): Model that only low 32 bits of operand 0 are consumed, and the result is zero-extended to 64 bits. gcc/testsuite/ChangeLog: * gcc.target/i386/pr106453.c: New test. --- gcc/config/i386/i386.md | 6 +++--- gcc/testsuite/gcc.target/i386/pr106453.c | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr106453.c diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 58fcc382f..b5760bb23 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -23823,10 +23823,10 @@ (define_insn "sse4_2_crc32di" [(set (match_operand:DI 0 "register_operand" "=r") - (unspec:DI - [(match_operand:DI 1 "register_operand" "0") + (zero_extend:DI (unspec:SI + [(match_operand:SI 1 "register_operand" "0") (match_operand:DI 2 "nonimmediate_operand" "rm")] - UNSPEC_CRC32))] + UNSPEC_CRC32)))] "TARGET_64BIT && TARGET_CRC32" "crc32{q}\t{%2, %0|%0, %2}" [(set_attr "type" "sselog1") diff --git a/gcc/testsuite/gcc.target/i386/pr106453.c b/gcc/testsuite/gcc.target/i386/pr106453.c new file mode 100644 index 000000000..bab5b1cb2 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr106453.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-msse4.2 -O2 -fdump-rtl-final" } */ +/* { dg-final { scan-rtl-dump-not "zero_extendsidi" "final" } } */ + +#include +#include + +uint32_t f(uint32_t c, uint64_t *p, size_t n) +{ + for (size_t i = 0; i < n; i++) + c = _mm_crc32_u64(c, p[i]); + return c; +}